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, int event) 

Source Link

Document

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

Usage

From source file:org.bonitasoft.studio.simulation.wizards.AddSimulationDataWizardPage.java

License:Open Source License

/**
 * @param composite//  w w  w . java 2  s  .c o m
 * @return
 */
private Composite createBooleanConfigurationComposite(Composite composite) {

    Composite booleanComposite = new Composite(composite, SWT.NONE);
    booleanComposite.setLayout(new GridLayout(2, false));
    Label nameLabel = new Label(booleanComposite, SWT.NONE);
    nameLabel.setText(Messages.AddSimulationDataWizardPage_ProbabilityOfTrueLabel);
    Text labelText = new Text(booleanComposite, SWT.BORDER);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    //        ControlDecoration controlDecoration = new ControlDecoration(labelText, SWT.LEFT|SWT.TOP);
    //        FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
    //                .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    //        controlDecoration.setImage(fieldDecoration.getImage());
    //        controlDecoration.setDescriptionText(Messages.mustBeAPercentage);
    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setConverter(StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), true));
    targetToModel.setAfterGetValidator(new ProbabilityValidator(new StringToDoubleValidator(
            StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false))));

    Binding provider = context.bindValue(SWTObservables.observeText(labelText, SWT.Modify),
            PojoObservables.observeValue(this, "probabilityOfTrue"), targetToModel,
            new UpdateValueStrategy().setConverter(
                    NumberToStringConverter.fromDouble(BonitaNumberFormat.getPercentInstance(), true)));

    ControlDecorationSupport.create(provider, SWT.TOP | SWT.LEFT);
    return booleanComposite;
}

From source file:org.bonitasoft.studio.simulation.wizards.AddSimulationDataWizardPage.java

License:Open Source License

private void createNameAndDescription(Composite composite) {
    Label nameLabel = new Label(composite, SWT.NONE);
    nameLabel.setText(Messages.dataNameLabel);
    final Text labelText = new Text(composite, SWT.BORDER);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    // Add an validator so that age can only be a number
    IValidator validator = new IValidator() {

        Set<String> existingDataNames = null;

        @Override//from www .  j a  v  a  2s .  co m
        public IStatus validate(Object arg0) {
            if (existingDataNames == null) {
                existingDataNames = new HashSet<String>();
                if (element != null) {
                    for (SimulationData simuData : element.getSimulationData()) {
                        existingDataNames.add(simuData.getName());
                    }
                }
            }

            if (existingDataNames.contains(labelText.getText())) {

                return ValidationStatus.error("Data name already exists.");
            }
            return ValidationStatus.ok();
        }

    };
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(validator);

    Binding bindingDataName = context.bindValue(SWTObservables.observeText(labelText, SWT.Modify),
            PojoObservables.observeValue(this, "dataName"), strategy, null);

    ControlDecorationSupport.create(bindingDataName, SWT.TOP | SWT.LEFT);
    //labelText.addModifyListener(updateButtonModifyListener) ;

    Label isExpressionLabel = new Label(composite, SWT.NONE);
    isExpressionLabel.setText(Messages.BasedOn);

    Composite radioBasedComposite = new Composite(composite, SWT.NONE);
    radioBasedComposite.setLayout(new GridLayout(2, true));

    isExpressionBased = new Button(radioBasedComposite, SWT.RADIO);
    isExpressionBased.setText(Messages.Expression);
    isExpressionBased.setSelection(expressionBased);
    isOtherBased = new Button(radioBasedComposite, SWT.RADIO);
    isOtherBased.setSelection(!expressionBased);
    isOtherBased.setText(Messages.AddSimulationDataWizardPage_probability);
    context.bindValue(SWTObservables.observeSelection(isExpressionBased),
            PojoObservables.observeValue(this, "expressionBased"));
    context.bindValue(SWTObservables.observeSelection(isOtherBased),
            PojoObservables.observeValue(this, "expressionBased"),
            new UpdateValueStrategy().setConverter(new Converter(Boolean.class, Boolean.class) {
                @Override
                public Object convert(Object fromObject) {
                    return !(Boolean) fromObject;
                }
            }), new UpdateValueStrategy().setConverter(new Converter(Boolean.class, Boolean.class) {
                @Override
                public Object convert(Object fromObject) {
                    return !(Boolean) fromObject;
                }
            }));

    Label expressionLabel = new Label(composite, SWT.NONE);
    expressionLabel.setText(Messages.Expression);

    ExpressionViewer expressionViewer = new ExpressionViewer(composite, SWT.BORDER, null);//FIXME: Expressionviewer
    expressionViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    if (element != null) {
        expressionViewer.setInput(element);
    } else {
        expressionViewer.setInput(data.eContainer());
    }
    expressionViewer.addFilter(new AvailableExpressionTypeFilter(
            new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.SIMULATION_VARIABLE_TYPE }));
    expressionViewer.setSelection(new StructuredSelection(dataExpression));

    context.bindValue(SWTObservables.observeVisible(expressionLabel),
            SWTObservables.observeSelection(isExpressionBased));
    context.bindValue(SWTObservables.observeVisible(expressionViewer.getControl()),
            SWTObservables.observeSelection(isExpressionBased));

    isOtherBased.addSelectionListener(updateButtonSelectionListener);
    isExpressionBased.addSelectionListener(updateButtonSelectionListener);

}

From source file:org.bonitasoft.studio.validators.ui.property.section.ValidatorsPropertySection.java

License:Open Source License

@Override
public void refresh() {
    super.refresh();

    if (tableViewer != null && !tableViewer.getTable().isDisposed() && comboViewerForValidatorClass != null
            && !comboViewerForValidatorClass.getCombo().isDisposed()) {
        if (getValidable().getValidators().size() > 0) {
            /*update value in the treeviewer when the name changed.*/
            tableViewer.refresh(true);//from   ww  w .  ja va 2  s. c  o  m
            currentValidator = (Validator) ((IStructuredSelection) tableViewer.getSelection())
                    .getFirstElement();
        } else {
            /*update the treeviewer if the last validator is removed*/
            tableViewer.refresh(true);
            currentValidator = null;
        }

        if (lastEObject == null || !lastEObject.equals(getEObject())) {
            lastEObject = getEObject();
            if (lastEObject != null) {
                tableViewer.setInput(getValidable());
                comboViewerForValidatorClass.resetFilters();
                if (getEObject() instanceof Form) {
                    comboViewerForValidatorClass.addFilter(formFilter);
                } else {
                    comboViewerForValidatorClass.addFilter(fieldFilter);
                }

                //               for(Validator validator :((Validable)lastEObject).getValidators()){
                //                  if(validator.getValidatorClass() != null){
                //                     boolean stilExists = false ;
                //                     for(IRepositoryFileStore file : validatorStore.getChildren()){
                //                        ValidatorDescriptor desc = (ValidatorDescriptor) file.getContent() ;
                //                        if(desc.getClassName().equals(validator.getValidatorClass())){
                //                           stilExists = true ;
                //                           break ;
                //                        }
                //                     }
                //                     if(!stilExists){
                //                        getEditingDomain().getCommandStack().execute(SetCommand.create(getEditingDomain(), validator, FormPackage.Literals.VALIDATOR__VALIDATOR_CLASS, null)) ;
                //                     }
                //                  }
                //               }

                comboViewerForValidatorClass.setInput(validatorStore.getValidatorDescriptors());

                if (context != null) {
                    context.dispose();
                }
                context = new EMFDataBindingContext();

                updateFieldDependingOnValidatorClass();

                if (defaultValidatorContext != null) {
                    defaultValidatorContext.dispose();
                }
                defaultValidatorContext = new DataBindingContext();
                defaultValidatorContext.bindValue(SWTObservables.observeSelection(defaultValidator),
                        EMFObservables.observeValue(getEObject(),
                                FormPackage.Literals.VALIDABLE__USE_DEFAULT_VALIDATOR));

                defaultValidatorContext.bindValue(SWTObservables.observeSelection(defaultValidatorIsBelow),
                        EMFObservables.observeValue(getEObject(), FormPackage.Literals.VALIDABLE__BELOW));

                defaultValidatorContext.bindValue(SWTObservables.observeSelection(defaultValidatorIsAbove),
                        EMFObservables.observeValue(getEObject(), FormPackage.Literals.VALIDABLE__BELOW),
                        new UpdateValueStrategy().setConverter(converter),
                        new UpdateValueStrategy().setConverter(converter));

                defaultValidator.setVisible(
                        lastEObject instanceof Widget && !(lastEObject instanceof MultipleValuatedFormField));
                positionComp.setVisible(lastEObject instanceof Widget && defaultValidator.getSelection());

                /*
                 * Use pattern master-detail databinding in order to be up to date with the selection in the FilteredTreeViewer
                 * */

                //      labelField.setElement((Element) lastEObject);
                //      labelField.reset();

                /*Observe change in selection*/
                IViewerObservableValue treeViewerObservaleValue = ViewersObservables
                        .observeSingleSelection(tableViewer);

                //Observe the validator name property of the current selection
                IObservableValue nameDetailValue = EMFObservables.observeDetailValue(Realm.getDefault(),
                        treeViewerObservaleValue, FormPackage.Literals.VALIDATOR__NAME);

                //Bind the Text widget to the name detail
                ISWTObservableValue nameFieldObservableValue = SWTObservables.observeText(nameField,
                        SWT.Modify);
                context.bindValue(nameFieldObservableValue, nameDetailValue);
                nameFieldObservableValue.addValueChangeListener(new IValueChangeListener() {
                    @Override
                    public void handleValueChange(ValueChangeEvent event) {
                        /*update value in the treeviewer when the name changed.*/
                        tableViewer.refresh(true);
                    }
                });

                //Observe the validator classes of the current selection
                IObservableValue emfValidatorClassObservableDetailValue = EMFObservables.observeDetailValue(
                        Realm.getDefault(), treeViewerObservaleValue,
                        FormPackage.Literals.VALIDATOR__VALIDATOR_CLASS);

                //Bind the Combo widget to the validator class detail
                IViewerObservableValue comboViewerObservable = ViewersObservables
                        .observeSingleSelection(comboViewerForValidatorClass);
                UpdateValueStrategy targetStrategy = new UpdateValueStrategy();
                targetStrategy.setConverter(new Converter(ValidatorDescriptor.class, String.class) {

                    @Override
                    public Object convert(Object from) {
                        if (from != null && from instanceof ValidatorDescriptor) {
                            return ((ValidatorDescriptor) from).getClassName();
                        }
                        return null;
                    }
                });
                UpdateValueStrategy modelStrategy = new UpdateValueStrategy();
                modelStrategy.setConverter(new Converter(String.class, ValidatorDescriptor.class) {

                    @Override
                    public Object convert(Object from) {
                        if (from != null && from instanceof String) {
                            Collection<ValidatorDescriptor> input = (Collection<ValidatorDescriptor>) comboViewerForValidatorClass
                                    .getInput();
                            for (ValidatorDescriptor d : input) {
                                if (d.getClassName().equals(from)) {
                                    return d;
                                }
                            }
                        }
                        return null;
                    }
                });

                context.bindValue(comboViewerObservable, emfValidatorClassObservableDetailValue, targetStrategy,
                        modelStrategy);

                /*When value changed,
                 * look if need to enabled/disabled some widgets*/
                comboViewerObservable.addValueChangeListener(new IValueChangeListener() {
                    @Override
                    public void handleValueChange(ValueChangeEvent event) {
                        updateFieldDependingOnValidatorClass();
                    }
                });

                IObservableValue htmlDetailValue = EMFObservables.observeDetailValue(Realm.getDefault(),
                        treeViewerObservaleValue, FormPackage.Literals.VALIDATOR__HTML_CLASS);
                context.bindValue(SWTObservables.observeText(htmlClassField, SWT.Modify), htmlDetailValue);

                IObservableValue isBelowValue = EMFObservables.observeDetailValue(Realm.getDefault(),
                        treeViewerObservaleValue, FormPackage.Literals.VALIDATOR__BELOW_FIELD);
                context.bindValue(SWTObservables.observeSelection(isBelow), isBelowValue);
                context.bindValue(SWTObservables.observeSelection(isAbove), isBelowValue,
                        new UpdateValueStrategy().setConverter(converter),
                        new UpdateValueStrategy().setConverter(converter));
            }
        }
        //            else{
        //                comboViewerForValidatorClass.setInput(validatorStore.getValidatorDescriptors());
        //                Validator validator = (Validator) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement() ;
        //                if(validator != null && validator.getValidatorClass() != null){
        //                    comboViewerForValidatorClass.setSelection(new StructuredSelection(validatorStore.getValidatorDescriptor(validator.getValidatorClass())));
        //                }
        //            }
    }
}

From source file:org.bonitasoft.studio.validators.ui.wizard.ValidatorWizardPage.java

License:Open Source License

private void createDisplayNameLine(Composite mainComposite) {
    Label displayNameLabel = new Label(mainComposite, SWT.NONE);
    displayNameLabel.setText(Messages.createValidatorWizardPage_displayNameLabel + " *");
    displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text displayNameText = new Text(mainComposite, SWT.BORDER);
    displayNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setAfterGetValidator(new IValidator() {

        @Override//from w  w w .ja v  a  2 s .co  m
        public IStatus validate(Object value) {
            if (value == null || value.toString().isEmpty()) {
                return new Status(IStatus.ERROR, ValidatorPlugin.PLUGIN_ID, Messages.nameIsEmpty);
            }
            return Status.OK_STATUS;
        }
    });

    context.bindValue(SWTObservables.observeText(displayNameText, SWT.Modify),
            EMFObservables.observeValue(validator, ValidatorPackage.Literals.VALIDATOR_DESCRIPTOR__NAME),
            targetToModel, null);
}

From source file:org.bonitasoft.studio.validators.ui.wizard.ValidatorWizardPage.java

License:Open Source License

private void createClassAndPackageName(Composite mainComposite) {
    Label classNameLabel = new Label(mainComposite, SWT.NONE);
    classNameLabel.setText(Messages.createValidatorWizardPage_classNameLabel + " *");
    classNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text classNameText = new Text(mainComposite, SWT.BORDER);
    classNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    final Label packageLabel = new Label(mainComposite, SWT.NONE);
    packageLabel.setText(Messages.createValidatorWizardPage_packageLabel + " *");
    packageLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final Text packageText = new Text(mainComposite, SWT.BORDER);
    packageText.setLayoutData(/*from w  ww.  ja v  a2 s .  c  o  m*/
            GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

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

        @Override
        public Object convert(Object from) {
            if (from != null) {
                String packageName = from.toString();
                if (classNameText != null && !classNameText.isDisposed()) {
                    return packageName + "." + classNameText.getText();
                }
            }
            return null;
        }
    });
    packageTargetToModel.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (!value.toString().isEmpty()) {
                return JavaConventions.validatePackageName(value.toString(), JavaCore.VERSION_1_6,
                        JavaCore.VERSION_1_6);
            } else {
                return new Status(IStatus.ERROR, ValidatorPlugin.PLUGIN_ID, Messages.missingPackageName);
            }
        }
    });

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

        @Override
        public Object convert(Object from) {
            if (from != null) {
                String qualifiedClassname = from.toString();
                if (qualifiedClassname.indexOf(".") != -1) {
                    int i = qualifiedClassname.lastIndexOf(".");
                    return qualifiedClassname.subSequence(0, i);
                } else {
                    return "";
                }
            }
            return null;
        }
    });

    packageModelToTarget.setAfterConvertValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value == null || value.toString().isEmpty()) {
                return new Status(IStatus.ERROR, ValidatorPlugin.PLUGIN_ID, Messages.missingPackageName);
            }
            return JavaConventions.validatePackageName(value.toString(), JavaCore.VERSION_1_6,
                    JavaCore.VERSION_1_6);
        }
    });

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

        @Override
        public Object convert(Object from) {
            if (from != null) {
                String className = from.toString();
                if (packageText != null && !packageText.isDisposed()) {
                    return packageText.getText() + "." + className;
                }
            }
            return null;
        }
    });
    classTargetToModel.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value == null || value.toString().isEmpty()) {
                return new Status(IStatus.ERROR, ValidatorPlugin.PLUGIN_ID, Messages.missingClassname);
            }
            return JavaConventions.validateJavaTypeName(value.toString(), JavaCore.VERSION_1_6,
                    JavaCore.VERSION_1_6);
        }
    });

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

        @Override
        public Object convert(Object from) {
            if (from != null) {
                String qualifiedClassname = from.toString();
                if (qualifiedClassname.indexOf(".") != -1) {
                    int i = qualifiedClassname.lastIndexOf(".");
                    return qualifiedClassname.subSequence(i + 1, qualifiedClassname.length());
                } else {
                    return qualifiedClassname;
                }
            }
            return null;
        }
    });

    context.bindValue(SWTObservables.observeText(classNameText, SWT.Modify),
            EMFObservables.observeValue(validator, ValidatorPackage.Literals.VALIDATOR_DESCRIPTOR__CLASS_NAME),
            classTargetToModel, classModelToTarget);
    context.bindValue(SWTObservables.observeText(packageText, SWT.Modify),
            EMFObservables.observeValue(validator, ValidatorPackage.Literals.VALIDATOR_DESCRIPTOR__CLASS_NAME),
            packageTargetToModel, packageModelToTarget);

    final Button browsePackagesButton = new Button(mainComposite, SWT.PUSH);
    browsePackagesButton.setText(Messages.createValidatorWizardPage_browsePackages);
    browsePackagesButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            IPackageFragment selectedPackage = ValidatorWizardPage.this.choosePackage();
            if (selectedPackage != null) {
                packageText.setText(selectedPackage.getElementName());
            }
        }
    });

}

From source file:org.bonitasoft.studio.xml.ui.XPathExpressionEditor.java

License:Open Source License

@Override
public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context,
        Expression inputExpression, ViewerFilter[] filters, ExpressionViewer expressionViewer) {
    editorInputExpression = inputExpression;
    Set<Data> input = new HashSet<Data>();
    IExpressionProvider provider = ExpressionEditorService.getInstance()
            .getExpressionProvider(ExpressionConstants.VARIABLE_TYPE);
    for (Expression e : provider.getExpressions(context)) {

        EObject data = e.getReferencedElements().get(0);
        if (data instanceof XMLData) {
            input.add((XMLData) data);//from   ww w.  ja v  a 2  s  .com
        }
    }
    viewer.setInput(input);

    IObservableValue nameObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__NAME);
    IObservableValue contentObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__CONTENT);
    final IObservableValue returnTypeObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE);
    IObservableValue referenceObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS);

    UpdateValueStrategy selectionToName = new UpdateValueStrategy();
    IConverter nameConverter = new Converter(String.class, String.class) {

        @Override
        public Object convert(Object data) {
            if (data instanceof Data) {
                XMLData xmlData = (XMLData) data;
                return xmlData.getName() + " - " + editorInputExpression.getContent();
            } else if (data instanceof String) {
                final XMLData xmlData = (XMLData) ((IStructuredSelection) viewer.getSelection())
                        .getFirstElement();

                return xmlData.getName() + " - " + data;

            }
            return null;
        }

    };
    selectionToName.setConverter(nameConverter);

    UpdateValueStrategy selectionToContent = new UpdateValueStrategy();
    IConverter contentConverter = new Converter(Object.class, String.class) {

        @Override
        public Object convert(Object value) {
            if (!xsdViewer.getSelection().isEmpty()) {
                return computeXPath((ITreeSelection) xsdViewer.getSelection());
            }
            Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (selection instanceof Data) {
                return ((Data) selection).getName();
            }
            return null;
        }

    };
    selectionToContent.setConverter(contentConverter);

    UpdateValueStrategy contentToSelection = new UpdateValueStrategy();
    IConverter methodToSelectionConverter = new Converter(String.class, Object.class) {

        @Override
        public Object convert(Object xPathExpression) {
            if (xPathExpression instanceof String) {
                ITreeSelection selection = new org.eclipse.jface.viewers.TreeSelection(createTreePath(
                        (String) xPathExpression, (XSDContentProvider) xsdViewer.getContentProvider()));
                return selection.getFirstElement();
            }
            return null;
        }

    };
    contentToSelection.setConverter(methodToSelectionConverter);

    UpdateValueStrategy selectionToReturnType = new UpdateValueStrategy();
    selectionToReturnType.setConverter(new Converter(Object.class, String.class) {

        @Override
        public Object convert(Object element) {
            if (editorInputExpression.isReturnTypeFixed()) {
                return returnTypeObservable.getValue();
            } else {
                return XPathReturnType.getType(element);
            }

        }

    });

    UpdateValueStrategy selectionToReferencedData = new UpdateValueStrategy();
    IConverter referenceConverter = new Converter(Data.class, List.class) {

        @Override
        public Object convert(Object data) {
            if (data != null) {
                XMLData xmlData = (XMLData) data;
                dataName = xmlData.getName();
                String namespace = xmlData.getNamespace();
                String element = xmlData.getType();
                XSDRepositoryStore xsdStore = (XSDRepositoryStore) RepositoryManager.getInstance()
                        .getRepositoryStore(XSDRepositoryStore.class);
                XSDElementDeclaration root = xsdStore.findElementDeclaration(namespace, element);
                XSDElementDeclaration existingElement = ((XSDContentProvider) xsdViewer.getContentProvider())
                        .getElement();
                if (existingElement == null || !existingElement.equals(root)) {
                    ((XSDContentProvider) xsdViewer.getContentProvider()).setElement(root);
                }
                return Collections.singletonList(data);
            } else {
                return Collections.emptyList();
            }
        }

    };
    selectionToReferencedData.setConverter(referenceConverter);

    UpdateValueStrategy referencedDataToSelection = new UpdateValueStrategy();
    IConverter referencetoDataConverter = new Converter(List.class, Data.class) {

        @Override
        public Object convert(Object dataList) {
            Data d = ((List<Data>) dataList).get(0);
            Collection<Data> inputData = (Collection<Data>) viewer.getInput();
            for (Data data : inputData) {
                if (data.getName().equals(d.getName())
                        && data.getDataType().getName().equals(d.getDataType().getName())) {
                    XMLData xmlData = (XMLData) data;
                    dataName = xmlData.getName();
                    String namespace = xmlData.getNamespace();
                    String element = xmlData.getType();
                    XSDRepositoryStore xsdStore = (XSDRepositoryStore) RepositoryManager.getInstance()
                            .getRepositoryStore(XSDRepositoryStore.class);
                    XSDElementDeclaration root = xsdStore.findElementDeclaration(namespace, element);
                    ((XSDContentProvider) xsdViewer.getContentProvider()).setElement(root);
                    return data;
                }
            }
            return null;
        }

    };
    referencedDataToSelection.setConverter(referencetoDataConverter);

    UpdateValueStrategy enableStrategy = new UpdateValueStrategy();
    enableStrategy.setConverter(new Converter(Object.class, Boolean.class) {
        @Override
        public Object convert(Object fromObject) {
            return fromObject != null;
        }
    });
    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(viewer), referenceObservable,
            selectionToReferencedData, referencedDataToSelection);
    dataBindingContext.bindValue(SWTObservables.observeText(text, SWT.Modify), nameObservable, selectionToName,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));

    dataBindingContext.bindValue(SWTObservables.observeEnabled(xsdViewer.getTree()),
            ViewersObservables.observeSingleSelection(viewer),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableStrategy);
    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(xsdViewer), contentObservable,
            selectionToContent, contentToSelection);
    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(xsdViewer), returnTypeObservable,
            selectionToReturnType, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));

    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(typeCombo), returnTypeObservable);
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.wizards.AbstractCloudFoundryServiceWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(10, LayoutConstants.getSpacing().y)
            .applyTo(composite);//from ww  w .  j av a 2s . c o m

    Label label = new Label(composite, SWT.NONE);
    label.setText("Name:");

    nameText = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText);
    nameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            service.setName(nameText.getText());
        }
    });

    bindingContext = new DataBindingContext();
    map = new WritableMap();

    WizardPageSupport.create(this, bindingContext);

    bindingContext.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
            Observables.observeMapEntry(map, "name"),
            new UpdateValueStrategy().setAfterConvertValidator(new StringValidator()), null);

    label = new Label(composite, SWT.NONE);
    label.setText("Type:");

    typeCombo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(typeCombo);
    typeCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = typeCombo.getSelectionIndex();
            if (index != -1) {
                ServiceConfiguration configuration = configurations.get(index);
                setCloudService(service, configuration);
            }
            refreshPlan();
        }
    });

    bindingContext.bindValue(SWTObservables.observeSelection(typeCombo),
            Observables.observeMapEntry(map, "type"),
            new UpdateValueStrategy().setAfterConvertValidator(new ComboValidator("Select a type")), null);

    pageBook = new PageBook(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(pageBook);

    planGroup = new Group(pageBook, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(planGroup);
    planGroup.setLayout(new GridLayout());
    planGroup.setVisible(false);
    planGroup.setText(getPlanLabel());

    MultiValidator validator = new MultiValidator() {
        protected IStatus validate() {
            // access plan value to bind validator
            if (planObservable.getValue() == null) {
                return ValidationStatus.cancel(getValidationErrorMessage());
            }
            return ValidationStatus.ok();
        }
    };
    bindingContext.addValidationStatusProvider(validator);

    Dialog.applyDialogFont(composite);
    setControl(composite);
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.wizards.CloudFoundryServiceWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(10, LayoutConstants.getSpacing().y)
            .applyTo(composite);//from w  ww .j  a va 2s . c  o  m

    Label label = new Label(composite, SWT.NONE);
    label.setText("Name:");

    nameText = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText);
    nameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            service.setName(nameText.getText());
        }
    });

    bindingContext = new DataBindingContext();
    map = new WritableMap();

    WizardPageSupport.create(this, bindingContext);

    bindingContext.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
            Observables.observeMapEntry(map, "name"),
            new UpdateValueStrategy().setAfterConvertValidator(new StringValidator()), null);

    label = new Label(composite, SWT.NONE);
    label.setText("Type:");

    typeCombo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(typeCombo);
    typeCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = typeCombo.getSelectionIndex();
            if (index != -1) {
                ServiceConfiguration configuration = configurations.get(index);
                service.setType(configuration.getType());
                service.setVendor(configuration.getVendor());
                service.setVersion(configuration.getVersion());
            }
            refreshTier();
        }
    });

    bindingContext.bindValue(SWTObservables.observeSelection(typeCombo),
            Observables.observeMapEntry(map, "type"),
            new UpdateValueStrategy().setAfterConvertValidator(new ComboValidator("Select a type")), null);

    pageBook = new PageBook(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(pageBook);

    tierLabel = new Label(pageBook, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tierLabel);

    tierGroup = new Group(pageBook, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tierGroup);
    tierGroup.setLayout(new GridLayout());
    tierGroup.setVisible(false);
    tierGroup.setText("Tier");

    MultiValidator validator = new MultiValidator() {
        protected IStatus validate() {
            // access tier value to bind validator
            if (tierObservable.getValue() == null) {
                return ValidationStatus.cancel("Select a tier");
            }
            return ValidationStatus.ok();
        }
    };
    bindingContext.addValidationStatusProvider(validator);

    Dialog.applyDialogFont(composite);
    setControl(composite);
}

From source file:org.cloudfoundry.ide.eclipse.server.ui.internal.wizards.CloudFoundryServicePlanWizardPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(10, LayoutConstants.getSpacing().y)
            .applyTo(composite);//w  w w. java2  s.c  o  m

    Label label = new Label(composite, SWT.NONE);
    label.setText(Messages.COMMONTXT_NAME_WITH_COLON);

    nameText = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText);
    nameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            service.setName(nameText.getText());
        }
    });

    bindingContext = new DataBindingContext();
    map = new WritableMap();

    WizardPageSupport.create(this, bindingContext);

    bindingContext.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
            Observables.observeMapEntry(map, "name"), //$NON-NLS-1$
            new UpdateValueStrategy().setAfterConvertValidator(new StringValidator()), null);

    label = new Label(composite, SWT.NONE);
    label.setText(Messages.CloudFoundryServicePlanWizardPage_LABEL_TYPE);

    typeCombo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(typeCombo);
    typeCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int index = typeCombo.getSelectionIndex();
            if (index != -1) {
                CloudServiceOffering configuration = serviceOfferings.get(index);
                setCloudService(service, configuration);
            }
            refreshPlan();
        }
    });

    bindingContext
            .bindValue(SWTObservables.observeSelection(typeCombo), Observables.observeMapEntry(map, "type"), //$NON-NLS-1$
                    new UpdateValueStrategy().setAfterConvertValidator(
                            new ComboValidator(Messages.CloudFoundryServicePlanWizardPage_TEXT_SELECT_TYPE)),
                    null);

    pageBook = new PageBook(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(pageBook);

    planGroup = new Group(pageBook, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(planGroup);
    planGroup.setLayout(new GridLayout());
    planGroup.setVisible(false);
    planGroup.setText(getPlanLabel());

    MultiValidator validator = new MultiValidator() {
        protected IStatus validate() {
            // access plan value to bind validator
            if (planObservable.getValue() == null) {
                return ValidationStatus.cancel(getValidationErrorMessage());
            }
            return ValidationStatus.ok();
        }
    };
    bindingContext.addValidationStatusProvider(validator);

    Dialog.applyDialogFont(composite);
    setControl(composite);
}

From source file:org.dozer.eclipse.plugin.editorpage.utils.DozerUiUtils.java

License:Apache License

public static IObservableValue createText(Composite client, String messagePrefix) {
    Text text = toolkit.createText(client, "", SWT.SINGLE); //$NON-NLS-1$
    text.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
    text.setToolTipText(Messages.getString(messagePrefix + "_hint")); //$NON-NLS-1$

    //Format//  w ww .  j  a v  a 2  s .c o  m
    TableWrapData td = new TableWrapData(TableWrapData.FILL_GRAB);
    text.setLayoutData(td);

    return SWTObservables.observeText(text, SWT.Modify);
}