Example usage for org.eclipse.jface.databinding.swt SWTObservables observeText

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeText

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables observeText.

Prototype

@Deprecated
public static ISWTObservableValue observeText(Control control) 

Source Link

Document

Returns an observable observing the text attribute of the provided control.

Usage

From source file:org.bonitasoft.studio.businessobject.ui.expression.QueryExpressionEditor.java

License:Open Source License

private void createReturnTypeText(final Composite composite, final EMFDataBindingContext ctx) {
    final Composite returnTypeComposite = new Composite(composite, SWT.NONE);
    returnTypeComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    returnTypeComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final Label returnTypeLabel = new Label(returnTypeComposite, SWT.NONE);
    returnTypeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).create());
    returnTypeLabel.setText(Messages.returnType);

    final Text returnTypeText = new Text(returnTypeComposite, SWT.BORDER | SWT.READ_ONLY);
    returnTypeText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    ctx.bindValue(SWTObservables.observeText(returnTypeText),
            EMFObservables.observeDetailValue(Realm.getDefault(), observeQuerySingleSelection,
                    ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE));
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.control.AttributesTabItemControl.java

License:Open Source License

private Composite createStringFieldDetailContent(final Group detailGroup, final DataBindingContext ctx,
        final IViewerObservableValue attributeSelectionObservable) {
    final Composite composite = new Composite(detailGroup, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).spacing(15, 5).create());

    final Label lengthLabel = new Label(composite, SWT.NONE);
    lengthLabel.setLayoutData(GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).create());
    lengthLabel.setText(Messages.length);

    final ControlDecoration controlDecoration = new ControlDecoration(lengthLabel, SWT.RIGHT);
    controlDecoration.setDescriptionText(Messages.stringLengthTooltip);
    controlDecoration.setImage(Pics.getImage(PicsConstants.hint));
    controlDecoration.setMarginWidth(-2);

    final Combo lengthCombo = new Combo(composite, SWT.BORDER);
    lengthCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    lengthCombo.setItems(getStringLengthValues());

    final UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    final StringToNumberConverter converter = StringToNumberConverter.toInteger(false);
    targetToModel.setConverter(converter);
    targetToModel.setAfterGetValidator(new StringToIntegerValidator(converter));
    targetToModel.setBeforeSetValidator(new IValidator() {

        @Override//from ww w . j a v a  2  s .co m
        public IStatus validate(final Object value) {
            if (value == null || value.toString().isEmpty()) {
                final Object selectedField = attributeSelectionObservable.getValue();
                if (selectedField instanceof SimpleField
                        && ((SimpleField) selectedField).getType() == FieldType.STRING) {
                    return ValidationStatus.error(Messages.lengthCannotBeEmpty);
                }
            }
            return ValidationStatus.ok();
        }
    });
    final UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
    modelToTarget.setConverter(NumberToStringConverter.fromInteger(false));
    final Binding lengthValueBinding = ctx.bindValue(SWTObservables.observeText(lengthCombo),
            PojoObservables.observeDetailValue(attributeSelectionObservable, "length", Integer.class),
            targetToModel, modelToTarget);
    attributeSelectionObservable.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            lengthValueBinding.updateModelToTarget();
        }
    });
    return composite;
}

From source file:org.bonitasoft.studio.common.repository.ui.wizard.ExportRepositoryWizardPage.java

License:Open Source License

protected void createDestination(final Composite group) {
    final Label destPath = new Label(group, SWT.NONE);
    destPath.setText(Messages.destinationPath + " *");
    destPath.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    // destination name entry field
    destinationCombo = new Combo(group, SWT.SINGLE | SWT.BORDER);
    destinationCombo.setLayoutData(//from ww w.ja va2  s  .com
            GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).create());

    restoreWidgetValues();
    UpdateValueStrategy pathStrategy = new UpdateValueStrategy();
    pathStrategy.setAfterGetValidator(new EmptyInputValidator(Messages.destinationPath));
    if (isZip) {
        pathStrategy.setBeforeSetValidator(new IValidator() {

            @Override
            public IStatus validate(Object input) {
                if (!input.toString().endsWith(".bos")) {
                    return ValidationStatus.error(Messages.invalidFileFormat);
                }
                if (new File(input.toString()).isDirectory()) {
                    return ValidationStatus.error(Messages.invalidFileFormat);
                }
                return ValidationStatus.ok();
            }
        });
    } else {
        pathStrategy.setBeforeSetValidator(new IValidator() {

            @Override
            public IStatus validate(Object input) {
                if (!new File(input.toString()).isDirectory()) {
                    return ValidationStatus.error(Messages.destinationPathMustBeADirectory);
                }
                return ValidationStatus.ok();
            }
        });
    }

    dbc.bindValue(SWTObservables.observeText(destinationCombo),
            PojoProperties.value(ExportRepositoryWizardPage.class, "detinationPath").observe(this),
            pathStrategy, null);

    // destination browse button
    destinationBrowseButton = new Button(group, SWT.PUSH);
    destinationBrowseButton.setText(Messages.browse);
    destinationBrowseButton.setLayoutData(GridDataFactory.fillDefaults().hint(85, SWT.DEFAULT).create());

    destinationBrowseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            handleDestinationBrowseButtonPressed();
        }
    });
}

From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java

License:Open Source License

private Control createArrayComposite(final Array widget) {
    final Composite mainComposite = new Composite(section, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 0).create());

    final Label nbColLabel = new Label(mainComposite, SWT.NONE);
    nbColLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    nbColLabel.setText(Messages.nbColumn);

    final Combo columnCombo = new Combo(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    columnCombo.setLayoutData(GridDataFactory.fillDefaults().create());
    for (int i = 1; i < 11; i++) {
        columnCombo.add(String.valueOf(i));
    }//from   www  .ja  va  2s .c  o m

    if (widget.getCols() == null) {
        widget.setCols(new BigInteger("1"));
    }

    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setConverter(new Converter(String.class, BigInteger.class) {

        @Override
        public Object convert(Object from) {
            return new BigInteger((String) from);
        }
    });

    UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
    modelToTarget.setConverter(new Converter(BigInteger.class, String.class) {

        @Override
        public Object convert(Object from) {
            return String.valueOf(((BigInteger) from).intValue());
        }
    });

    context.bindValue(SWTObservables.observeText(columnCombo),
            EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.ARRAY__COLS), targetToModel,
            modelToTarget);

    final Label fixedColLabel = new Label(mainComposite, SWT.NONE);
    fixedColLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Button fixedColButton = new Button(mainComposite, SWT.CHECK);
    fixedColButton.setLayoutData(GridDataFactory.fillDefaults().create());
    fixedColButton.setText(Messages.fixedColumn);

    context.bindValue(SWTObservables.observeSelection(fixedColButton),
            EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.ARRAY__FIXED_COLS));

    final Label colHeadersLabel = new Label(mainComposite, SWT.NONE);
    colHeadersLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());
    colHeadersLabel.setText(Messages.columnHeaders);

    final Composite itemComposite = new Composite(mainComposite, SWT.NONE);
    itemComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    itemComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final TableViewer itemViewer = new TableViewer(itemComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    itemViewer.getTable()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).create());
    itemViewer.setContentProvider(new ArrayContentProvider());
    final TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(100));
    itemViewer.getTable().setLayout(layout);

    final TableViewerColumn inputNameColumn = new TableViewerColumn(itemViewer, SWT.FILL);
    inputNameColumn.getColumn().setText(Messages.input);
    inputNameColumn.setEditingSupport(new CaptionEditingSupport(itemViewer, widget));
    inputNameColumn.setLabelProvider(new ColumnLabelProvider());

    context.bindValue(ViewersObservables.observeInput(itemViewer),
            EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.ARRAY__COLS_CAPTION));

    final Composite buttonComposite = new Composite(itemComposite, SWT.NONE);
    buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
    buttonComposite
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create());

    final Button addButton = new Button(buttonComposite, SWT.FLAT);
    addButton.setText(Messages.Add);
    addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String item = generateCaption(widget);
            widget.getColsCaption().add(item);
            itemViewer.editElement(item, 0);
        }

    });

    final Button upButton = new Button(buttonComposite, SWT.FLAT);
    upButton.setText(Messages.up);
    upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement();
            int i = widget.getColsCaption().indexOf(selected);
            if (i > 0) {
                widget.getColsCaption().move(i - 1, selected);
                itemViewer.refresh();
            }
        }
    });

    final Button downButton = new Button(buttonComposite, SWT.FLAT);
    downButton.setText(Messages.down);
    downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement();
            int i = widget.getColsCaption().indexOf(selected);
            if (i < widget.getColsCaption().size() - 1) {
                widget.getColsCaption().move(i + 1, selected);
                itemViewer.refresh();
            }
        }
    });

    final Button removeButton = new Button(buttonComposite, SWT.FLAT);
    removeButton.setText(Messages.remove);
    removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            widget.getColsCaption().removeAll(((IStructuredSelection) itemViewer.getSelection()).toList());
            itemViewer.refresh();
        }
    });

    return mainComposite;
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.PageComponentSwitch.java

License:Open Source License

protected Combo createSelectControl(Composite composite, Select object) {
    final Input input = getConnectorInput(object.getInputName());
    final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);

    if (parameter != null) {
        createFieldLabel(composite, SWT.CENTER, object.getId(), input.isMandatory());
        final Combo combo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
        combo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

        final AbstractExpression inputExpression = parameter.getExpression();
        for (String item : object.getItems()) {
            combo.add(item);// www. jav a2 s.c  o m
        }
        context.bindValue(SWTObservables.observeText(combo),
                EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME));
        context.bindValue(SWTObservables.observeText(combo),
                EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT));

        if (combo.getText() == null || combo.getText().isEmpty()) {
            String defaultValue = input.getDefaultValue();
            for (String item : combo.getItems()) {
                if (defaultValue != null && item.equals(defaultValue)) {
                    combo.setText(defaultValue);
                }
            }
            if (defaultValue == null) {
                ((Expression) inputExpression).setName(combo.getItem(0));
                ((Expression) inputExpression).setContent(combo.getItem(0));
            } else if (combo.getText() == null || combo.getText().isEmpty()) {
                ((Expression) inputExpression).setName(combo.getItem(0));
                ((Expression) inputExpression).setContent(combo.getItem(0));
            }
        }

        String desc = messageProvider.getFieldDescription(definition, object.getId());
        if (desc != null && !desc.isEmpty()) {
            combo.setToolTipText(desc);
        }

        ((Expression) inputExpression).setType(ExpressionConstants.CONSTANT_TYPE);
        ((Expression) inputExpression).setReturnType(input.getType());
        return combo;
    }
    return null;
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.PageComponentSwitchBuilder.java

License:Open Source License

public Combo createSelectControl(final Composite composite, final Select object) {
    final Input input = getConnectorInput(object.getInputName());
    final ConnectorParameter parameter = getConnectorParameter(object.getInputName(), object, input);

    if (parameter != null) {
        createFieldLabel(composite, SWT.CENTER, object.getId(), input.isMandatory());
        final Combo combo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
        combo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

        final AbstractExpression inputExpression = parameter.getExpression();
        for (final String item : object.getItems()) {
            combo.add(item);//from w  w w. j a va 2  s. c o  m
        }
        context.bindValue(SWTObservables.observeText(combo),
                EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME));
        context.bindValue(SWTObservables.observeText(combo),
                EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT));

        if (combo.getText() == null || combo.getText().isEmpty()) {
            final String defaultValue = input.getDefaultValue();
            for (final String item : combo.getItems()) {
                if (defaultValue != null && item.equals(defaultValue)) {
                    combo.setText(defaultValue);
                }
            }
            if (defaultValue == null) {
                ((Expression) inputExpression).setName(combo.getItem(0));
                ((Expression) inputExpression).setContent(combo.getItem(0));
            } else if (combo.getText() == null || combo.getText().isEmpty()) {
                ((Expression) inputExpression).setName(combo.getItem(0));
                ((Expression) inputExpression).setContent(combo.getItem(0));
            }
        }

        final String desc = getDescription(object.getId());
        if (desc != null && !desc.isEmpty()) {
            combo.setToolTipText(desc);
        }

        ((Expression) inputExpression).setType(ExpressionConstants.CONSTANT_TYPE);
        ((Expression) inputExpression).setReturnType(input.getType());
        return combo;
    }
    return null;
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.support.InputMandatoryEditingSupport.java

License:Open Source License

@Override
protected IObservableValue doCreateCellEditorObservable(CellEditor cellEditor) {
    return SWTObservables.observeText(cellEditor.getControl());
}

From source file:org.bonitasoft.studio.connector.model.definition.wizard.support.WidgetInputNameEditingSupport.java

License:Open Source License

@Override
protected IObservableValue doCreateCellEditorObservable(CellEditor editor) {
    return SWTObservables.observeText(editor.getControl());
}

From source file:org.bonitasoft.studio.data.ui.wizard.DataWizardPage.java

License:Open Source License

protected void bindXSDCombo() {
    final XSDRepositoryStore store = (XSDRepositoryStore) RepositoryManager.getInstance()
            .getRepositoryStore(XSDRepositoryStore.class);
    if (nsCombo != null && !nsCombo.isDisposed()) {
        final List<XSDFileStore> allArtifacts = store.getChildren();
        for (final XSDFileStore artifact : allArtifacts) {
            final String namespace = ((XSDSchema) artifact.getContent()).getTargetNamespace();
            if (namespace != null) {
                nsCombo.add(namespace);/*from   w  w  w  .ja  va  2 s .  co  m*/
            } else {
                nsCombo.add("No Namespace " + "(" + artifact.getName() + ")");
            }
        }

        nsCombo.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                elementCombo.removeAll();
                if (nsCombo.getSelectionIndex() >= 0) {
                    final XSDFileStore artifact = store.getChildren().get(nsCombo.getSelectionIndex());
                    for (final String element : artifact.getElements()) {
                        elementCombo.add(element);
                    }
                }
            }
        });
        final IObservableValue observeValue = EMFObservables.observeValue(data,
                ProcessPackage.Literals.XML_DATA__NAMESPACE);
        final ISWTObservableValue observeText = SWTObservables.observeText(nsCombo);
        emfDatabindingContext.bindValue(observeText, observeValue);
        observeText.addValueChangeListener(new IValueChangeListener() {

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                if (newXMLButton != null && !newXMLButton.isDisposed()) {
                    newXMLButton
                            .setEnabled(((XMLData) data).getType() != null && event.diff.getNewValue() != null
                                    && !event.diff.getNewValue().toString().isEmpty());
                }
            }
        });
    }

    if (elementCombo != null && !elementCombo.isDisposed() && data instanceof XMLData) {
        elementCombo.removeAll();
        final XSDFileStore artifact = store.findArtifactWithNamespace(((XMLData) data).getNamespace());
        if (((XMLData) data).getNamespace() != null) {
            for (final String element : artifact.getElements()) {
                elementCombo.add(element);
            }
        }
        final UpdateValueStrategy strategy = new UpdateValueStrategy();
        strategy.setBeforeSetValidator(new IValidator() {

            @Override
            public IStatus validate(final Object value) {
                if (value == null || value.toString().isEmpty()) {
                    return new Status(IStatus.ERROR, DataPlugin.PLUGIN_ID, Messages.emptyXMLElement);
                }
                return Status.OK_STATUS;
            }
        });
        final IObservableValue observeValue = EMFObservables.observeValue(data,
                ProcessPackage.Literals.XML_DATA__TYPE);
        final ISWTObservableValue observeText = SWTObservables.observeText(elementCombo);
        emfDatabindingContext.bindValue(observeText, observeValue, strategy, null);
        observeText.addValueChangeListener(new IValueChangeListener() {

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                if (newXMLButton != null && !newXMLButton.isDisposed()) {
                    newXMLButton.setEnabled(
                            ((XMLData) data).getNamespace() != null && event.diff.getNewValue() != null
                                    && !event.diff.getNewValue().toString().isEmpty());
                }
            }
        });

    }
}

From source file:org.bonitasoft.studio.designer.ui.property.section.control.InfoMessageComposite.java

License:Open Source License

protected void doBindInfo(final DataBindingContext context, final IObservableValue formMappingObservable,
        final FormMappingType type) {
    final UpdateValueStrategy infoStrategy = new UpdateValueStrategy();
    infoStrategy.setConverter(new InfoMessageConverter(type));
    context.bindValue(SWTObservables.observeText(info), formMappingObservable, null, infoStrategy);
}