Java Code Examples for org.eclipse.core.databinding.UpdateValueStrategy#setConverter()
The following examples show how to use
org.eclipse.core.databinding.UpdateValueStrategy#setConverter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContractPropertySection.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
private UpdateValueStrategy isLastElementToBooleanStrategy() { final UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setConverter(new Converter(Object.class, Boolean.class) { @Override public Object convert(final Object from) { if (from instanceof ContractConstraint) { final Contract contract = (Contract) ((ContractConstraint) from).eContainer(); final EList<ContractConstraint> constraints = contract.getConstraints(); return constraints.size() > 1 && constraints.indexOf(from) < constraints.size() - 1; } return false; } }); return strategy; }
Example 2
Source File: RolesToAccessRightsPreferencePage.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
protected DataBindingContext initDataBindings(){ DataBindingContext bindingContext = new DataBindingContext(); // IObservableValue observeTextTxti18nObserveWidget = WidgetProperties.text(SWT.Modify).observe(txti18n); IObservableValue wvTranslatedLabelObserveDetailValue = PojoProperties.value(Role.class, "translatedLabel", String.class).observeDetail(wv); bindingContext.bindValue(observeTextTxti18nObserveWidget, wvTranslatedLabelObserveDetailValue, null, null); // IObservableValue observeEnabledTxtRoleNameObserveWidget = WidgetProperties.enabled().observe(txtRoleName); IObservableValue wvSystemRoleObserveDetailValue = PojoProperties.value(Role.class, "systemRole", Boolean.class).observeDetail(wv); UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setConverter(new BooleanNotConverter()); bindingContext.bindValue(observeEnabledTxtRoleNameObserveWidget, wvSystemRoleObserveDetailValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), strategy); // return bindingContext; }
Example 3
Source File: EssentialsPage.java From thym with Eclipse Public License 1.0 | 5 votes |
protected DataBindingContext initDataBindings() { DataBindingContext bindingContext = new DataBindingContext(); // IObservableValue observeTextTxtIdtxtObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtIdtxt); IObservableValue idGetWidgetObserveValue = BeanProperties.value("id").observe(getWidget()); bindingContext.bindValue(observeTextTxtIdtxtObserveWidget, idGetWidgetObserveValue, null, null); // IObservableValue observeTextTxtNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtName); IObservableValue nameGetWidgetObserveValue = BeanProperties.value("name").observe(getWidget()); UpdateValueStrategy strategy_3 = new UpdateValueStrategy(); strategy_3.setConverter(new StringToDisplayableStringConverter()); bindingContext.bindValue(observeTextTxtNameObserveWidget, nameGetWidgetObserveValue, null, strategy_3); // IObservableValue observeTextTxtDescriptionObserveWidget = WidgetProperties.text(SWT.Modify) .observe(txtDescription); IObservableValue descriptionGetWidgetObserveValue = BeanProperties.value("description").observe(getWidget()); UpdateValueStrategy strategy_2 = new UpdateValueStrategy(); strategy_2.setConverter(new StringToDisplayableStringConverter()); bindingContext.bindValue(observeTextTxtDescriptionObserveWidget, descriptionGetWidgetObserveValue, null, strategy_2); // IObservableValue observeTextTxtVersionObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtVersion); IObservableValue versionGetWidgetObserveValue = BeanProperties.value("version").observe(getWidget()); bindingContext.bindValue(observeTextTxtVersionObserveWidget, versionGetWidgetObserveValue, null, null); // return bindingContext; }
Example 4
Source File: InputNameEditingSupport.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected Binding createBinding(IObservableValue target, final IObservableValue model) { UpdateValueStrategy targetToModel = new UpdateValueStrategy(); targetToModel.setConverter(new Converter(String.class, String.class) { @Override public Object convert(Object from) { return from != null ? NamingUtils.toJavaIdentifier(from.toString(), false) : null; } }); targetToModel.setBeforeSetValidator(new IValidator() { @Override public IStatus validate(Object input) { if (input == null || input.toString().isEmpty()) { return ValidationStatus.error(Messages.nameIsEmpty); } for (Input i : definition.getInput()) { EObject observed = (EObject) ((EObjectObservableValue) model).getObserved(); if (!i.equals(observed) && i.getName() != null && i.getName().equals(input.toString())) { return ValidationStatus.error(Messages.nameAlreadyExists); } } return Status.OK_STATUS; } }); return context.bindValue(target, model, targetToModel, null); }
Example 5
Source File: OutputNameEditingSupport.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected Binding createBinding(IObservableValue target, final IObservableValue model) { UpdateValueStrategy targetToModel = new UpdateValueStrategy(); targetToModel.setConverter(new Converter(String.class, String.class) { @Override public Object convert(Object from) { return from != null ? NamingUtils.toJavaIdentifier(from.toString(), false) : null; } }); targetToModel.setBeforeSetValidator(new IValidator() { @Override public IStatus validate(Object input) { if (input == null || input.toString().isEmpty()) { return ValidationStatus.error(Messages.nameIsEmpty); } for (Input i : definition.getInput()) { EObject observed = (EObject) ((EObjectObservableValue) model).getObserved(); if (!i.equals(observed) && i.getName() != null && i.getName().equals(input.toString())) { return ValidationStatus.error(Messages.nameAlreadyExists); } } return Status.OK_STATUS; } }); return context.bindValue(target, model, targetToModel, null); }
Example 6
Source File: GroovyScriptFileDialog.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected void showContent(String type) { currentExpressionEditor = new GroovyScriptFileEditor(); if (currentExpressionEditor != null) { if (dataBindingContext != null) { dataBindingContext.dispose(); } dataBindingContext = new EMFDataBindingContext(); currentExpressionEditor.createExpressionEditor(contentComposite, dataBindingContext); if (helpControl != null) { helpControl.setVisible(currentExpressionEditor.provideDialogTray()); if (getTray() != null) { closeTray(); } } UpdateValueStrategy selectionToExpressionType = new UpdateValueStrategy(); IConverter convert = new Converter(IExpressionProvider.class, String.class) { @Override public Object convert(Object from) { return from != null ? ((IExpressionProvider) from).getExpressionType() : null; } }; selectionToExpressionType.setConverter(convert); currentExpressionEditor.bindExpression(dataBindingContext, context, inputExpression, viewerTypeFilters, null); } }
Example 7
Source File: ContractInputExpressionEditor.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected UpdateValueStrategy selectionToInputNameStrategy() { final UpdateValueStrategy strategy = new UpdateValueStrategy(); final IConverter nameConverter = new Converter(ContractInput.class, String.class) { @Override public Object convert(final Object input) { return input != null ? ((ContractInput) input).getName() : null; } }; strategy.setConverter(nameConverter); return strategy; }
Example 8
Source File: ExpressionViewer.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected void bindExpression() { if (expressionBinding != null && externalDataBindingContext != null) { externalDataBindingContext.removeBinding(expressionBinding); expressionBinding.dispose(); } final IObservableValue nameObservable = getExpressionNameObservable(); final IObservableValue typeObservable = getExpressionTypeObservable(); final IObservableValue returnTypeObservable = getExpressionReturnTypeObservable(); final IObservableValue contentObservable = getExpressionContentObservable(); nameObservable.addValueChangeListener(this); typeObservable.addValueChangeListener(this); contentObservable.addValueChangeListener(this); returnTypeObservable.addValueChangeListener(this); final UpdateValueStrategy targetToModelNameStrategy = new UpdateValueStrategy(); if (mandatoryFieldName != null) { targetToModelNameStrategy .setBeforeSetValidator(mandatoryFieldValidator.orElse(new EmptyInputValidator(mandatoryFieldName))); } targetToModelNameStrategy.setConverter(getNameConverter()); final ISWTObservableValue textDelayedObservableValue = SWTObservables.observeDelayedValue(500, SWTObservables.observeText(textControl, SWT.Modify)); expressionBinding = internalDataBindingContext.bindValue(textDelayedObservableValue, nameObservable, targetToModelNameStrategy, updateValueStrategy().create()); bindEditableText(typeObservable); internalDataBindingContext.bindValue(ViewersObservables.observeSingleSelection(contentAssistText), getSelectedExpressionObservable()); if (externalDataBindingContext != null) { externalDataBindingContext.addBinding(expressionBinding); externalDataBindingContext.addValidationStatusProvider(expressionViewerValidator); } }
Example 9
Source File: ContractInputExpressionEditor.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected UpdateValueStrategy selectionToTypeStrategy() { final UpdateValueStrategy strategy = new UpdateValueStrategy(); final IConverter converter = new Converter(ContractInput.class, String.class) { @Override public Object convert(final Object input) { return ExpressionConstants.CONTRACT_INPUT_TYPE; } }; strategy.setConverter(converter); return strategy; }
Example 10
Source File: SelectDatabaseOutputTypeWizardPage.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected Button createSingleChoice(final Composite choicesComposite, EMFDataBindingContext context) { final Button singleRadio = new Button(choicesComposite, SWT.RADIO); singleRadio.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).create()); singleRadio.setText(Messages.singleValue); final Label singleIcon = new Label(choicesComposite, SWT.NONE); singleIcon.setLayoutData( GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(15, 0).grab(true, false).create()); final UpdateValueStrategy selectImageStrategy = new UpdateValueStrategy(); selectImageStrategy.setConverter(new Converter(Boolean.class, Image.class) { @Override public Object convert(Object fromObject) { if (fromObject != null && (Boolean) fromObject) { return Pics.getImage("single_placeholder.png", ConnectorPlugin.getDefault()); } else { return Pics.getImage("single_placeholder_disabled.png", ConnectorPlugin.getDefault()); } } }); singleModeRadioObserveEnabled = SWTObservables.observeEnabled(singleRadio); context.bindValue(SWTObservables.observeImage(singleIcon), singleModeRadioObserveEnabled, null, selectImageStrategy); return singleRadio; }
Example 11
Source File: SelectDatabaseOutputTypeWizardPage.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected Button createNRowsOneColChoice(final Composite choicesComposite, EMFDataBindingContext context) { final Button oneColRadio = new Button(choicesComposite, SWT.RADIO); oneColRadio.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).create()); oneColRadio.setText(Messages.nRowOneCol); final ControlDecoration oneColDeco = new ControlDecoration(oneColRadio, SWT.RIGHT, choicesComposite); oneColDeco.setImage(Pics.getImage(PicsConstants.hint)); oneColDeco.setDescriptionText(Messages.oneColHint); final Label oneColIcon = new Label(choicesComposite, SWT.NONE); oneColIcon.setLayoutData( GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(15, 0).grab(true, false).create()); final UpdateValueStrategy selectImageStrategy = new UpdateValueStrategy(); selectImageStrategy.setConverter(new Converter(Boolean.class, Image.class) { @Override public Object convert(Object fromObject) { if (fromObject != null && (Boolean) fromObject) { return Pics.getImage("column_placeholder.png", ConnectorPlugin.getDefault()); } else { return Pics.getImage("column_placeholder_disabled.png", ConnectorPlugin.getDefault()); } } }); nRowsOneColModeRadioObserveEnabled = SWTObservables.observeEnabled(oneColRadio); context.bindValue(SWTObservables.observeImage(oneColIcon), nRowsOneColModeRadioObserveEnabled, null, selectImageStrategy); return oneColRadio; }
Example 12
Source File: DBConnectorsPreferencePage.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void bindButtonWithViewer(Button button, TableViewer viewer) { UpdateValueStrategy modelToTarget = new UpdateValueStrategy(); modelToTarget.setConverter(new Converter(Object.class, Boolean.class) { @Override public Object convert(Object fromObject) { return fromObject != null; } }); context.bindValue(SWTObservables.observeEnabled(button), ViewersObservables.observeSingleSelection(viewer), null, modelToTarget); }
Example 13
Source File: DatabaseConnectorDriversWizardPage.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void bindButtonWithViewer(Button button, TableViewer viewer) { UpdateValueStrategy modelToTarget = new UpdateValueStrategy(); modelToTarget.setConverter(new Converter(Object.class, Boolean.class) { @Override public Object convert(Object fromObject) { return fromObject != null; } }); context.bindValue(SWTObservables.observeEnabled(button), ViewersObservables.observeSingleSelection(viewer), null, modelToTarget); }
Example 14
Source File: CronEditor.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected void createHourlyTab(TabFolder tablFolder) { final TabItem item = new TabItem(tablFolder, SWT.NONE); item.setText(Messages.hourly); final Composite hourlyContent = new Composite(tablFolder, SWT.NONE); hourlyContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); hourlyContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).create()); final Button everyRadio = new Button(hourlyContent, SWT.RADIO); everyRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); everyRadio.setText(Messages.every); context.bindValue(SWTObservables.observeSelection(everyRadio), PojoProperties.value("useEveryHour").observe(cronExpression)); final Composite everyComposite = new Composite(hourlyContent, SWT.NONE); everyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); everyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); final Text minuteText = new Text(everyComposite, SWT.BORDER | SWT.SINGLE); minuteText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create()); UpdateValueStrategy hourFrequencyStrategy = new UpdateValueStrategy(); hourFrequencyStrategy.setAfterGetValidator(dotValidator); hourFrequencyStrategy.setConverter(StringToNumberConverter.toInteger(true)); hourFrequencyStrategy.setBeforeSetValidator(new FrequencyValidator()); context.bindValue(SWTObservables.observeText(minuteText, SWT.Modify), PojoProperties.value("hourFrequencyForHourly").observe(cronExpression), hourFrequencyStrategy, null); final Label minuteLabel = new Label(everyComposite, SWT.NONE); minuteLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); minuteLabel.setText(Messages.hourLabel); final Button atRadio = new Button(hourlyContent, SWT.RADIO); atRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); atRadio.setText(Messages.at); final Composite atComposite = new Composite(hourlyContent, SWT.NONE); atComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); atComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(0, 0).create()); final Combo hourCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER); hourCombo.setItems(HOURS_IN_DAY); UpdateValueStrategy hourStrategy = new UpdateValueStrategy(); hourStrategy.setConverter(StringToNumberConverter.toInteger(true)); UpdateValueStrategy hourStrategy2 = new UpdateValueStrategy(); NumberFormat formatter = new DecimalFormat("#00"); hourStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true)); context.bindValue(SWTObservables.observeText(hourCombo), PojoProperties.value("atHour").observe(cronExpression), hourStrategy, hourStrategy2); final Combo minuteCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER); minuteCombo.setItems(MINUTES_IN_HOURS); UpdateValueStrategy minuteStrategy = new UpdateValueStrategy(); minuteStrategy.setConverter(StringToNumberConverter.toInteger(true)); UpdateValueStrategy minuteStrategy2 = new UpdateValueStrategy(); minuteStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true)); context.bindValue(SWTObservables.observeText(minuteCombo), PojoProperties.value("atMinute").observe(cronExpression), minuteStrategy, minuteStrategy2); final Combo secondCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER); secondCombo.setItems(MINUTES_IN_HOURS); final IObservableValue secondObservable = PojoProperties.value("atSecond").observe(cronExpression); UpdateValueStrategy secondStrategy = new UpdateValueStrategy(); secondStrategy.setConverter(StringToNumberConverter.toInteger(true)); UpdateValueStrategy secondStrategy2 = new UpdateValueStrategy(); secondStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true)); context.bindValue(SWTObservables.observeText(secondCombo), secondObservable, secondStrategy, secondStrategy2); item.setControl(hourlyContent); }
Example 15
Source File: InternalMappingComposite.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected void doBindInfo(final DataBindingContext context, final IObservableValue formMappingObservable) { final UpdateValueStrategy infoStrategy = new UpdateValueStrategy(); infoStrategy.setConverter(new InfoMessageConverter(org.bonitasoft.studio.model.process.FormMappingType.INTERNAL)); context.bindValue(WidgetProperties.text().observe(info), formMappingObservable, null, infoStrategy); }
Example 16
Source File: ComparisonExpressionEditor.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void bindExpression(final EMFDataBindingContext dataBindingContext, final EObject context, final Expression inputExpression, final ViewerFilter[] viewerTypeFilters, final ExpressionViewer expressionViewer) { this.inputExpression = inputExpression; final IObservableValue contentModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT); final IObservableValue nameModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME); final IObservableValue dependenciesModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS); final IObservableValue autoDepsModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__AUTOMATIC_DEPENDENCIES); final IObservableValue returnTypeModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); final ISWTObservableValue observeText = WidgetProperties.text(SWT.Modify) .observe(comparisonEditor.getViewer().getControl()); dataBindingContext.bindValue(observeText, nameModelObservable); dataBindingContext.bindValue(observeText, contentModelObservable); dataBindingContext.bindValue(ViewersObservables.observeInput(dependenciesViewer), dependenciesModelObservable); final UpdateValueStrategy opposite = new UpdateValueStrategy(); opposite.setConverter(new BooleanInverserConverter()); dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton), autoDepsModelObservable); dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton), SWTObservables.observeEnabled(addDependencyButton), opposite, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dependencySection.setExpanded(!automaticResolutionButton.getSelection()); addDependencyButton.setEnabled(!inputExpression.isAutomaticDependencies()); ControlDecorationSupport .create(dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(typeCombo), returnTypeModelObservable), SWT.LEFT); typeCombo.getCombo().setEnabled(!inputExpression.isReturnTypeFixed()); final ExpressionContentProvider provider = ExpressionContentProvider.getInstance(); final Set<Expression> filteredExpressions = new HashSet<Expression>(); final Expression[] expressions = provider.getExpressions(context); if (expressions != null) { filteredExpressions.addAll(Arrays.asList(expressions)); if (context != null && viewerTypeFilters != null) { for (final Expression exp : expressions) { for (final ViewerFilter filter : viewerTypeFilters) { if (filter != null && !filter.select(comparisonEditor.getViewer(), context, exp)) { filteredExpressions.remove(exp); } } } } } addDependencyButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { final SelectDependencyDialog dialog = new SelectDependencyDialog(Display.getDefault().getActiveShell(), filteredExpressions, ComparisonExpressionEditor.this.inputExpression.getReferencedElements()); dialog.open(); } }); }
Example 17
Source File: DataWizardPage.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected void bindIsMultipleData() { emfDatabindingContext.bindValue(SWTObservables.observeSelection(multiplicityButton), EMFObservables.observeValue(data, ProcessPackage.Literals.DATA__MULTIPLE)); final UpdateValueStrategy startegy = new UpdateValueStrategy(); final IObservableValue returnTypeObservable = EMFObservables.observeValue(data.getDefaultValue(), ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); final IObservableValue typeObservable = EMFObservables.observeValue(data.getDefaultValue(), ExpressionPackage.Literals.EXPRESSION__TYPE); final IObservableValue interpreterObservable = EMFObservables.observeValue(data.getDefaultValue(), ExpressionPackage.Literals.EXPRESSION__INTERPRETER); startegy.setConverter(new Converter(Boolean.class, String.class) { private Object previousExpressionType; @Override public Object convert(final Object input) { if (input != null) { if ((Boolean) input) { previousExpressionType = typeObservable.getValue(); if (!previousExpressionType.equals(ExpressionConstants.QUERY_TYPE)) { typeObservable.setValue(ExpressionConstants.SCRIPT_TYPE); interpreterObservable.setValue(ExpressionConstants.GROOVY); } defaultValueViewer.refresh(); return multipleReturnType; } else { if (previousExpressionType != null) { typeObservable.setValue(previousExpressionType); if (!ExpressionConstants.SCRIPT_TYPE.equals(previousExpressionType)) { interpreterObservable.setValue(null); } defaultValueViewer.refresh(); } return getSelectedReturnType(); } } return null; } }); emfDatabindingContext.bindValue(SWTObservables.observeSelection(multiplicityButton), returnTypeObservable, startegy, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); }
Example 18
Source File: ScriptExpressionEditor.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void bindExpression(final EMFDataBindingContext dataBindingContext, final EObject context, final Expression inputExpression, final ViewerFilter[] filters, final ExpressionViewer viewer) { this.inputExpression = inputExpression; final IObservableValue nameModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME); final UpdateValueStrategy opposite = new UpdateValueStrategy(); opposite.setConverter(new BooleanInverserConverter()); IObservableValue nameTextObservable = SWTObservables.observeText(expressionNameText, SWT.Modify); final UpdateValueStrategy targetToModel = new UpdateValueStrategy(); targetToModel.setAfterConvertValidator(new EmptyInputValidator(Messages.name)); bindValue = dataBindingContext.bindValue(nameTextObservable, nameModelObservable, targetToModel, null); nameTextObservable.addValueChangeListener(handleValidationStatusChanged()); nameModelObservable.addValueChangeListener(event -> fireSelectionChanged()); editor.bindExpression(dataBindingContext, context, inputExpression, filters, viewer); if (inputExpression.getReturnType() != null) { typeCombo.setInput(inputExpression.getReturnType()); } else { typeCombo.setInput(new Object()); } returnTypeModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); final String defaultReturnType = viewer.getDefaultReturnType(); if (defaultReturnType != null && !inputExpression.isReturnTypeFixed() && shouldChangeReturnType(inputExpression.getReturnType(), defaultReturnType)) { returnTypeModelObservable.setValue(defaultReturnType); } dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(typeCombo), returnTypeModelObservable); dataBindingContext.bindValue(SWTObservables.observeText(typeCombo.getCombo()), returnTypeModelObservable, updateValueStrategy().withConverter(ConverterBuilder.<String, String> newConverter() .withConvertFunction(this::toClassName) .create()) .create(), updateValueStrategy().withConverter(ConverterBuilder.<String, String> newConverter() .withConvertFunction(this::toDisplayName) .create()) .create()); typeCombo.getCombo().setEnabled(!inputExpression.isReturnTypeFixed()); browseClassesButton.setEnabled(!inputExpression.isReturnTypeFixed()); }
Example 19
Source File: CronEditor.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected void createDailyTab(TabFolder tablFolder) { final TabItem item = new TabItem(tablFolder, SWT.NONE); item.setText(Messages.daily); final Composite dailyContent = new Composite(tablFolder, SWT.NONE); dailyContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); dailyContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).create()); final Button everyRadio = new Button(dailyContent, SWT.RADIO); everyRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); everyRadio.setText(Messages.every); context.bindValue(SWTObservables.observeSelection(everyRadio), PojoProperties.value("useEveryDayForDaily").observe(cronExpression)); final Composite everyComposite = new Composite(dailyContent, SWT.NONE); everyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(-65, 0).create()); everyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); final Text dayText = new Text(everyComposite, SWT.BORDER | SWT.SINGLE); dayText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create()); UpdateValueStrategy dayFrequencyStrategy = new UpdateValueStrategy(); dayFrequencyStrategy.setAfterGetValidator(dotValidator); dayFrequencyStrategy.setConverter(StringToNumberConverter.toInteger(true)); dayFrequencyStrategy.setBeforeSetValidator(new FrequencyValidator()); context.bindValue(SWTObservables.observeText(dayText, SWT.Modify), PojoProperties.value("dayFrequencyForDaily").observe(cronExpression), dayFrequencyStrategy, null); final Label dayLabel = new Label(everyComposite, SWT.NONE); dayLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); dayLabel.setText(Messages.dayLabel); final Button everyWeekDayRadio = new Button(dailyContent, SWT.RADIO); everyWeekDayRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); everyWeekDayRadio.setText(Messages.everyWeekDay); final Label filler = new Label(dailyContent, SWT.NONE); filler.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); final IObservableValue hourObservable = PojoProperties.value("atHourInDay").observe(cronExpression); final IObservableValue minuteObservable = PojoProperties.value("atMinuteInDay").observe(cronExpression); final IObservableValue secondObservable = PojoProperties.value("atSecondInDay").observe(cronExpression); createStartTimeComposite(dailyContent, hourObservable, minuteObservable, secondObservable); item.setControl(dailyContent); }
Example 20
Source File: EssentialsPage.java From thym with Eclipse Public License 1.0 | 4 votes |
private void bindAuthor(DataBindingContext bindingContext) { // final WritableValue value = new WritableValue(); if (getWidget() != null) { Author author = getWidget().getAuthor(); if (author == null) { value.setValue(new DummyAuthor()); } else { value.setValue(author); } authorListener = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { value.getRealm().exec(new Runnable() { @Override public void run() { if (evt.getNewValue() == null) { value.setValue(new DummyAuthor()); } else { value.setValue(evt.getNewValue()); } } }); } }; getWidget().addPropertyChangeListener("author", authorListener); } // IObservableValue observeTextTxtAuthornameObserveWidget = WidgetProperties.text(SWT.Modify) .observe(txtAuthorname); IObservableValue authornameGetWidgetObserveValue = BeanProperties.value("name").observeDetail(value); UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setConverter(new StringToDisplayableStringConverter()); bindingContext.bindValue(observeTextTxtAuthornameObserveWidget, authornameGetWidgetObserveValue, null, strategy); // IObservableValue observeTextTxtEmailObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtEmail); IObservableValue authoremailGetWidgetObserveValue = BeanProperties.value("email").observeDetail(value); bindingContext.bindValue(observeTextTxtEmailObserveWidget, authoremailGetWidgetObserveValue, null, null); // IObservableValue observeTextTxtUrlObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtUrl); IObservableValue authorhrefGetWidgetObserveValue = BeanProperties.value("href").observeDetail(value); bindingContext.bindValue(observeTextTxtUrlObserveWidget, authorhrefGetWidgetObserveValue, null, null); }