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

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

Introduction

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

Prototype

@Deprecated
public static ISWTObservableValue observeSelection(Control control) 

Source Link

Document

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

Usage

From source file:org.objectstyle.wolips.eomodeler.editors.entity.EOEntityAdvancedEditorSection.java

License:Open Source License

public void setInput(IWorkbenchPart part, ISelection selection) {
    if (ComparisonUtils.equals(selection, getSelection())) {
        return;/*www  .ja  v a2  s .c om*/
    }

    super.setInput(part, selection);
    disposeBindings();

    Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
    _entity = (EOEntity) selectedObject;
    if (_entity != null) {
        _bindingContext = new DataBindingContext();
        _bindingContext.bindValue(SWTObservables.observeText(_maxNumberOfInstancesToBatchFetchText, SWT.Modify),
                BeansObservables.observeValue(_entity, EOEntity.MAX_NUMBER_OF_INSTANCES_TO_BATCH_FETCH), null,
                null);
        // new BindSpec(null, null, new RegexStringValidator("^[0-9]*$",
        // "^[0-9]+$", "Please enter a number"), null));
        _bindingContext.bindValue(SWTObservables.observeSelection(_cacheInMemoryButton),
                BeansObservables.observeValue(_entity, EOEntity.CACHES_OBJECTS), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_readOnlyButton),
                BeansObservables.observeValue(_entity, EOEntity.READ_ONLY), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_immutableButton),
                BeansObservables.observeValue(_entity, EOEntity.IMMUTABLE), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_generateSourceButton),
                BeansObservables.observeValue(_entity, EOEntity.GENERATE_SOURCE), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_rawRowsOnlyButton),
                BeansObservables.observeValue(_entity, EOEntity.RAW_ROWS_ONLY), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeText(_externalQueryText, SWT.Modify),
                BeansObservables.observeValue(_entity, EOEntity.EXTERNAL_QUERY), null, null);
        _bindingContext.bindValue(SWTObservables.observeText(_clientClassNameText, SWT.Modify),
                BeansObservables.observeValue(_entity, EOEntity.CLIENT_CLASS_NAME), null, null);
        _bindingContext.bindValue(SWTObservables.observeText(_parentClassNameText, SWT.Modify),
                BeansObservables.observeValue(_entity, EOEntity.PARENT_CLASS_NAME), null, null);

        _partialEntityComboViewer.setInput(_entity);
        _partialEntityBinding = new ComboViewerBinding(_partialEntityComboViewer, _entity,
                EOEntity.PARTIAL_ENTITY, _entity.getModel(), EOModel.ENTITIES,
                EOEntityListContentProvider.BLANK_ENTITY);
    }
}

From source file:org.objectstyle.wolips.eomodeler.editors.entity.EOEntityBasicEditorSection.java

License:Open Source License

public void setInput(IWorkbenchPart part, ISelection selection) {
    if (ComparisonUtils.equals(selection, getSelection())) {
        return;/*  ww w  .ja  va 2s .c o m*/
    }

    super.setInput(part, selection);
    Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
    EOEntity entity = (EOEntity) selectedObject;
    if (!ComparisonUtils.equals(entity, myEntity)) {
        disposeBindings();

        myEntity = entity;
        if (myEntity != null) {
            myBindingContext = new DataBindingContext();
            myBindingContext.bindValue(SWTObservables.observeText(myNameText, SWT.Modify),
                    BeansObservables.observeValue(myEntity, EOEntity.NAME), null, null);
            myBindingContext.bindValue(SWTObservables.observeText(myExternalNameText, SWT.Modify),
                    BeansObservables.observeValue(myEntity, EOEntity.EXTERNAL_NAME), null, null);
            myBindingContext.bindValue(SWTObservables.observeText(myClassNameText, SWT.Modify),
                    BeansObservables.observeValue(myEntity, EOEntity.CLASS_NAME), null, null);
            myBindingContext.bindValue(SWTObservables.observeText(myRestrictingQualifierText, SWT.Modify),
                    BeansObservables.observeValue(myEntity, EOEntity.RESTRICTING_QUALIFIER), null, null);
            myBindingContext.bindValue(SWTObservables.observeSelection(myAbstractButton),
                    BeansObservables.observeValue(myEntity, EOEntity.ABSTRACT_ENTITY), null,
                    new BooleanUpdateValueStrategy());

            myParentEntityComboViewer.setInput(myEntity);
            myParentEntityBinding = new ComboViewerBinding(myParentEntityComboViewer, myEntity, EOEntity.PARENT,
                    myEntity.getModel(), EOModel.ENTITIES, EOEntityListContentProvider.BLANK_ENTITY);
        }
    }
}

From source file:org.objectstyle.wolips.eomodeler.editors.fetchspec.EOFetchSpecOptionsEditorSection.java

License:Open Source License

public void setInput(IWorkbenchPart part, ISelection selection) {
    if (ComparisonUtils.equals(selection, getSelection())) {
        return;/*www .  ja  v a2  s.c  om*/
    }

    super.setInput(part, selection);
    disposeBindings();

    Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
    _fetchSpecification = (EOFetchSpecification) selectedObject;
    if (_fetchSpecification != null) {
        _bindingContext = new DataBindingContext();
        _bindingContext.bindValue(SWTObservables.observeText(_fetchLimitText, SWT.Modify),
                BeansObservables.observeValue(_fetchSpecification, EOFetchSpecification.FETCH_LIMIT), null,
                null);
        // new BindSpec(null, null, new RegexStringValidator("^[0-9]*$",
        // "^[0-9]+$", "Please enter a number"), null));
        _bindingContext.bindValue(SWTObservables.observeSelection(_promptsAfterFetchLimitButton),
                BeansObservables.observeValue(_fetchSpecification,
                        EOFetchSpecification.PROMPTS_AFTER_FETCH_LIMIT),
                null, new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_deepButton),
                BeansObservables.observeValue(_fetchSpecification, EOFetchSpecification.DEEP), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_usesDistinctButton),
                BeansObservables.observeValue(_fetchSpecification, EOFetchSpecification.USES_DISTINCT), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_lockObjectsButton),
                BeansObservables.observeValue(_fetchSpecification, EOFetchSpecification.LOCKS_OBJECTS), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_refreshesRefetchedObjectsButton),
                BeansObservables.observeValue(_fetchSpecification,
                        EOFetchSpecification.REFRESHES_REFETCHED_OBJECTS),
                null, new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_requiresAllQualifierBindingVariablesButton),
                BeansObservables.observeValue(_fetchSpecification,
                        EOFetchSpecification.REQUIRES_ALL_QUALIFIER_BINDING_VARIABLES),
                null, new BooleanUpdateValueStrategy());
    }
}

From source file:org.objectstyle.wolips.eomodeler.editors.relationship.EORelationshipAdvancedEditorSection.java

License:Open Source License

public void setInput(IWorkbenchPart part, ISelection selection) {
    if (ComparisonUtils.equals(selection, getSelection())) {
        return;//from ww w  . ja  va 2  s . c om
    }

    super.setInput(part, selection);
    disposeBindings();

    Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
    if (selectedObject instanceof EORelationship) {
        _relationship = (EORelationship) selectedObject;
    } else if (selectedObject instanceof EORelationshipPath) {
        _relationship = ((EORelationshipPath) selectedObject).getChildRelationship();
    }
    if (_relationship != null) {
        _relationship.addPropertyChangeListener(EORelationship.TO_MANY, _relationshipPropertyChangeListener);
        _bindingContext = new DataBindingContext();
        _bindingContext.bindValue(
                SWTObservables.observeText(_numberOfToManyFaultsToBatchFetchText, SWT.Modify), BeansObservables
                        .observeValue(_relationship, EORelationship.NUMBER_OF_TO_MANY_FAULTS_TO_BATCH_FETCH),
                null, null);
        // new BindSpec(null, null, new RegexStringValidator("^[0-9]*$",
        // "^[0-9]+$", "Please enter a number"), null)
        _bindingContext.bindValue(SWTObservables.observeSelection(_ownsDestinationButton),
                BeansObservables.observeValue(_relationship, EORelationship.OWNS_DESTINATION), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_propagatesPrimaryKeyButton),
                BeansObservables.observeValue(_relationship, EORelationship.PROPAGATES_PRIMARY_KEY), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_clientClassPropertyButton),
                BeansObservables.observeValue(_relationship, EORelationship.CLIENT_CLASS_PROPERTY), null,
                new BooleanUpdateValueStrategy());
        _bindingContext.bindValue(SWTObservables.observeSelection(_commonClassPropertyButton),
                BeansObservables.observeValue(_relationship, EORelationship.COMMON_CLASS_PROPERTY), null,
                new BooleanUpdateValueStrategy());
        updateCardinalityEnabled();
    }
}

From source file:org.objectstyle.wolips.eomodeler.editors.relationship.EORelationshipBasicEditorSection.java

License:Open Source License

public void setInput(IWorkbenchPart part, ISelection selection) {
    if (ComparisonUtils.equals(selection, getSelection())) {
        return;//from  w  ww .  ja va2  s .com
    }

    super.setInput(part, selection);
    EORelationship relationship = null;
    Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
    if (selectedObject instanceof EORelationship) {
        relationship = (EORelationship) selectedObject;
    } else if (selectedObject instanceof EORelationshipPath) {
        relationship = ((EORelationshipPath) selectedObject).getChildRelationship();
    }
    if (!ComparisonUtils.equals(relationship, _relationship)) {
        disposeBindings();

        _relationship = relationship;
        if (_relationship != null) {
            _relationship.addPropertyChangeListener(EORelationship.JOINS, _joinsListener);
            _relationship.addPropertyChangeListener(EORelationship.DEFINITION, _joinsListener);
            _joinsTableEditor.setRelationship(_relationship);
            _modelComboViewer.setInput(_relationship);
            _entityComboViewer.setInput(_relationship);
            EOEntity destinationEntity = _relationship.getDestination();
            if (destinationEntity != null) {
                _modelComboViewer.setSelection(new StructuredSelection(destinationEntity.getModel()));
            }

            _bindingContext = new DataBindingContext();
            _bindingContext.bindValue(SWTObservables.observeText(_nameText, SWT.Modify),
                    BeansObservables.observeValue(_relationship, EORelationship.NAME), null, null);
            _bindingContext.bindValue(SWTObservables.observeText(_definitionText, SWT.Modify),
                    BeansObservables.observeValue(_relationship, EORelationship.DEFINITION), null, null);
            //_bindingContext.bindValue(SWTObservables.observeSelection(_toOneButton), BeansObservables.observeValue(_relationship, EORelationship.TO_ONE), null, new BooleanUpdateValueStrategy());
            _bindingContext.bindValue(SWTObservables.observeSelection(_toManyButton),
                    BeansObservables.observeValue(_relationship, EORelationship.TO_MANY), null,
                    new BooleanUpdateValueStrategy());
            _bindingContext.bindValue(SWTObservables.observeSelection(_optionalButton),
                    BeansObservables.observeValue(_relationship, EORelationship.OPTIONAL), null,
                    new BooleanUpdateValueStrategy());
            //_bindingContext.bindValue(SWTObservables.observeSelection(_mandatoryButton), BeansObservables.observeValue(_relationship, EORelationship.MANDATORY), null, new BooleanUpdateValueStrategy());
            _bindingContext.bindValue(SWTObservables.observeSelection(_classPropertyButton),
                    BeansObservables.observeValue(_relationship, EORelationship.CLASS_PROPERTY), null,
                    new BooleanUpdateValueStrategy());

            _deleteRuleBinding = new ComboViewerBinding(_deleteRuleComboViewer, _relationship,
                    EORelationship.DELETE_RULE, null, null, null);
            _joinSemanticBinding = new ComboViewerBinding(_joinSemanticComboViewer, _relationship,
                    EORelationship.JOIN_SEMANTIC, _relationship.getEntity().getModel().getModelGroup(),
                    EOModelGroup.MODELS, null);
            _entityBinding = new ComboViewerBinding(_entityComboViewer, _relationship,
                    EORelationship.DESTINATION, _relationship.getEntity().getModel(), EOModel.ENTITIES, null);

            // boolean flattened = myRelationship.isFlattened();
            // myDefinitionLabel.setVisible(flattened);
            // myDefinitionText.setVisible(flattened);

            updateModelAndEntityCombosEnabled();
        }
    }
}

From source file:org.objectstyle.wolips.wooeditor.editor.DisplayGroupDetailsPage.java

License:Open Source License

private void bind() {
    // XXX This method is too long
    if (myDisplayGroup == null) {
        return;//w  w w.  ja  v a 2 s  .c o m
    }
    myBindingContext = new DataBindingContext();

    myBindingContext.bindValue(SWTObservables.observeText(myNameText, SWT.Modify),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.NAME), null, null);

    myBindingContext.bindList(SWTObservables.observeItems(myClassNameCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.CLASS_NAME_LIST),
            null, null);
    myBindingContext.bindValue(SWTObservables.observeSingleSelectionIndex(myClassNameCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.CLASS_NAME_INDEX), null, null);

    myBindingContext.bindList(SWTObservables.observeItems(myEntityCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.ENTITY_LIST), null,
            null);
    myBindingContext.bindValue(SWTObservables.observeEnabled(myMasterDetailGroup),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.HAS_MASTER_DETAIL),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);

    UpdateValueStrategy booleanInverse = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE) {
        @Override
        protected IStatus doSet(final IObservableValue observableValue, final Object value) {
            Boolean newValue = !(Boolean) value;
            return super.doSet(observableValue, newValue);
        }
    };

    myBindingContext.bindValue(SWTObservables.observeEnabled(myEntityCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.HAS_MASTER_DETAIL),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), booleanInverse);
    myBindingContext.bindValue(CustomSWTObservables.observeText(myEntityCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.ENTITY_NAME), null, null);

    myBindingContext.bindValue(SWTObservables.observeEnabled(myEditingContextText),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.HAS_MASTER_DETAIL),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), booleanInverse);
    myBindingContext.bindValue(SWTObservables.observeText(myEditingContextText, SWT.Modify),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.EDITING_CONTEXT), null, null);

    myBindingContext.bindValue(SWTObservables.observeSelection(myHasDetailButton),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.HAS_MASTER_DETAIL), null, null);

    myBindingContext.bindList(SWTObservables.observeItems(myMasterEntityCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.ENTITY_LIST), null,
            null);
    myBindingContext.bindValue(CustomSWTObservables.observeText(myMasterEntityCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.MASTER_ENTITY_NAME), null, null);

    myBindingContext.bindList(SWTObservables.observeItems(myDetailKeyCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.DETAIL_KEY_LIST),
            null, null);

    myBindingContext.bindValue(CustomSWTObservables.observeText(myDetailKeyCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.DETAIL_KEY_NAME), null, null);

    myBindingContext.bindValue(SWTObservables.observeSelection(myEntriesPerBatchSpinner),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.ENTRIES_PER_BATCH), null, null);

    myBindingContext.bindValue(SWTObservables.observeSelection(mySelectsFirstObjectButton),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.SELECTS_FIRST_OBJECT), null, null);

    myBindingContext.bindList(SWTObservables.observeItems(myQualificationCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.QUALIFICATION_LIST),
            null, null);
    myBindingContext.bindValue(SWTObservables.observeSingleSelectionIndex(myQualificationCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.QUALIFICATION_INDEX), null, null);

    myBindingContext.bindValue(SWTObservables.observeSelection(myFetchOnLoadButton),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.FETCHES_ON_LOAD), null, null);

    myBindingContext.bindList(SWTObservables.observeItems(mySortAttributeCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.SORT_LIST), null,
            null);

    myBindingContext.bindValue(CustomSWTObservables.observeSelection(mySortAttributeCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.SORT_ORDER_KEY), null, null);

    myBindingContext.bindValue(CustomSWTObservables.observeSelection(mySortRadioGroup),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.SORT_ORDER), null, null);

    UpdateValueStrategy fetchSpecEmpty = new UpdateValueStrategy();
    fetchSpecEmpty.setConverter(new IConverter() {
        public Object convert(final Object fromObject) {
            boolean result = fromObject != null && ((List<?>) fromObject).size() > 0;
            if (!myHasDetailButton.getSelection()) {
                return result;
            }
            return false;
        }

        public Object getFromType() {
            return new ArrayList<String>();
        }

        public Object getToType() {
            return true;
        }
    });

    UpdateValueStrategy fetchSpecEnabled = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE) {
        @Override
        protected IStatus doSet(final IObservableValue observableValue, final Object value) {
            Boolean newValue = false;
            if (myFetchSpecCombo.getItemCount() > 0) {
                newValue = !(Boolean) value;
            }
            return super.doSet(observableValue, newValue);
        }
    };
    myBindingContext.bindValue(SWTObservables.observeEnabled(myFetchSpecCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.HAS_MASTER_DETAIL),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), fetchSpecEnabled);

    myBindingContext.bindValue(SWTObservables.observeEnabled(myFetchSpecCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.FETCH_SPEC_LIST),
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), fetchSpecEmpty);

    myBindingContext.bindList(SWTObservables.observeItems(myFetchSpecCombo),
            BeansObservables.observeList(Realm.getDefault(), myDisplayGroup, DisplayGroup.FETCH_SPEC_LIST),
            null, null);

    UpdateValueStrategy fetchSpecSelection = new UpdateValueStrategy() {
        @Override
        protected IStatus doSet(IObservableValue observableValue, Object value) {
            if (value == null || value.equals("")) {
                value = DisplayGroup.FETCH_SPEC_NONE;
            }
            return super.doSet(observableValue, value);
        }
    };
    myBindingContext.bindValue(CustomSWTObservables.observeSelection(myFetchSpecCombo),
            BeansObservables.observeValue(myDisplayGroup, DisplayGroup.FETCH_SPEC_NAME), null,
            fetchSpecSelection);

    myEntityCombo.addModifyListener(myEntityModifyListener);
    myMasterEntityCombo.addModifyListener(myMasterEntityListener);
    mySortAttributeCombo.addSelectionListener(mySortEntityListener);

}

From source file:org.openscada.ca.ui.editor.forms.common.ConfigurationFormToolkit.java

License:Open Source License

public void createStandardCheckbox(final Composite parent, final String attributeName, final String label,
        final IObservableMap data, final Object valueType) {
    final Button button = this.toolkit.createButton(parent, label, SWT.CHECK);
    {//from   www .j  a va  2  s .  c o m
        final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 3;
        button.setLayoutData(gd);
        final IObservableValue value = Observables.observeMapEntry(data, attributeName, valueType);
        this.dbc.bindValue(SWTObservables.observeSelection(button), value);
    }
}

From source file:org.polarsys.reqcycle.repository.data.ui.dialog.AddTypeDialog.java

License:Open Source License

@Override
protected void doInitDataBindings(DataBindingContext bindingContext) {
    // Create the Select Observable for our enum type
    SelectObservableValue typeRadioObservable = new SelectObservableValue(TYPE.class);

    // bind the requirement radio button selection to the right enum value
    IObservableValue btnRequirementObserverSelection = SWTObservables.observeSelection(btnReqRadio);
    typeRadioObservable.addOption(TYPE.REQUIREMENT, btnRequirementObserverSelection);

    // bind the enumeration radio button selection to the right enum value
    IObservableValue btnEnumerationObserverSelection = SWTObservables.observeSelection(btnEnumRadio);
    typeRadioObservable.addOption(TYPE.ENUMERATION, btnEnumerationObserverSelection);

    bindingContext.bindValue(typeRadioObservable, PojoObservables.observeValue(bean, "type"));
}

From source file:org.reap.internal.core.binding.BindingManager.java

License:Open Source License

private IObservable createSWTObservable(final Control control, final BindingConfig binding) {
    IObservable obs = null;/*from  w  w w  .  j a  v a 2  s.c  om*/
    switch (binding.getType()) {
    case BACKGROUND:
        obs = SWTObservables.observeBackground(control);
        break;
    case EDITABLE:
        obs = SWTObservables.observeEditable(control);
        break;
    case ENABLED:
        obs = SWTObservables.observeEnabled(control);
        break;
    case FONT:
        obs = SWTObservables.observeFont(control);
        break;
    case FOREGROUND:
        obs = SWTObservables.observeForeground(control);
        break;
    case ITEMS:
        obs = SWTObservables.observeItems(control);
        break;
    case MAX:
        obs = SWTObservables.observeMax(control);
        break;
    case MIN:
        obs = SWTObservables.observeMin(control);
        break;
    case SELECTION:
        obs = SWTObservables.observeSelection(control);
        break;
    case SINGLESELECTIONINDEX:
        obs = SWTObservables.observeSingleSelectionIndex(control);
        break;
    case TEXT:
        obs = SWTObservables.observeText(control);
        break;
    case TEXTFOCUSOUT:
        obs = SWTObservables.observeText(control, SWT.FocusOut);
        break;
    case TEXTMODIFY:
        obs = SWTObservables.observeText(control, SWT.Modify);
        break;
    case TEXTNONE:
        obs = SWTObservables.observeText(control, SWT.None);
        break;
    case TOOLTIPTEXT:
        obs = SWTObservables.observeTooltipText(control);
        break;
    case VISIBLE:
        obs = SWTObservables.observeVisible(control);
        break;
    default:
        throw new IllegalArgumentException();
    }
    return obs;
}

From source file:org.reap.internal.core.persistence.config.PersistenceConfigPage.java

License:Open Source License

private void bind() {
    if (config == null) {
        final IExtensionRegistry reg = Platform.getExtensionRegistry();
        final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
        config = PersistenceConfigFactory.createPersistenceConfig(reg, store);
    }//from   w  w  w . j av a2  s .  c  om

    final DataBindingContext context = new DataBindingContext();

    final IObservableValue observeUseSystemProperties = BeansObservables.observeValue(config,
            "useSystemProperties");
    context.bindValue(SWTObservables.observeSelection(useSystemProperties), observeUseSystemProperties, null,
            null);
    context.bindValue(SWTObservables.observeVisible(comp), observeUseSystemProperties, null,
            new NegateBoolean());

    final IObservableValue observeHost = BeansObservables.observeValue(config, "host");
    context.bindValue(SWTObservables.observeText(hostText, SWT.Modify), observeHost, null, null);
    final IObservableValue observePort = BeansObservables.observeValue(config, "port");
    context.bindValue(SWTObservables.observeText(portText, SWT.Modify), observePort, null, null);
    final IObservableValue observeDatabase = BeansObservables.observeValue(config, "database");
    context.bindValue(SWTObservables.observeText(databaseText, SWT.Modify), observeDatabase, null, null);
    context.bindValue(SWTObservables.observeText(usernameText, SWT.Modify),
            BeansObservables.observeValue(config, "username"), null, null);
    context.bindValue(SWTObservables.observeText(passwordText, SWT.Modify),
            BeansObservables.observeValue(config, "password"), null, null);

    final IObservableValue observejdbcFreeSetting = BeansObservables.observeValue(config, "driverFreeSetting");
    context.bindValue(SWTObservables.observeSelection(freeDriverInput), observejdbcFreeSetting, null, null);
    context.bindValue(SWTObservables.observeEnabled(jdbcCombo), observejdbcFreeSetting, null,
            new NegateBoolean());
    context.bindValue(SWTObservables.observeEnabled(jdbcText), observejdbcFreeSetting, null, null);
    final IObservableValue observeDialectFreeSetting = BeansObservables.observeValue(config,
            "dialectFreeSetting");
    context.bindValue(SWTObservables.observeSelection(freeDialectInput), observeDialectFreeSetting, null, null);
    context.bindValue(SWTObservables.observeEnabled(dialectCombo), observeDialectFreeSetting, null,
            new NegateBoolean());
    context.bindValue(SWTObservables.observeEnabled(dialectText), observeDialectFreeSetting, null, null);

    final IObservableMap attributeMapOrm = BeansObservables.observeMap(
            Observables.staticObservableSet(new HashSet<ORMManagerConfig>(config.getOrmManagers())),
            ORMManagerConfig.class, "name");
    crmViewer.setLabelProvider(new ObservableMapLabelProvider(attributeMapOrm));
    crmViewer.setContentProvider(new ArrayContentProvider());
    crmViewer.setInput(config.getOrmManagers());
    final IObservableValue observeOrmManager = BeansObservables.observeValue(config, "ormManager");
    context.bindValue(ViewersObservables.observeSingleSelection(crmViewer), observeOrmManager, null, null);

    final IObservableMap attributeMapDatabase = BeansObservables.observeMap(
            Observables.staticObservableSet(new HashSet<DatabaseSystemConfig>(config.getDatabaseSystems())),
            DatabaseSystemConfig.class, "name");
    databaseSystemViewer.setLabelProvider(new ObservableMapLabelProvider(attributeMapDatabase));
    databaseSystemViewer.setContentProvider(new ArrayContentProvider());
    databaseSystemViewer.setInput(config.getDatabaseSystems());
    final IObservableValue observeDatabankSystem = BeansObservables.observeValue(config, "databaseSystem");
    context.bindValue(ViewersObservables.observeSingleSelection(databaseSystemViewer), observeDatabankSystem,
            null, null);

    final IObservableSet observeDetailSet = BeansObservables.observeDetailSet(Realm.getDefault(),
            observeDatabankSystem, "driverConfigs", DriverConfig.class);
    final IObservableMap attributeMapDriverConfig = BeansObservables.observeMap(observeDetailSet,
            DriverConfig.class, "driver");
    jdbcViewer.setLabelProvider(new ObservableMapLabelProvider(attributeMapDriverConfig));
    jdbcViewer.setContentProvider(new ObservableSetContentProvider());
    jdbcViewer.setInput(observeDetailSet);
    context.bindValue(ViewersObservables.observeSingleSelection(jdbcViewer),
            BeansObservables.observeValue(config, "driverConfig"), null, null);

    context.bindValue(SWTObservables.observeText(jdbcText, SWT.Modify),
            BeansObservables.observeValue(config, "driverConfigFree"), null, null);

    final IObservableSet dialectSet = MasterDetailObservables.detailSet(new ComputedValue() {
        @Override
        protected Object calculate() {
            ORMManagerConfig value = (ORMManagerConfig) observeOrmManager.getValue();
            DatabaseSystemConfig value2 = (DatabaseSystemConfig) observeDatabankSystem.getValue();

            final WritableSet retSet = WritableSet.withElementType(DialectConfig.class);

            if (value != null && value2 != null) {
                for (DialectConfig dialectConfig : value.getDialectConfigs()) {
                    if (dialectConfig.getReference().equals(value2.getSubProtocol())) {
                        retSet.add(dialectConfig);
                    }
                }
                databaseDialects: for (DialectConfig dialectConfig : value2.getDialectConfigs()) {
                    if (dialectConfig.getReference().equals(value.getId())) {
                        for (Object o : retSet) {
                            if (((DialectConfig) o).getDialect().equals(dialectConfig.getDialect())) {
                                continue databaseDialects;
                            }
                        }
                        retSet.add(dialectConfig);
                    }
                }
            }

            return retSet;
        }
    }, new IObservableFactory() {
        public IObservable createObservable(final Object target) {
            return (WritableSet) target;
        }
    }, DialectConfig.class);

    final IObservableMap attributeMapDialectConfig = BeansObservables.observeMap(dialectSet,
            DialectConfig.class, "dialect");
    dialectViewer.setLabelProvider(new ObservableMapLabelProvider(attributeMapDialectConfig));
    dialectViewer.setContentProvider(new ObservableSetContentProvider());
    dialectViewer.setInput(dialectSet);
    context.bindValue(ViewersObservables.observeSingleSelection(dialectViewer),
            BeansObservables.observeValue(config, "dialectConfig"), null, null);

    context.bindValue(SWTObservables.observeText(dialectText, SWT.Modify),
            BeansObservables.observeValue(config, "dialectConfigFree"), null, null);

    context.bindValue(SWTObservables.observeText(urlLabel), new ComputedValue() {
        @Override
        protected Object calculate() {
            final StringBuffer buffer = new StringBuffer();
            buffer.append("jdbc:")
                    .append(((DatabaseSystemConfig) observeDatabankSystem.getValue()).getSubProtocol())
                    .append("://").append(observeHost.getValue()).append(":").append(observePort.getValue())
                    .append("/").append(observeDatabase.getValue());
            return buffer.toString();
        }
    }, null, null);
}