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:es.cv.gvcase.fefem.common.composites.EMFPropertyIntegerComposite.java

License:Open Source License

@Override
protected IObservableValue getTargetObservable() {
    return SWTObservables.observeSelection(spinner);
}

From source file:gov.redhawk.ide.codegen.frontend.ui.wizard.FrontEndTunerTypeSelectionWizardPage.java

License:Open Source License

private void createBindings() {
    // create new Context
    this.ctx = new DataBindingContext();

    //      //from ww  w.  j  av a  2s.c o  m
    //      // Binding for the antenna only option
    //      this.ctx.bindValue(SWTObservables.observeSelection(this.deviceTypeAntennaButton),
    //         EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__ANTENNA), new UpdateValueStrategy(), new UpdateValueStrategy());

    // Binding for GPS ingest & output
    this.ctx.bindValue(SWTObservables.observeSelection(this.ingestGPSCheckbox),
            EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__INGESTS_GPS),
            new UpdateValueStrategy(), new UpdateValueStrategy());

    this.ctx.bindValue(SWTObservables.observeSelection(this.outputGPSCheckbox),
            EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__OUTPUTS_GPS),
            new UpdateValueStrategy(), new UpdateValueStrategy());

    // Need custom update value strat for the group binding since false -> true and true -> false
    UpdateValueStrategy tunerTypeGroupUVS = new UpdateValueStrategy();
    tunerTypeGroupUVS.setConverter(new IConverter() {

        @Override
        public Object getToType() {
            return Boolean.class;
        }

        @Override
        public Object getFromType() {
            return Boolean.class;
        }

        @Override
        public Object convert(Object fromObject) {
            return !((Boolean) fromObject).booleanValue();
        }
    });

    this.ctx.bindValue(SWTObservables.observeEnabled(this.tunerTypeGroup),
            EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__ANTENNA),
            new UpdateValueStrategy(), tunerTypeGroupUVS);

    this.ctx.bindValue(SWTObservables.observeEnabled(this.receiveOnlyTunerButton),
            EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__ANTENNA),
            new UpdateValueStrategy(), tunerTypeGroupUVS);

    this.ctx.bindValue(SWTObservables.observeEnabled(this.transmitOnlyTunerButton),
            EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__ANTENNA),
            new UpdateValueStrategy(), tunerTypeGroupUVS);

    this.ctx.bindValue(SWTObservables.observeEnabled(this.bothRxTxButton),
            EMFObservables.observeValue(this.feiDevice, FrontendPackage.Literals.FEI_DEVICE__ANTENNA),
            new UpdateValueStrategy(), tunerTypeGroupUVS);

    // Bindings for the tuner type is difficult since it is a 3 way with the third option being both the 1st and 2nd so listeners are used.
    this.bothRxTxButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FrontEndTunerTypeSelectionWizardPage.this.feiDevice.setRxTuner(true);
            FrontEndTunerTypeSelectionWizardPage.this.feiDevice.setTxTuner(true);
        }
    });

    this.receiveOnlyTunerButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FrontEndTunerTypeSelectionWizardPage.this.feiDevice.setRxTuner(true);
            FrontEndTunerTypeSelectionWizardPage.this.feiDevice.setTxTuner(false);
        }
    });

    this.transmitOnlyTunerButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FrontEndTunerTypeSelectionWizardPage.this.feiDevice.setRxTuner(false);
            FrontEndTunerTypeSelectionWizardPage.this.feiDevice.setTxTuner(true);
        }
    });

    IWizardPage[] wizPages = this.getWizard().getPages();
    ScaDeviceProjectPropertiesWizardPage propWizPage = null;

    for (IWizardPage wizPage : wizPages) {
        if (wizPage instanceof ScaDeviceProjectPropertiesWizardPage) {
            propWizPage = (ScaDeviceProjectPropertiesWizardPage) wizPage;
            break;
        }
    }

    // This must come after the creation of the page support since creation of page support updates the 
    // error message.  The WizardPageSupport doesn't update the error message because no UI elements have changed
    // so this is a bit of a hack.
    if (propWizPage != null) {
        this.validator = new FrontEndProjectValidator(propWizPage.getProjectSettings(), this);
        ctx.addValidationStatusProvider(validator);
        IObservableValue validationStatus = validator.getValidationStatus();
        validationStatus.addChangeListener(new IChangeListener() {

            @Override
            public void handleChange(ChangeEvent event) {
                if (validator != null) {
                    updateErrorMessage();
                }
            }
        });

        updateErrorMessage();
    }

}

From source file:gov.redhawk.ide.sdr.ui.export.DeployableScaExportWizardPage.java

License:Open Source License

private void bind(final DataBindingContext dbc, final CheckboxTableViewer availableProjectsViewer,
        final Button directoryRadio, final Text directoryText, final Button archiveRadio,
        final Text archiveText) {

    // Data-Bindings
    // Setup databinding
    dbc.bindSet(ViewersObservables.observeCheckedElements(availableProjectsViewer, IProject.class),
            this.model.projectsToExport, null, null);

    dbc.bindValue(SWTObservables.observeSelection(directoryRadio), this.model.directoryExport, null, null);

    dbc.bindValue(SWTObservables.observeSelection(archiveRadio), this.model.archiveExport, null, null);

    dbc.bindValue(SWTObservables.observeText(directoryText, SWT.Modify), this.model.directoryDestination,
            new UpdateValueStrategy().setAfterConvertValidator(new IValidator() {
                @Override//ww  w  . j  a  va 2  s . co  m
                public IStatus validate(final Object value) {
                    final String s = (String) value;
                    if (!directoryRadio.getSelection()) {
                        return ValidationStatus.ok();
                    }

                    if ((s == null) || (s.length() == 0)) {
                        return ValidationStatus.error("Enter an archive destination name.");
                    }
                    return ValidationStatus.ok();
                }
            }), null);

    dbc.bindValue(SWTObservables.observeText(archiveText, SWT.Modify), this.model.archiveDestination,
            new UpdateValueStrategy().setAfterConvertValidator(new IValidator() {
                @Override
                public IStatus validate(final Object value) {
                    final String s = (String) value;
                    if (!archiveRadio.getSelection()) {
                        return ValidationStatus.ok();
                    }

                    if ((s == null) || (s.length() == 0)) {
                        return ValidationStatus.error("Enter an archive destination name.");
                    }
                    return ValidationStatus.ok();
                }
            }), null);
}

From source file:gov.redhawk.prf.internal.ui.editor.detailspart.BasicSimplePropertyDetailsPage.java

License:Open Source License

@Override
protected List<Binding> bind(final DataBindingContext dataBindingContext, final EObject input) {
    final BasicSimplePropertyComposite composite = (BasicSimplePropertyComposite) getComposite();

    final EditingDomain domain = getEditingDomain();
    this.input = input;
    this.property = getProperty(this.input);

    final List<Binding> retVal = super.bind(dataBindingContext, input);

    // Type/* w  ww  .  j  a va  2 s  .c  om*/
    if (composite.getTypeViewer() != null) {
        retVal.add(dataBindingContext.bindValue(
                ViewersObservables.observeSingleSelection(composite.getTypeViewer()),
                EMFEditObservables.observeValue(domain, input, this.property.getType()), null, null));
    }

    if (composite.getTypeModifier() != null) {
        retVal.add(dataBindingContext.bindValue(SWTObservables.observeSelection(composite.getTypeModifier()),
                EMFEditObservables.observeValue(domain, input, this.property.getTypeModifier()),
                createTypeModifierTargetToModel(), createTypeModifierModelTarget()));
    }

    // Units
    if (getComposite().getUnitsEntry() != null) {
        retVal.add(dataBindingContext.bindValue(
                WidgetProperties.text(SWT.Modify).observeDelayed(SCAFormEditor.getFieldBindingDelay(),
                        composite.getUnitsEntry().getText()),
                EMFEditObservables.observeValue(domain, input, this.property.getUnits()),
                new EMFEmptyStringToNullUpdateValueStrategy(), null));
    }

    // Kind
    if (getComposite().getKindViewer() != null) {
        composite.getKindViewer().setCheckedElements(Collections.EMPTY_LIST.toArray());
        createKindBinding(dataBindingContext, input, domain, retVal);
    }

    // Action
    if (getComposite().getActionViewer() != null) {
        retVal.add(dataBindingContext.bindValue(
                ViewersObservables.observeSingleSelection(composite.getActionViewer()),
                EMFEditObservables.observeValue(domain, input, this.property.getAction()),
                createActionTargetToModel(), createActionModelToTarget()));
    }

    // Range
    if (getComposite().getRangeButton() != null) {
        retVal.addAll(bindRanges(input, dataBindingContext, domain));
        addRangeListener();
    }

    return retVal;
}

From source file:gov.redhawk.prf.internal.ui.editor.detailspart.BasicSimplePropertyDetailsPage.java

License:Open Source License

public List<Binding> bindButton(final DataBindingContext context, final Button rangeButton, final Text minText,
        final Text maxText) {

    final EMFUpdateValueStrategy targetToModel = new EMFUpdateValueStrategy();
    targetToModel.setConverter(new Converter(Boolean.class, Range.class) {

        @Override//from ww  w  . ja  v  a2s . c o  m
        public Object convert(final Object fromObject) {
            if ((Boolean) fromObject) {
                return PrfFactory.eINSTANCE.createRange();
            } else {
                return null;
            }
        }
    });

    final EMFUpdateValueStrategy modelToTarget = new EMFUpdateValueStrategy();
    modelToTarget.setConverter(new Converter(Range.class, Boolean.class) {

        @Override
        public Object convert(final Object fromObject) {
            return fromObject != null;
        }

    });

    final List<Binding> buttonBindings = new ArrayList<Binding>();
    buttonBindings.add(context.bindValue(SWTObservables.observeSelection(rangeButton),
            EMFEditObservables.observeValue(getEditingDomain(), this.input, this.property.getRange()),
            targetToModel, modelToTarget));

    buttonBindings.add(context.bindValue(SWTObservables.observeEnabled(minText),
            SWTObservables.observeSelection(rangeButton)));
    buttonBindings.add(context.bindValue(SWTObservables.observeEnabled(maxText),
            SWTObservables.observeSelection(rangeButton)));
    return buttonBindings;
}

From source file:gov.redhawk.sca.waveform.controlpanel.propertyEditors.BooleanPropertyEditor.java

License:Open Source License

@Override
public void setupBindings() {
    this.context = new EMFDataBindingContext();
    final ScaSimplePropertyControl scaSimplePropertyControl = new ScaSimplePropertyControl(this.radioGroup,
            (ScaSimpleProperty) this.prop);
    final ISWTObservableValue trueObservable = WidgetProperties.selection().observe(this.t);
    this.context.bindValue(trueObservable, scaSimplePropertyControl.getModel());
    this.context.bindValue(SWTObservables.observeSelection(this.t),
            scaSimplePropertyControl.getEditingObserable());
    this.context.bindValue(scaSimplePropertyControl.getTarget(),
            EMFObservables.observeValue(this.prop, ScaPackage.Literals.SCA_SIMPLE_PROPERTY__VALUE), null,
            new BooleanUpdateStrategy());
}

From source file:gov.redhawk.sca.waveform.controlpanel.propertyEditors.DecimalPropertyEditor.java

License:Open Source License

@Override
public void setupBindings() {
    this.context = new EMFDataBindingContext();
    if (this.enumViewer == null) {
        final ScaSimplePropertyControl scaSimplePropertyControl = new ScaSimplePropertyControl(this.control,
                this.prop);
        final ISWTObservableValue textObservable = WidgetProperties
                .text(new int[] { SWT.FocusOut, SWT.DefaultSelection }).observe(this.control);
        this.context.bindValue(textObservable, scaSimplePropertyControl.getModel(),
                new DecimalUpdateValueStrategy2(), new DecimalUpdateValueStrategy3());
        this.context.bindValue(WidgetProperties.text(SWT.Modify).observeDelayed(UPDATE_DELAY_MS, this.control),
                scaSimplePropertyControl.getEditingObserable());
        this.context.bindValue(scaSimplePropertyControl.getTarget(),
                EMFObservables.observeValue(this.prop, ScaPackage.Literals.SCA_SIMPLE_PROPERTY__VALUE),
                new DecimalUpdateValueStrategy(), new DecimalUpdateValueStrategy());
    } else {/*from www.jav a  2  s  . com*/
        final ScaSimplePropertyControl scaSimplePropertyControl = new ScaSimplePropertyControl(
                this.enumViewer.getControl(), this.prop);
        final ISWTObservableValue selectObservable = WidgetProperties.selection()
                .observe(this.enumViewer.getCombo());
        this.context.bindValue(selectObservable, scaSimplePropertyControl.getModel(),
                new SelectionToLocalValueStrategy(), new LocalToSelectionValueStrategy());
        this.context.bindValue(SWTObservables.observeSelection(this.enumViewer.getCombo()),
                scaSimplePropertyControl.getEditingObserable(), new SelectionToLocalValueStrategy(), null);
        this.context.bindValue(scaSimplePropertyControl.getTarget(),
                EMFObservables.observeValue(this.prop, ScaPackage.Literals.SCA_SIMPLE_PROPERTY__VALUE),
                new DecimalUpdateValueStrategy(), null);
    }
}

From source file:it.rcpvision.emf.components.binding.FormControlFactory.java

License:Open Source License

protected ControlObservablePair createControlAndObservableValueForBoolean() {
    ControlObservablePair retValAndTargetPair = new ControlObservablePair();
    Button b = toolkit.createButton(parent, "", SWT.CHECK);
    retValAndTargetPair.setControl(b);//from  w w  w.j av  a  2 s . co m
    retValAndTargetPair.setObservableValue(SWTObservables.observeSelection(b));
    return retValAndTargetPair;
}

From source file:net.geoprism.shapefile.locatedIn.LocatedInPage.java

License:Open Source License

private void bind(Scale scale, String attribute) {
    IObservableValue uiElement = SWTObservables.observeSelection(scale);
    IObservableValue modelElement = BeanProperties.value(LocatedInBean.class, attribute).observe(bean);

    bindingContext.bindValue(uiElement, modelElement, null, null);
}

From source file:net.sf.rcer.conn.ui.login.LoginDialog.java

License:Open Source License

/**
 * Connects the UI elements to the model elements. 
 *//*from  www . j  av  a2 s.c  o  m*/
private void bindUserInterface() {

    // set the values of the locales combo
    final Collection<Locale> locales = LocaleRegistry.getInstance().getLocales();
    final Iterator<Locale> it = locales.iterator();
    final LocaleToStringConverter converter = new LocaleToStringConverter(true);
    String[] entries = new String[locales.size() + 1];
    for (int i = 0; i < locales.size(); i++) {
        entries[i] = (String) converter.convert(it.next());
    }
    entries[locales.size()] = ""; //$NON-NLS-1$
    localeCombo.setItems(entries);

    context = new DataBindingContext();

    // observe changes in the selection of the connection combo
    IObservableValue selection = ViewersObservables.observeSingleSelection(connectionComboViewer);
    IObservableValue connection = BeansObservables.observeDetailValue(selection, "connection", //$NON-NLS-1$
            IConnection.class);

    // bind the client 
    context.bindValue(SWTObservables.observeText(clientText, SWT.Modify),
            BeansObservables.observeDetailValue(connection, "client", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    context.bindValue(SWTObservables.observeEnabled(clientText),
            BeansObservables.observeDetailValue(connection, "clientEditable", boolean.class), //$NON-NLS-1$
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy());

    // bind the user name
    context.bindValue(SWTObservables.observeText(userText, SWT.Modify),
            BeansObservables.observeDetailValue(connection, "userName", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    context.bindValue(SWTObservables.observeEnabled(userText),
            BeansObservables.observeDetailValue(connection, "userEditable", boolean.class), //$NON-NLS-1$
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy());

    // bind the password
    context.bindValue(SWTObservables.observeText(passwordText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "password", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());

    // bind the locale 
    context.bindValue(SWTObservables.observeSelection(localeCombo),
            BeansObservables.observeDetailValue(connection, "locale", Locale.class), //$NON-NLS-1$
            new UpdateValueStrategy().setConverter(new LocaleFromStringConverter()),
            new UpdateValueStrategy().setConverter(new LocaleToStringConverter(true)));
    context.bindValue(SWTObservables.observeEnabled(localeCombo),
            BeansObservables.observeDetailValue(connection, "localeEditable", boolean.class), //$NON-NLS-1$
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy());

    // provide the connection list with input data
    connectionComboViewer.setContentProvider(new ObservableListContentProvider());
    connectionComboViewer.setInput(credentials);

    // select the first entry
    connectionComboViewer.setSelection(new StructuredSelection(credentials.get(0)));

    // only enable the combo box if more than one connection can be chosen
    connectionComboViewer.getCombo().setEnabled(credentials.size() > 1);

}