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.emf.ecp.editor.mecontrols.MEIntControl.java

License:Open Source License

/**
 * {@inheritDoc}//from w  w w.  ja v a2 s.c o m
 * 
 * @return A spinner for the int value.
 */
@Override
public Control createControl(Composite parent, int style) {
    Object feature = getItemPropertyDescriptor().getFeature(getModelElement());
    this.attribute = (EAttribute) feature;

    composite = getToolkit().createComposite(parent, style);
    composite.setBackgroundMode(SWT.INHERIT_FORCE);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(2, 0).applyTo(composite);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);

    labelWidgetImage = getToolkit().createLabel(composite, "    ");
    labelWidgetImage.setBackground(parent.getBackground());

    spinner = new Spinner(composite, style | SWT.BORDER);
    spinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    spinner.setMinimum(-1000);
    spinner.setMaximum(1000);
    IObservableValue model = EMFEditObservables.observeValue(getEditingDomain(), getModelElement(), attribute);
    EMFDataBindingContext dbc = new EMFDataBindingContext();
    dbc.bindValue(SWTObservables.observeSelection(spinner), model, null, null);

    return composite;
}

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

License:Open Source License

@Override
protected Control createControl(Composite parent, int style) {
    this.attribute = (EAttribute) getItemPropertyDescriptor().getFeature(getModelElement());
    dateComposite = getToolkit().createComposite(parent);
    dateComposite.setBackgroundMode(SWT.INHERIT_FORCE);
    GridLayoutFactory.fillDefaults().numColumns(4).spacing(2, 0).applyTo(dateComposite);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(dateComposite);

    createDateAndTimeWidget();/*from w  w w . j a  va 2s. c om*/

    IObservableValue model = EMFEditObservables.observeValue(getEditingDomain(), getModelElement(), attribute);
    EMFDataBindingContext dbc = new EMFDataBindingContext();
    IObservableValue dateObserver = SWTObservables.observeSelection(dateWidget);
    IObservableValue timeObserver = SWTObservables.observeSelection(timeWidget);
    dbc.bindValue(new DateAndTimeObservableValue(dateObserver, timeObserver), model, null, null);

    return dateComposite;
}

From source file:org.eclipse.emf.editor.ui.binding.EmfSwtBindingFactory.java

License:Open Source License

private Control bindValue(EStructuralFeature feature) {
    Control retVal = null;// w w w.j a  v a  2s  . c om
    IObservableValue source = EMFEditObservables.observeValue(domain, owner, feature);
    IObservableValue target = null;
    if (feature.getEType().equals(EcorePackage.Literals.EBOOLEAN)
            || feature.getEType().equals(EcorePackage.Literals.EBOOLEAN_OBJECT)
            || (feature.getEType() instanceof EDataType
                    && (feature.getEType().getInstanceClass() == Boolean.class
                            || feature.getEType().getInstanceClass() == Boolean.TYPE))) {
        Button b = toolkit.createButton(parent, "", SWT.CHECK);
        target = SWTObservables.observeSelection(b);
        retVal = b;
    } else {
        List<?> proposals = proposalcreator.proposals(feature);
        if (feature instanceof EReference || feature.getEType() instanceof EEnumImpl) {
            ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY);
            toolkit.adapt(combo.getCombo());
            combo.setContentProvider(new ArrayContentProvider());
            combo.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            combo.setInput(proposals);
            target = ViewersObservables.observeSingleSelection(combo);
            retVal = combo.getCombo();
        } else {
            Text t = toolkit.createText(parent, "");
            t.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
            if (proposals != null && !proposals.isEmpty()) {
                // TODO prevent adding null to a list, for example a Collection
                // Type
                while (proposals.remove(null)) {
                    // clear null entries
                }
                ControlDecoration field = new ControlDecoration(t, SWT.BORDER);
                FieldDecoration requiredFieldIndicator = FieldDecorationRegistry.getDefault()
                        .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
                field.setImage(requiredFieldIndicator.getImage());
                field.setDescriptionText(requiredFieldIndicator.getDescription());
                KeyStroke keyStroke = null;
                String string = "Ctrl+Space";
                try {
                    keyStroke = KeyStroke.getInstance(string);
                } catch (ParseException e) {
                    EEPlugin.getDefault().getLog().log(
                            new Status(IStatus.ERROR, EEPlugin.PLUGIN_ID, "Error while parse: " + string, e));
                }
                new ContentProposalAdapter(t, new TextContentAdapter(),
                        new SimpleContentProposalProvider(proposals.toArray(new String[] {})), keyStroke, null);
            }
            target = SWTObservables.observeText(t, SWT.Modify);
            retVal = t;

        }
    }
    edbc.bindValue(target, source, null, null);
    return retVal;
}

From source file:org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog.java

License:Open Source License

protected Button createCheck(Composite parent, String label, EObject obj, EAttribute att,
        IValidator validator) {//w ww  .  jav a 2  s .co m
    Label l = toolkit.createLabel(parent, label, SWT.NONE);
    l.setLayoutData(new GridData(SWT.NONE));

    Button check = toolkit.createButton(parent, "", SWT.CHECK);
    check.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    UpdateValueStrategy t2m = null;
    UpdateValueStrategy m2t = null;
    if (validator != null) {
        t2m = new UpdateValueStrategy();
        t2m.setAfterConvertValidator(validator);
        t2m.setBeforeSetValidator(validator);
        m2t = new UpdateValueStrategy();
        m2t.setAfterConvertValidator(validator);
        m2t.setBeforeSetValidator(validator);
    }
    bindingContext.bindValue(SWTObservables.observeSelection(check),
            PojoObservables.observeValue(obj, att.getName()), t2m, m2t);

    return check;
}

From source file:org.eclipse.etrice.ui.structure.dialogs.PortPropertyDialog.java

License:Open Source License

private void createRelayCheck(Composite parent, Result notReferenced, FormToolkit toolkit) {
    Label l = toolkit.createLabel(parent, "Is Relay Port:", SWT.NONE);
    l.setLayoutData(new GridData(SWT.NONE));

    relayCheck = toolkit.createButton(parent, "", SWT.CHECK);
    relayCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    relayCheck.setSelection(relay);//w w  w.  j a  v a2 s .  c  om
    relayCheck.setEnabled(notReferenced.isOk());

    RelayValidator validator = new RelayValidator();
    UpdateValueStrategy t2m = new UpdateValueStrategy();
    t2m.setAfterConvertValidator(validator);
    t2m.setBeforeSetValidator(validator);
    UpdateValueStrategy m2t = new UpdateValueStrategy();
    m2t.setAfterConvertValidator(validator);
    m2t.setBeforeSetValidator(validator);

    getBindingContext().bindValue(SWTObservables.observeSelection(relayCheck),
            PojoObservables.observeValue(this, "relay"), t2m, m2t);

    if (notReferenced.isOk())
        createDecorator(relayCheck, "");
    else
        createInfoDecorator(relayCheck, notReferenced.getMsg());
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.ColorBlock.java

License:Open Source License

public Control createContents(Composite parent) {
    final Realm realm = bindings.getValidationRealm();

    Composite result = group(parent, DiagramUIPrintingMessages.JPSOptionsDialog_Color);
    layout(result, 2);// ww  w.  j a v a2  s .  c o m

    colorRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_ChromaticityColor);
    layoutSpanHorizontal(colorRadio, 4);

    monoRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_ChromaticityMonochrome);
    layoutSpanHorizontal(monoRadio, 4);

    colorBinding = bindings.bindValue(SWTObservables.observeSelection(colorRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_CHROMATICITY_COLOR), null,
            null);

    monoBinding = bindings.bindValue(SWTObservables.observeSelection(monoRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_CHROMATICITY_MONO), null, null);

    initializeControls(options.getDestination().getName());

    return result;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.CopiesBlock.java

License:Open Source License

public Control createContents(Composite parent) {
    final Realm realm = bindings.getValidationRealm();

    Composite result = group(parent, DiagramUIPrintingMessages.JPSPrintDialog_Copies);
    layout(result, 2);//from  ww w .j  a v a2s  .c  o  m

    label(result, DiagramUIPrintingMessages.JPSPrintDialog_NumberOfCopies);
    Spinner copiesSpinner = spinner(result, 1, 999);

    bindings.bindValue(SWTObservables.observeSelection(copiesSpinner),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_COPIES), null, null);

    final Label collateImageButton = new Label(result, SWT.CENTER | SWT.SHADOW_NONE);

    layoutAlignRight(collateImageButton);
    collateImageButton.setImage(collateOffImage);

    Button collateCheck = check(result, DiagramUIPrintingMessages.JPSPrintDialog_Collate);

    bindings.bindValue(SWTObservables.observeSelection(collateCheck),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_COLLATE), null, null);

    collateCheck.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            // do nothing
        }

        public void widgetSelected(SelectionEvent arg0) {
            if (options.isCollate()) {
                collateImageButton.setImage(collateOnImage);
            } else {
                collateImageButton.setImage(collateOffImage);
            }
        }
    });

    return result;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.DiagramPrintRangeBlock.java

License:Open Source License

/**
 * Create the contents of the diagram selection block. It contains 2 radio
 * buttons for current or multi-selection and a list box of diagram options.
 *//*from   w w w  . j  a  v a 2  s. c o m*/
@Override
public Control createContents(Composite parent) {

    final Realm realm = bindings.getValidationRealm();

    Composite result = group(parent, DiagramUIPrintingMessages.JPSOptionsDialog_DiagramPrintRange);
    layout(result, 3);

    Button currentDiagramRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_DiagramPrintCurrent);
    layoutSpanHorizontal(currentDiagramRadio, 4);

    Button selectedDiagramsRadio = radio(result,
            DiagramUIPrintingMessages.JPSOptionsDialog_DiagramPrintSelected);
    layoutSpanHorizontal(selectedDiagramsRadio, 4);

    diagramList = list(result);

    layoutFillHorizontal(layoutHeight(diagramList.getControl(), 48));
    GridData data = getLayoutData(diagramList.getControl());
    data.widthHint = 300;

    diagramList.getControl().setEnabled(options.isDiagramSelection());

    currentDiagramRadio.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            //do nothing
        }

        public void widgetSelected(SelectionEvent event) {
            diagramList.getControl().setEnabled(options.isDiagramSelection());
        }
    });

    selectedDiagramsRadio.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            //do nothing
        }

        public void widgetSelected(SelectionEvent event) {
            diagramList.getControl().setEnabled(!options.isDiagramCurrent());
        }
    });

    diagramList.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangedEvent event) {
            if (event != null) {

                StructuredSelection selection = (StructuredSelection) event.getSelection();

                options.setDiagramsToPrint(selection.toList());

            }

        }
    });

    diagramList.setContentProvider(new DiagramContentProvider());
    diagramList.setLabelProvider(new DiagramLabelProvider());

    diagramList.setInput(availableDiagrams);

    bindings.bindValue(SWTObservables.observeSelection(currentDiagramRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_DIAGRAM_CURRENT), null, null);

    bindings.bindValue(SWTObservables.observeSelection(selectedDiagramsRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_DIAGRAM_SELECTION), null, null);

    return result;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.QualityBlock.java

License:Open Source License

public Control createContents(Composite parent) {
    final Realm realm = bindings.getValidationRealm();

    Composite result = group(parent, DiagramUIPrintingMessages.JPSOptionsDialog_Quality);
    layout(result, 2);//  w w  w  .j a v a2s  . c  o m

    Button highRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_QualityHigh);
    layoutSpanHorizontal(highRadio, 4);

    Button mediumRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_QualityMedium);
    layoutSpanHorizontal(mediumRadio, 4);

    Button lowRadio = radio(result, DiagramUIPrintingMessages.JPSOptionsDialog_QualityLow);
    layoutSpanHorizontal(lowRadio, 4);

    qualityHighBinding = bindings.bindValue(SWTObservables.observeSelection(highRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_QUALITY_HIGH), null, null);

    qualityMedBinding = bindings.bindValue(SWTObservables.observeSelection(mediumRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_QUALITY_MED), null, null);

    qualityLowBinding = bindings.bindValue(SWTObservables.observeSelection(lowRadio),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_QUALITY_LOW), null, null);

    return result;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.RangeBlock.java

License:Open Source License

public Control createContents(Composite parent) {
    final Realm realm = bindings.getValidationRealm();

    Composite result = group(parent, DiagramUIPrintingMessages.JPSPrintDialog_PrintRange);
    layout(result, 4);/*from w  w  w. j a va2  s .  c  om*/

    Button allRadio = radio(result, DiagramUIPrintingMessages.JPSPrintDialog_All);
    layoutSpanHorizontal(allRadio, 4);

    final IObservableValue allValue = BeansObservables.observeValue(realm, options,
            PrintOptions.PROPERTY_ALL_PAGES);
    bindings.bindValue(SWTObservables.observeSelection(allRadio), allValue, null, null);

    Button rangeRadio = radio(result, DiagramUIPrintingMessages.JPSPrintDialog_Pages);
    layoutSpanHorizontal(rangeRadio, 4);

    IObservableValue rangeValue = new ComputedValue(realm) {
        protected Object calculate() {
            return Boolean.valueOf(!((Boolean) allValue.getValue()).booleanValue());
        }
    };
    bindings.bindValue(SWTObservables.observeSelection(rangeRadio), rangeValue, null, null);

    layoutHorizontalIndent(label(result, DiagramUIPrintingMessages.JPSPrintDialog_From));
    Text textFrom = text(result, 20);

    layoutHorizontalIndent(label(result, DiagramUIPrintingMessages.JPSPrintDialog_To));
    Text textTo = text(result, 20);

    bindings.bindValue(SWTObservables.observeText(textFrom, SWT.Modify),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_RANGE_FROM), null, null);
    bindings.bindValue(SWTObservables.observeEnabled(textFrom), rangeValue, null, null);
    bindings.bindValue(SWTObservables.observeText(textTo, SWT.Modify),
            BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_RANGE_TO), null, null);
    bindings.bindValue(SWTObservables.observeEnabled(textTo), rangeValue, null, null);

    return result;
}