List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeSelection
@Deprecated public static ISWTObservableValue observeSelection(Control control)
control
. From source file:com.netxforge.netxstudio.screens.f4.NewEditJob.java
License:Open Source License
public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext bindingContext = new EMFDataBindingContext(); // JOB_STATE//from w w w. j av a 2s. c o m EMFUpdateValueStrategy jobStateModelToTargetStrategy = new EMFUpdateValueStrategy(); jobStateModelToTargetStrategy.setConverter(new IConverter() { public Object getFromType() { return JobState.class; } public Object getToType() { return Boolean.class; } public Object convert(Object fromObject) { JobState current = (JobState) fromObject; if (current.getValue() == JobState.ACTIVE_VALUE) { return Boolean.TRUE; } else { return Boolean.FALSE; } } }); EMFUpdateValueStrategy jobStateTargetToModelStrategy = new EMFUpdateValueStrategy(); jobStateTargetToModelStrategy.setConverter(new IConverter() { public Object getFromType() { return Boolean.class; } public Object getToType() { return JobState.class; } public Object convert(Object fromObject) { Boolean current = (Boolean) fromObject; if (current) { return JobState.ACTIVE; } else { return JobState.IN_ACTIVE; } } }); IObservableValue jobStateObservable = SWTObservables.observeSelection(btnActive); IEMFValueProperty jobStateProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__JOB_STATE); bindingContext.bindValue(jobStateObservable, jobStateProperty.observe(job), jobStateTargetToModelStrategy, jobStateModelToTargetStrategy); // JOB_NAME EMFUpdateValueStrategy nameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Name is required"); IObservableValue textObserveJobName = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(this.txtJobName, SWT.Modify)); IEMFValueProperty textJobNameValue = EMFProperties.value(SchedulingPackage.Literals.JOB__NAME); bindingContext.bindValue(textObserveJobName, textJobNameValue.observe(job), nameStrategy, null); // //////////////////////////////////////////////////////// // WRITABLE OBSERVABLES // All these widgets, do not directly through the model and are // therefore bound // separately for each sync direction through a WritableValue // //////////////////////////////////////////////////////// comboViewerOn.setContentProvider(new ArrayContentProvider()); comboViewerOn.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return NonModelUtils.weekDay((Integer) element); } }); comboViewerOn.setInput(NonModelUtils.weekDaysAsInteger().toArray()); comboViewerEvery.setContentProvider(new ArrayContentProvider()); comboViewerEvery.setInput(ComboStartInput); // //////////////////////////// // OBSERVABLES THROUGH AN AGGREGATOR // ////////////////////////////// comboViewerOnWritableValue = new WritableValue(); comboViewerEveryWritableValue = new WritableValue(); cdateTimeStartTimeWritableValue = new WritableValue(); dateChooserStartsOnWritableValue = new WritableValue(); dateChooserEndsOnWritableValue = new WritableValue(); btnOnWritableValue = new WritableValue(); btnAfterWritableValue = new WritableValue(); btnNeverWritableValue = new WritableValue(); txtOccurencesWritableValue = new WritableValue(); comboViewerOnObserveSingleSelection = ViewersObservables.observeSingleSelection(comboViewerOn); comboViewerEveryObserveSingleSelection = ViewersObservables.observeSingleSelection(comboViewerEvery); comboViewerEveryObserveText = SWTObservables.observeText(comboViewerEvery.getCombo()); comboObserveStartTime = new CDateTimeObservableValue(this.cdateTimeStartTime); dateChooseObserveStartDate = new DateChooserComboObservableValue(dateChooserStartsOn, SWT.Modify); dateChooseObserveEndDate = new DateChooserComboObservableValue(dateChooserEndsOn, SWT.Modify); endOnObservable = SWTObservables.observeSelection(btnOn); endOccurencesObservable = SWTObservables.observeSelection(btnAfter); endNeverObservable = SWTObservables.observeSelection(btnNever); occurenceObservable = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(this.txtOccurences, SWT.Modify)); // //////////////////////////// // OPPOSITE BINDING // /////////////////////////// bindingContext.bindValue(comboViewerOnObserveSingleSelection, comboViewerOnWritableValue, null, null); bindingContext.bindValue(comboViewerEveryObserveSingleSelection, comboViewerEveryWritableValue, null, null); bindingContext.bindValue(comboObserveStartTime, cdateTimeStartTimeWritableValue, null, null); bindingContext.bindValue(dateChooseObserveStartDate, dateChooserStartsOnWritableValue, null, null); bindingContext.bindValue(dateChooseObserveEndDate, dateChooserEndsOnWritableValue, null, null); bindingContext.bindValue(endNeverObservable, btnNeverWritableValue, null, null); bindingContext.bindValue(endOccurencesObservable, btnAfterWritableValue, null, null); bindingContext.bindValue(endOnObservable, btnOnWritableValue, null, null); EMFUpdateValueStrategy occurencesModelToTargetStrategy = new EMFUpdateValueStrategy(); occurencesModelToTargetStrategy.setConverter(new IConverter() { public Object getFromType() { return Integer.class; } public Object getToType() { return String.class; } public Object convert(Object fromObject) { if (fromObject != null) { return ((Integer) fromObject).toString(); } else { return ""; } } }); EMFUpdateValueStrategy occurencesTargetToModelStrategy = new EMFUpdateValueStrategy(); occurencesTargetToModelStrategy.setConverter(new IConverter() { public Object getFromType() { return String.class; } public Object getToType() { return Integer.class; } public Object convert(Object fromObject) { try { String from = (String) fromObject; if (from.length() == 0) { return 0; } return new Integer(from); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } return 0; } }); bindingContext.bindValue(occurenceObservable, this.txtOccurencesWritableValue, occurencesTargetToModelStrategy, occurencesModelToTargetStrategy); // ///////////////////////////////////////////////// // ACTUAL MODEL BINDING // //////////////////////////////////////////////// // The following binding is indirect through a series of writableValues. // / The writables, which will be deduced from various widgets by our // aggregator. IObservableValue startTimeWritableValue = new WritableValue(); IObservableValue endTimeWritableValue = new WritableValue(); IObservableValue intervalWritableValue = new WritableValue(); IObservableValue repeatWritableValue = new WritableValue(); // The aggregator. JobInfoAggregate aggregate = new JobInfoAggregate(startTimeWritableValue, endTimeWritableValue, intervalWritableValue, repeatWritableValue); IEMFValueProperty startTimeProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__START_TIME); IEMFValueProperty endTimeProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__END_TIME); IEMFValueProperty intervalProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__INTERVAL); IEMFValueProperty repeatProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__REPEAT); // TODO, add converters and validators. IObservableValue startTimeObservableValue = startTimeProperty.observe(job); IObservableValue endTimeObservableValue = endTimeProperty.observe(job); IObservableValue intervalObservableValue = intervalProperty.observe(job); IObservableValue repeatObservableValue = repeatProperty.observe(job); // ////////////////////// // BIND OUR WRITABLES. // //////////////////// EMFUpdateValueStrategy targetToModelStrategy = new EMFUpdateValueStrategy(); targetToModelStrategy.setConverter(new DateToXMLConverter()); bindingContext.bindValue(startTimeWritableValue, startTimeObservableValue, targetToModelStrategy, null); bindingContext.bindValue(endTimeWritableValue, endTimeObservableValue, targetToModelStrategy, null); bindingContext.bindValue(intervalWritableValue, intervalObservableValue, targetToModelStrategy, null); bindingContext.bindValue(repeatWritableValue, repeatObservableValue, targetToModelStrategy, null); // Set initial values of the widgets. , without having the aggregator // activated yet. this.setInitial(startTimeObservableValue.getValue(), endTimeObservableValue.getValue(), repeatObservableValue.getValue(), intervalObservableValue.getValue()); // Set the initial values of the aggregator. aggregate.setInitialValues(job); this.enableAggregate(aggregate); // bindingContext.updateTargets(); return bindingContext; }
From source file:com.netxforge.netxstudio.screens.f4.NewEditMappingColumn.java
License:Open Source License
private void initDataBindingHeaderMappingColumn(EMFDataBindingContext context) { // /////////////////////////// // WRITABLE OBSERVABLES MAPPING COLUMN KIND // /////////////////////////// btnIdentifierWritableValue = new WritableValue(); btnDateTimeWritableValue = new WritableValue(); btnDateWritableValue = new WritableValue(); btnTimeWritableValue = new WritableValue(); btnIntervalWritableValue = new WritableValue(); identifierObservable = SWTObservables.observeSelection(btnIdentifier); dateTimeObservable = SWTObservables.observeSelection(btnDatetime); dateObservable = SWTObservables.observeSelection(btnDate); timeObservable = SWTObservables.observeSelection(btnTime); intervalObservable = SWTObservables.observeSelection(this.btnInterval); context.bindValue(identifierObservable, btnIdentifierWritableValue, null, null); context.bindValue(dateTimeObservable, btnDateTimeWritableValue, null, null); context.bindValue(dateObservable, btnDateWritableValue, null, null); context.bindValue(timeObservable, btnTimeWritableValue, null, null); context.bindValue(intervalObservable, btnIntervalWritableValue, null, null); // /////////////////////////// // PATTERN FIELD OBSERVABLES // /////////////////////////// dateTimePatternObservable = SWTObservables.observeText(this.cmbDateTimePattern); datePatternObservable = SWTObservables.observeText(this.cmbDatePattern); timePatternObservable = SWTObservables.observeText(this.cmbTimePattern); // /////////////////////////// // IDENTIFIER BINDING // /////////////////////////// IObservableValue identifierPatternObservable = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(this.txtIdentifierPattern, SWT.Modify)); IObservableValue objectKindObservable = SWTObservables.observeText(this.txtObject, SWT.Modify); IObservableValue objectAttributeObservable = SWTObservables.observeText(this.txtObjectAttribute, SWT.Modify);/*from w w w. j a v a2s .c o m*/ IEMFEditValueProperty objectPatternProperty = EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.IDENTIFIER_DATA_KIND__PATTERN)); IEMFEditValueProperty objectKindProperty = EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.IDENTIFIER_DATA_KIND__OBJECT_KIND)); IEMFEditValueProperty objectAttributeProperty = EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.IDENTIFIER_DATA_KIND__OBJECT_PROPERTY)); context.bindValue(identifierPatternObservable, objectPatternProperty.observe(mxlsColumn)); EMFUpdateValueStrategy mttObjectKindStrategy = new EMFUpdateValueStrategy(); mttObjectKindStrategy.setConverter(new MTTObjectKindStrategy()); EMFUpdateValueStrategy ttmObjectKindStrategy = new EMFUpdateValueStrategy(); ttmObjectKindStrategy.setConverter(new TTMObjectKindStrategy()); context.bindValue(objectKindObservable, objectKindProperty.observe(mxlsColumn), ttmObjectKindStrategy, mttObjectKindStrategy); /* * A default strategy to delegate to the default converter, for non * specific cases. */ EMFUpdateValueStrategy mttObjectAttributeStrategy = new EMFUpdateValueStrategy(); mttObjectAttributeStrategy.setConverter(new MTTObjectAttributeStrategy()); EMFUpdateValueStrategy ttmObjectAttributeStrategy = new EMFUpdateValueStrategy(); ttmObjectAttributeStrategy.setConverter(new TTMObjectAttributeConverter()); context.bindValue(objectAttributeObservable, objectAttributeProperty.observe(mxlsColumn), ttmObjectAttributeStrategy, mttObjectAttributeStrategy); }
From source file:com.netxforge.netxstudio.screens.f4.NewEditMappingColumn.java
License:Open Source License
private void initDataBindingDataMappingColumn(EMFDataBindingContext context, IEMFValueProperty dataKindProperty) { // Metric option selected. btnMetricWritableValue = new WritableValue(); metricObservable = SWTObservables.observeSelection(btnMetricValue); context.bindValue(metricObservable, btnMetricWritableValue, null, null); // We should really observe the button. metricValueObservable = SWTObservables.observeText(txtMetric, SWT.Modify); // valuePatternObservable = SWTObservables.observeText( // this.txtMetricValuePattern, SWT.Modify); EMFUpdateValueStrategy metricModelToTargetStrategy = new EMFUpdateValueStrategy(); metricModelToTargetStrategy.setConverter(new DataKindModelToTargetConverter() { public Object convert(Object fromObject) { if (fromObject instanceof ValueDataKind) { Metric metric = ((ValueDataKind) fromObject).getMetricRef(); if (metric != null) { return metric.getName(); }/*ww w. j av a 2 s .c om*/ } return null; } }); context.bindValue(metricValueObservable, dataKindProperty.observe(mxlsColumn), null, metricModelToTargetStrategy); cmbViewrMetricKindHint.setContentProvider(new ArrayContentProvider()); cmbViewrMetricKindHint.setLabelProvider(new LabelProvider()); cmbViewrMetricKindHint.setInput(KindHintType.VALUES); metricKindHintObservable = ViewerProperties.singleSelection().observe(cmbViewrMetricKindHint); IEMFEditValueProperty KindHintProperty = EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__KIND_HINT)); context.bindValue(metricKindHintObservable, KindHintProperty.observe(mxlsColumn), null, null); }
From source file:com.netxforge.netxstudio.screens.nf4.NewEditUser.java
License:Open Source License
/** * Converted to new EMF API.// w w w .j a v a2 s . c om * * @return */ public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext bindingContext = new EMFDataBindingContext(); validationService.registerBindingContext(bindingContext); // Validation Strategies EMFUpdateValueStrategy loginStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Login is required"); EMFUpdateValueStrategy firstNameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("First name is required"); EMFUpdateValueStrategy lastNameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Last name is required"); EMFUpdateValueStrategy emailNameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Email is required"); // The active strategy is merely a warning. EMFUpdateValueStrategy activeStrategy = ValidationService.getStrategyfactory() .strategyAfterGet(new IValidator() { public IStatus validate(Object value) { if (value instanceof Boolean) { if (!((Boolean) value).booleanValue()) { // Not active, issue warning. return new Status(IStatus.WARNING, ScreensActivator.PLUGIN_ID, "Person not active, are you sure"); } else { return Status.OK_STATUS; } } else { return new Status(IStatus.ERROR, ScreensActivator.PLUGIN_ID, "Should and will not occure"); } } }); EMFUpdateValueStrategy roleStrategy = ValidationService.getStrategyfactory() .strategyAfterGet(new IValidator() { public IStatus validate(Object value) { if (value == null) { return new Status(IStatus.WARNING, ScreensActivator.PLUGIN_ID, "A role should be selected"); } else { // Any other value should do. return Status.OK_STATUS; } } }); // Bindings IObservableValue textObserveTextObserveWidget_1 = SWTObservables.observeDelayedValue(100, SWTObservables.observeText(txtLogin, SWT.Modify)); IEMFValueProperty userLoginObserveValue_1 = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__LOGIN); bindingContext.bindValue(textObserveTextObserveWidget_1, userLoginObserveValue_1.observe(user), loginStrategy, null); IObservableValue txtFirstNameObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtFirstName, SWT.Modify)); // IObservableValue userFirstNameObserveValue = // EMFObservables.observeValue(user, Literals.PERSON__FIRST_NAME); IEMFValueProperty userFirstNameObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__FIRST_NAME); bindingContext.bindValue(txtFirstNameObserveTextObserveWidget, userFirstNameObserveValue.observe(user), firstNameStrategy, null); IObservableValue txtLastNameObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtLastName, SWT.Modify)); // IObservableValue userLastNameObserveValue = EMFObservables // .observeValue(user, Literals.PERSON__LAST_NAME); IEMFValueProperty userLastNameObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__LAST_NAME); bindingContext.bindValue(txtLastNameObserveTextObserveWidget, userLastNameObserveValue.observe(user), lastNameStrategy, null); IObservableValue txtEmailObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtEmail, SWT.Modify)); // IObservableValue userEmailObserveValue = EMFObservables.observeValue( // user, Literals.PERSON__EMAIL); IEMFValueProperty userEmailObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__EMAIL); bindingContext.bindValue(txtEmailObserveTextObserveWidget, userEmailObserveValue.observe(user), emailNameStrategy, null); IObservableValue btnCheckObserveSelectionObserveWidget = SWTObservables.observeSelection(btnCheck); IEMFValueProperty userActiveObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__ACTIVE); bindingContext.bindValue(btnCheckObserveSelectionObserveWidget, userActiveObserveValue.observe(user), activeStrategy, null); IObservableValue passwordObservableValue = new WritableValue(); IObservableValue txtPasswordObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtPass, SWT.Modify)); IObservableValue txtConfirmObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtConfirm, SWT.Modify)); // NEW CODE, Use a custom MultiValidator, it produces NewPasswordConfirmed newPasswordConfirmed = new NewPasswordConfirmed(bindingContext, new IObservableValue[] { txtPasswordObserveTextObserveWidget, txtConfirmObserveTextObserveWidget }); passwordObservableValue = newPasswordConfirmed .observeValidatedValue(newPasswordConfirmed.getMiddletons().get(0)); // OLD CODE. // Special writable case for password and confirmation, // both share the value changed listener, which only sets the model. // when both passwords are the same. 2 x widgets -> model // PasswordConfirmed confirmedHandler = new PasswordConfirmed( // passwordObservableValue); // txtPasswordObserveTextObserveWidget // .addValueChangeListener(confirmedHandler); // txtConfirmObserveTextObserveWidget // .addValueChangeListener(confirmedHandler); // EMFUpdateValueStrategy passStrategy = ValidationService // .getStrategyfactory().strategyAfterGet(confirmedHandler); EMFUpdateValueStrategy passStrategy = new EMFUpdateValueStrategy(); passStrategy.setConverter(new PasswordConverter()); IEMFValueProperty passwordObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__PASSWORD); // Password, can not be presented (Ok it can but we don't want to), so only target to model. bindingContext.bindValue(passwordObservableValue, passwordObserveValue.observe(user), passStrategy, null); newPasswordConfirmed.revalidateExternal(); // Hand coded binding for a combo. ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); this.getComboViewerWidget().setContentProvider(listContentProvider); IObservableMap observeMap = EMFObservables.observeMap(listContentProvider.getKnownElements(), Literals.ROLE__NAME); this.getComboViewerWidget().setLabelProvider(new ObservableMapLabelProvider(observeMap)); rolesResource = editingService.getData(GenericsPackage.Literals.ROLE); IEMFListProperty l = EMFEditProperties.resource(editingService.getEditingDomain()); IObservableList rolesObservableList = l.observe(rolesResource); // obm.addObservable(rolesObservableList); this.getComboViewerWidget().setInput(rolesObservableList); IObservableValue comboObserveProxy = ViewerProperties.singleSelection().observe(comboViewer); IEMFValueProperty roleObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__ROLES); bindingContext.bindValue(comboObserveProxy, roleObserveValue.observe(user), roleStrategy, null); return bindingContext; }
From source file:com.rcpcompany.uibindings.internal.uiAttributeFactories.ButtonDefaultUIAttributeFactory.java
License:Open Source License
@Override public IUIAttribute create(Widget widget, String attribute) { final int style = widget.getStyle(); if (((style & SWT.CHECK) == SWT.CHECK) || ((style & SWT.RADIO) == SWT.RADIO) || ((style & SWT.TOGGLE) == SWT.TOGGLE)) return new SimpleUIAttribute(widget, attribute, SWTObservables.observeSelection((Control) widget), true);/*from w w w.jav a2 s. co m*/ else return new SimpleUIAttribute(widget, attribute, new ButtonTextObservableValue((Button) widget), true); }
From source file:com.rcpcompany.uibindings.internal.uiAttributeFactories.SelectionUIAttributeFactory.java
License:Open Source License
@Override public IUIAttribute create(Widget widget, String attribute) { return new SimpleUIAttribute(widget, attribute, SWTObservables.observeSelection((Control) widget), true); }
From source file:com.xored.af.ui.forms.parts.CheckboxFormPart.java
License:Open Source License
@Override protected IObservableValue observeControl() { return SWTObservables.observeDelayedValue(400, SWTObservables.observeSelection(control)); }
From source file:de.prozesskraft.pmodel.PmodelPartUi1.java
protected DataBindingContext initDataBindingsRefresh() { DataBindingContext bindingContextRefresh = new DataBindingContext(); ////from w w w. j a va2 s . co m // IObservableValue targetObservableRefresh = WidgetProperties.text().observe(button_refresh); // IObservableValue modelObservableRefresh = BeanProperties.value("nextRefreshSecondsText").observe(einstellungen); // bindingContextRefresh.bindValue(targetObservableRefresh, modelObservableRefresh, null, null); // // IObservableValue targetObservableRefreshInterval = WidgetProperties.selection().observe(spinner_refreshinterval); // IObservableValue modelObservableRefreshInterval = BeanProperties.value("refreshInterval").observe(einstellungen); // bindingContextRefresh.bindValue(targetObservableRefreshInterval, modelObservableRefreshInterval, null, null); // // // IObservableValue targetObservableRefreshHit = WidgetProperties.selection().observe(button_refresh); IObservableValue targetObservableRefreshHit = SWTObservables.observeSelection(button_refresh); // IObservableValue modelObservableRefreshHit = BeansObservables.observeValue(einstellungen, "refreshNow"); IObservableValue modelObservableRefreshHit = BeanProperties.value("refreshNow").observe(einstellungen); bindingContextRefresh.bindValue(targetObservableRefreshHit, modelObservableRefreshHit, null, null); // return bindingContextRefresh; }
From source file:de.uniluebeck.itm.spyglass.gui.configuration.BasicGroupComposite.java
License:Open Source License
/** * Sets the parameters necessary for data binding * /* w ww.ja v a 2s .c o m*/ * @param dbc * the data binding context * @param config * the configuration * @param owner * @param manager * the plug-in managing instance * @param isInstancePage * <code>true</code> indicates that this widget is used to set parameters for a * plug-in instance, <code>false</code> indicates that this widget is used to set * parameters for a plug-in type. * */ public void setDatabinding(final DataBindingContext dbc, final PluginXMLConfig config, final Plugin owner, final PluginManager manager, final boolean isInstancePage) { // plugin name { final IObservableValue modelObservable = BeansObservables.observeValue(dbc.getValidationRealm(), config, PluginXMLConfig.PROPERTYNAME_NAME); final ISWTObservableValue fieldObservableText = SWTObservables.observeText(pluginName, SWT.Modify); if (isInstancePage) { dbc.bindValue(fieldObservableText, modelObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator(new PluginNameValidator(manager, owner)), null); } else { dbc.bindValue(fieldObservableText, modelObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null); } } // semantic types { final IObservableValue modelObservable2 = BeansObservables.observeValue(dbc.getValidationRealm(), config, PluginXMLConfig.PROPERTYNAME_SEMANTIC_TYPES); final UpdateValueStrategy strToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT); final UpdateValueStrategy strFromModel = new UpdateValueStrategy(); strFromModel.setConverter(new IntListToStringConverter()); strToModel.setConverter(new StringToIntListConverter()); strToModel.setAfterConvertValidator(new IntegerRangeValidator("Semantic types", -1, 255)); strToModel.setAfterGetValidator(new StringToIntListValidator("Semantic types")); dbc.bindValue(SWTObservables.observeText(this.semanticTypes, SWT.Modify), modelObservable2, strToModel, strFromModel); } // all semTypes { final IObservableValue observableAllSemTypes = BeansObservables.observeValue(dbc.getValidationRealm(), config, PluginXMLConfig.PROPERTYNAME_ALL_SEMANTIC_TYPES); final IObservableValue observableAllSemTypesCheckbox = SWTObservables.observeSelection(this.allTypes); dbc.bindValue(observableAllSemTypesCheckbox, observableAllSemTypes, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null); } // is visible { final IObservableValue observableVisible = BeansObservables.observeValue(dbc.getValidationRealm(), config, PluginXMLConfig.PROPERTYNAME_VISIBLE); dbc.bindValue(SWTObservables.observeSelection(this.isVisible), observableVisible, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null); } // is active { final IObservableValue observableActive = BeansObservables.observeValue(dbc.getValidationRealm(), config, PluginXMLConfig.PROPERTYNAME_ACTIVE); final IObservableValue observableActiveButton = SWTObservables.observeSelection(this.isActive); dbc.bindValue(observableActiveButton, observableActive, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null); } // disable the visibility field if plug-in is inactive { // ... but only if it's visibility button is not to be disabled all the time if (!basicOptions.equals(BasicOptions.ALL_BUT_VISIBLE) && !basicOptions.equals(BasicOptions.ALL_BUT_VISIBLE_AND_SEMANTIC_TYPES)) { dbc.bindValue(SWTObservables.observeEnabled(this.isVisible), SWTObservables.observeSelection(this.isActive), null, null); } } }
From source file:de.uniluebeck.itm.spyglass.gui.configuration.GeneralPreferencesComposite.java
License:Open Source License
public void setDatabinding(final DataBindingContext dbc, final GeneralSettingsXMLConfig config) { this.config = config; this.dbc = dbc; // unit length final IObservableValue modelObservable2 = BeansObservables.observeValue(dbc.getValidationRealm(), config.getMetrics(), "unit"); dbc.bindValue(SWTObservables.observeText(this.unitLength, SWT.Modify), modelObservable2, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator( new StringRegExValidator("Unit of length", ".+", "Please enter a unit.")), new UpdateValueStrategy()); // showRuler/*from www.j av a 2 s.c om*/ final IObservableValue observableVisible = BeansObservables.observeValue(dbc.getValidationRealm(), config, "showRuler"); dbc.bindValue(SWTObservables.observeSelection(this.showRuler), observableVisible, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null); // unit of time final IObservableValue modelObservable2b = BeansObservables.observeValue(dbc.getValidationRealm(), config, "timeUnit"); dbc.bindValue(SWTObservables.observeText(this.unitTime, SWT.Modify), modelObservable2b, new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).setAfterConvertValidator( new StringRegExValidator("Unit of time", ".+", "Please enter a unit.")), new UpdateValueStrategy()); // offset X dbc.bindValue(SWTObservables.observeText(this.offsetX, SWT.Modify), BeansObservables.observeValue(dbc.getValidationRealm(), config.getMetrics(), "abs2metricOffsetX"), new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), new UpdateValueStrategy()); // offset Y dbc.bindValue(SWTObservables.observeText(this.offsetY, SWT.Modify), BeansObservables.observeValue(dbc.getValidationRealm(), config.getMetrics(), "abs2metricOffsetY"), new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), new UpdateValueStrategy()); // scale X dbc.bindValue(SWTObservables.observeText(this.scaleX, SWT.Modify), BeansObservables.observeValue(dbc.getValidationRealm(), config.getMetrics(), "abs2metricFactorX"), new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), new UpdateValueStrategy()); // scale Y dbc.bindValue(SWTObservables.observeText(this.scaleY, SWT.Modify), BeansObservables.observeValue(dbc.getValidationRealm(), config.getMetrics(), "abs2metricFactorY"), new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), new UpdateValueStrategy()); // scale Time dbc.bindValue(SWTObservables.observeText(this.scaleTime, SWT.Modify), BeansObservables.observeValue(dbc.getValidationRealm(), config, "timeScale"), new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), new UpdateValueStrategy()); dbc.bindValue(SWTObservables.observeText(this.label11length), SWTObservables.observeText(this.unitLength, SWT.Modify), null, null); dbc.bindValue(SWTObservables.observeText(this.label9length), SWTObservables.observeText(this.unitLength, SWT.Modify), null, null); updateScaleLink(); }