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.eclipse.bpmn2.modeler.ui.property.AbstractBpmn2PropertiesComposite.java

License:Open Source License

protected void bindBoolean(final EStructuralFeature a, final Button button, final EObject object) {
    button.setSelection((Boolean) object.eGet(a));
    IObservableValue buttonObserver = SWTObservables.observeSelection(button);
    buttonObserver.addValueChangeListener(new IValueChangeListener() {

        @SuppressWarnings("restriction")
        @Override/*from www  .j a v a 2s.  c om*/
        public void handleValueChange(ValueChangeEvent event) {

            if (!object.eGet(a).equals(button.getSelection())) {
                TransactionalEditingDomain editingDomain = bpmn2Editor.getEditingDomain();
                editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
                    @Override
                    protected void doExecute() {
                        object.eSet(a, button.getSelection());
                    }
                });

                if (bpmn2Editor.getDiagnostics() != null) {
                    // revert the change and display error status message.
                    button.setSelection((Boolean) be.eGet(a));
                    bpmn2Editor.showErrorMessage(bpmn2Editor.getDiagnostics().getMessage());
                } else
                    bpmn2Editor.showErrorMessage(null);
            }
        }
    });

    button.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        public void focusLost(FocusEvent e) {
            bpmn2Editor.showErrorMessage(null);
        }
    });
}

From source file:org.eclipse.bpmn2.modeler.ui.property.editors.BooleanObjectEditor.java

License:Open Source License

public Control createControl(Composite composite, String label, int style) {

    // create a separate label to the LEFT of the checkbox, otherwise the grid layout will
    // be off by one column for all other widgets that are created after this one.
    createLabel(composite, label);/* w w  w  .  jav a 2s .com*/

    button = getToolkit().createButton(composite, "", SWT.CHECK);
    button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    button.setSelection((Boolean) object.eGet(feature));
    IObservableValue buttonObserver = SWTObservables.observeSelection(button);
    buttonObserver.addValueChangeListener(new IValueChangeListener() {

        @SuppressWarnings("restriction")
        @Override
        public void handleValueChange(ValueChangeEvent event) {

            if (!object.eGet(feature).equals(button.getSelection())) {
                TransactionalEditingDomain editingDomain = getDiagramEditor().getEditingDomain();
                editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
                    @Override
                    protected void doExecute() {
                        object.eSet(feature, button.getSelection());
                    }
                });

                if (getDiagramEditor().getDiagnostics() != null) {
                    // revert the change and display error status message.
                    button.setSelection((Boolean) object.eGet(feature));
                    ErrorUtils.showErrorMessage(getDiagramEditor().getDiagnostics().getMessage());
                } else
                    ErrorUtils.showErrorMessage(null);
            }
        }
    });

    button.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        public void focusLost(FocusEvent e) {
            ErrorUtils.showErrorMessage(null);
        }
    });

    return button;
}

From source file:org.eclipse.e4.demo.viewer.PropertiesElement.java

License:Open Source License

protected Binding bind(Button button, EStructuralFeature feature) {
    if (selectedObject == null)
        return null;
    IObservableValue observable = EMFObservables.observeValue(selectedObject, feature);
    return dbc.bindValue(SWTObservables.observeSelection(button), observable, null, null);
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet024SelectObservableValue.java

License:Open Source License

protected void createContents() {
    shell = new Shell();
    shell.setSize(400, 300);/*from   w  ww .  j  a v a 2s .  c  o m*/
    shell.setLayout(new GridLayout(2, true));
    shell.setText("Snippet024SelectObservableValue");

    final ListViewer listViewer = new ListViewer(shell, SWT.BORDER);
    listViewer.setContentProvider(new ArrayContentProvider());
    listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Group group = new Group(shell, SWT.NONE);
    group.setText("Radio Group");
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    group.setLayout(new GridLayout());

    // Data Binding
    Color[] colors = Color.values();

    listViewer.setInput(colors);
    IViewerObservableValue listViewerSelection = ViewersObservables.observeSingleSelection(listViewer);

    SelectObservableValue radioGroup = new SelectObservableValue();
    for (int i = 0; i < colors.length; i++) {
        Button button = new Button(group, SWT.RADIO);
        button.setText(colors[i].toString());
        radioGroup.addOption(colors[i], SWTObservables.observeSelection(button));
    }

    DataBindingContext dbc = new DataBindingContext();
    dbc.bindValue(radioGroup, listViewerSelection);
}

From source file:org.eclipse.ecf.salvo.ui.internal.preferences.SalvoPreferencePage.java

License:Open Source License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ///*from w  w  w . j  a v a  2  s  .com*/
    IObservableValue btnMoreArticleViewsObserveSelectionObserveWidget = SWTObservables
            .observeSelection(btnMoreArticleViews);
    IObservableValue modelViewPerGroupObserveValue = PojoObservables.observeValue(model, "viewPerGroup");
    bindingContext.bindValue(btnMoreArticleViewsObserveSelectionObserveWidget, modelViewPerGroupObserveValue,
            null, null);
    //
    IObservableValue btnCreateNewArticlesObserveSelectionObserveWidget = SWTObservables
            .observeSelection(btnCreateNewArticles);
    IObservableValue modelUseDetachedViewObserveValue = PojoObservables.observeValue(model, "useDetachedView");
    bindingContext.bindValue(btnCreateNewArticlesObserveSelectionObserveWidget,
            modelUseDetachedViewObserveValue, null, null);
    //
    return bindingContext;
}

From source file:org.eclipse.ecf.salvo.ui.internal.preferences.SignaturePreferencePage.java

License:Open Source License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ////from   w ww .j  a  v a 2  s .c om
    IObservableValue signatureObserveTextObserveWidget = SWTObservables.observeText(signature, SWT.Modify);
    IObservableValue modelSignatureObserveValue = PojoObservables.observeValue(model, "signature");
    bindingContext.bindValue(signatureObserveTextObserveWidget, modelSignatureObserveValue, null, null);
    //
    IObservableValue btnUseSignatureObserveSelectionObserveWidget_7 = SWTObservables
            .observeSelection(btnUseSignature);
    IObservableValue signatureEnabledObserveValue = PojoObservables.observeValue(signature, "enabled");
    bindingContext.bindValue(btnUseSignatureObserveSelectionObserveWidget_7, signatureEnabledObserveValue, null,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
    //
    IObservableValue btnUseSignatureObserveSelectionObserveWidget_1 = SWTObservables
            .observeSelection(btnUseSignature);
    IObservableValue modelUseSignatureObserveValue = PojoObservables.observeValue(model, "useSignature");
    bindingContext.bindValue(btnUseSignatureObserveSelectionObserveWidget_1, modelUseSignatureObserveValue,
            null, null);
    //
    return bindingContext;
}

From source file:org.eclipse.emf.compare.rcp.ui.internal.configuration.ui.match.DefaultMatchEngineConfiguratorUI.java

License:Open Source License

/**
 * Bind radio button with data object/*from   w w  w .  j ava2 s .  c o  m*/
 */
private void bindData() {
    DataBindingContext ctx = new DataBindingContext();
    IObservableValue whenAvailableBtnSelection = SWTObservables.observeSelection(whenAvailableButton);
    IObservableValue onlyButtonSelection = SWTObservables.observeSelection(onlyButton);
    IObservableValue neverButtonSelection = SWTObservables.observeSelection(neverButton);
    SelectObservableValue featureRepoPolicyObservable = new SelectObservableValue(DataHolder.class);
    featureRepoPolicyObservable.addOption(UseIdentifiers.WHEN_AVAILABLE, whenAvailableBtnSelection);
    featureRepoPolicyObservable.addOption(UseIdentifiers.ONLY, onlyButtonSelection);
    featureRepoPolicyObservable.addOption(UseIdentifiers.NEVER, neverButtonSelection);
    ctx.bindValue(featureRepoPolicyObservable, PojoObservables.observeValue(dataHolder, "value")); //$NON-NLS-1$
}

From source file:org.eclipse.emf.ecp.edit.internal.swt.controls.BooleanControl.java

License:Open Source License

@Override
public Binding bindValue() {
    final IObservableValue targetValue = SWTObservables.observeSelection(check);
    return getDataBindingContext().bindValue(targetValue, getModelValue());
}

From source file:org.eclipse.emf.ecp.edit.internal.swt.controls.DateTimeControl.java

License:Open Source License

@Override
public Binding bindValue() {
    final IObservableValue dateObserver = SWTObservables.observeSelection(dateWidget);
    final IObservableValue timeObserver = SWTObservables.observeSelection(timeWidget);
    final IObservableValue target = new DateAndTimeObservableValue(dateObserver, timeObserver);
    final Binding binding = getDataBindingContext().bindValue(target, getModelValue());
    return binding;
}

From source file:org.eclipse.emf.ecp.editor.mecontrols.MEBoolControl.java

License:Open Source License

/**
 * returns a check button without Label. {@inheritDoc}
 * /*from  w  w w  . j  ava  2s  .  c om*/
 * @return Control
 */
@Override
public Control createControl(Composite parent, int style) {
    Object feature = getItemPropertyDescriptor().getFeature(getModelElement());
    this.attribute = (EAttribute) feature;
    composite = getToolkit().createComposite(parent, style);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(2, 0).applyTo(composite);

    labelWidgetImage = getToolkit().createLabel(composite, "     ");
    labelWidgetImage.setBackground(parent.getBackground());
    labelWidgetImage.setSize(SWT.DEFAULT, 16);

    check = getToolkit().createButton(composite, "", SWT.CHECK);
    IObservableValue model = EMFEditObservables.observeValue(getEditingDomain(), getModelElement(), attribute);
    EMFDataBindingContext dbc = new EMFDataBindingContext();
    dbc.bindValue(SWTObservables.observeSelection(check), model, null, null);
    return composite;
}