List of usage examples for org.eclipse.jface.databinding.fieldassist ControlDecorationSupport create
public static ControlDecorationSupport create(ValidationStatusProvider validationStatusProvider, int position)
From source file:com.amitinside.e4.rcp.todo.parts.EMFTodoDetailsPart.java
License:Apache License
private void updateUserInterface(Todo todo) { if (todo == null) { enableUserInterface(false);/*from w w w . ja va2 s. co m*/ return; } else { enableUserInterface(true); } if (txtSummary != null && !txtSummary.isDisposed()) { IObservableList providers = ctx.getValidationStatusProviders(); for (final Object o : providers) { final Binding b = (Binding) o; b.getTarget().removeChangeListener(listener); } ctx.dispose(); IObservableValue target = WidgetProperties.text(SWT.Modify).observe(txtSummary); IObservableValue model = EMFProperties.value(TodoPackage.Literals.TODO__SUMMARY).observe(todo); ctx.bindValue(target, model); target = WidgetProperties.selection().observe(btnDone); model = EMFProperties.value(TodoPackage.Literals.TODO__DONE).observe(todo); ctx.bindValue(target, model); target = WidgetProperties.text(SWT.Modify).observe(txtNote); model = EMFProperties.value(TodoPackage.Literals.TODO__NOTE).observe(todo); final IConverter converter = new IConverter() { @Override public Object getToType() { return null; } @Override public Object getFromType() { return null; } @Override public Object convert(Object elem) { System.out.println(">>>>>" + elem); return elem.toString().charAt(0); } }; final IValidator validator = new IValidator() { @Override public IStatus validate(Object value) { if (value instanceof String) { if (((String) value).matches(messages.TodoDetailsPart_5)) { flagBeforeSave = true; return ValidationStatus.OK_STATUS; } else flagBeforeSave = false; } return ValidationStatus.error(messages.TodoDetailsPart_6); } }; final UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(validator); strategy.setConverter(converter); final Binding bindvalue = ctx.bindValue(target, model, strategy, null); ControlDecorationSupport.create(bindvalue, SWT.TOP | SWT.LEFT); final IObservableValue observeSelectionDateTimeObserveWidget = WidgetProperties.selection() .observe(dateTime); final IObservableValue dueDateTodoObserveValue = EMFProperties .value(TodoPackage.Literals.TODO__DUE_DATE).observe(todo); ctx.bindValue(observeSelectionDateTimeObserveWidget, dueDateTodoObserveValue); providers = ctx.getValidationStatusProviders(); for (final Object o : providers) { final Binding b = (Binding) o; b.getTarget().addChangeListener(listener); } } }
From source file:com.amitinside.e4.rcp.todo.parts.TodoDetailsPart.java
License:Apache License
private void updateUserInterface(Todo todo) { // check if Todo is null if (todo == null) { enableUserInterface(false);/*from w w w . j a v a2 s.c om*/ return; } else { enableUserInterface(true); } // Check if the user interface is available // assume you have a field called "summary" // for a widget if (txtSummary != null && !txtSummary.isDisposed()) { // Deregister change listener to the old binding IObservableList providers = ctx.getValidationStatusProviders(); for (final Object o : providers) { final Binding b = (Binding) o; b.getTarget().removeChangeListener(listener); } // Remove bindings ctx.dispose(); IObservableValue target = WidgetProperties.text(SWT.Modify).observe(txtSummary); IObservableValue model = BeanProperties.value(Todo.FIELD_SUMMARY).observe(todo); ctx.bindValue(target, model); target = WidgetProperties.selection().observe(btnDone); model = BeanProperties.value(Todo.FIELD_DONE).observe(todo); ctx.bindValue(target, model); target = WidgetProperties.selection().observe(btnDone); model = BeanProperties.value(Todo.FIELD_DONE).observe(todo); ctx.bindValue(target, model); target = WidgetProperties.text(SWT.Modify).observe(txtNote); model = BeanProperties.value(Todo.FIELD_NOTE).observe(todo); final IValidator validator = new IValidator() { @Override public IStatus validate(Object value) { if (value instanceof String) { if (((String) value).matches(messages.TodoDetailsPart_5)) { return ValidationStatus.OK_STATUS; } } return ValidationStatus.error(messages.TodoDetailsPart_6); } }; final UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(validator); final Binding bindvalue = ctx.bindValue(target, model, strategy, null); ControlDecorationSupport.create(bindvalue, SWT.TOP | SWT.LEFT); final IObservableValue observeSelectionDateTimeObserveWidget = WidgetProperties.selection() .observe(dateTime); final IObservableValue dueDateTodoObserveValue = BeanProperties.value(Todo.FIELD_DUEDATE).observe(todo); ctx.bindValue(observeSelectionDateTimeObserveWidget, dueDateTodoObserveValue); // register listener for any changes providers = ctx.getValidationStatusProviders(); for (final Object o : providers) { final Binding b = (Binding) o; b.getTarget().addChangeListener(listener); } // Register for the changes providers = ctx.getValidationStatusProviders(); for (final Object o : providers) { final Binding b = (Binding) o; b.getTarget().addChangeListener(listener); } } }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.emf.EObjectUIHelper.java
License:Open Source License
/** * Sets up the data binding.//from w ww. j a v a 2 s . com * @param eObject * @param domain * @param dbc * @param entries */ private static void setUpDatabinding(EObject eObject, EditingDomain domain, DataBindingContext dbc, boolean showDecorator, List<EntryDescription> entries) { for (EntryDescription entry : entries) { IObservableValue widgetObservable = null; if (entry.widget instanceof Text) widgetObservable = SWTObservables.observeDelayedValue(300, SWTObservables.observeText((Text) entry.widget, SWT.Modify)); else if (entry.widget instanceof StyledText) widgetObservable = SWTObservables.observeDelayedValue(300, SWTObservables.observeText((StyledText) entry.widget, SWT.Modify)); else if (entry.widget instanceof Spinner) widgetObservable = SWTObservables.observeSelection((Spinner) entry.widget); else if (entry.widget instanceof ISelectionProvider) widgetObservable = ViewersObservables.observeSingleSelection((ISelectionProvider) entry.widget); else if (entry.widget instanceof Button) widgetObservable = SWTObservables.observeSelection((Button) entry.widget); if (widgetObservable != null) { UpdateValueStrategy targetToModel = new UpdateValueStrategy(); if (entry.attribute.getLowerBound() > 0) targetToModel.setBeforeSetValidator(new MandatoryFieldValidator(entry.attribute)); IObservableValue iov = domain == null ? EMFObservables.observeValue(eObject, entry.attribute) // : EMFEditObservables.observeValue( domain, eObject, entry.attribute ); : createCustomEmfEditObservable(domain, eObject, entry.attribute); Binding binding; if (domain == null) binding = dbc.bindValue(widgetObservable, iov, targetToModel, null); else binding = dbc.bindValue(widgetObservable, iov); if (showDecorator && entry.attribute.getLowerBound() > 0) ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT); } } }
From source file:com.nextep.designer.dbgm.ui.editors.CheckConstraintFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider()); // Binding name IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText); IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "name", //$NON-NLS-1$ String.class); UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false)); Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT); // Binding description widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descriptionText); modelValue = PojoObservables.observeDetailValue(selectionValue, "description", String.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue, null, null); // Binding check condition widgetValue = WidgetProperties.text(SWT.FocusOut).observe(conditionText); modelValue = PojoObservables.observeDetailValue(selectionValue, "condition", String.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue, null, null); }
From source file:com.nextep.designer.dbgm.ui.editors.ColumnFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider()); IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText); IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "name", //$NON-NLS-1$ String.class); UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); // UpdateValueStrategy.POLICY_CONVERT); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false)); Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); fieldDecorators.add(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT)); // Binding description widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText); modelValue = PojoObservables.observeDetailValue(selectionValue, "description", String.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue); // Binding datatype widgetValue = WidgetProperties.selection().observe(datatypeCombo); modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.name", //$NON-NLS-1$ String.class); boundValue = context.bindValue(widgetValue, modelValue); final IValidator integerValidator = ValidatorFactory.createIntegerValidator(); // Binding length widgetValue = WidgetProperties.text(SWT.FocusOut).observe(lengthText); modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.length", //$NON-NLS-1$ int.class); targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterGetValidator(integerValidator); targetModelStrategy.setConverter(ConverterFactory.createToIntegerConverter(true, true)); UpdateValueStrategy modelTargetStrategy = new UpdateValueStrategy(); modelTargetStrategy.setAfterGetValidator(integerValidator); modelTargetStrategy.setConverter(ConverterFactory.createFromIntegerConverter(true, true)); boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy); fieldDecorators.add(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT)); // Binding length type widgetValue = WidgetProperties.selection().observe(lengthTypeCombo); modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.lengthType", //$NON-NLS-1$ String.class); targetModelStrategy = new UpdateValueStrategy() .setConverter(ConverterFactory.createLengthTypeModelConverter()); modelTargetStrategy = new UpdateValueStrategy() .setConverter(ConverterFactory.createLengthTypeTargetConverter()); boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy); // Binding precision widgetValue = WidgetProperties.text(SWT.FocusOut).observe(precisionText); modelValue = PojoObservables.observeDetailValue(selectionValue, "datatype.precision", //$NON-NLS-1$ int.class); targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterGetValidator(integerValidator); targetModelStrategy.setConverter(ConverterFactory.createToIntegerConverter(true, true)); modelTargetStrategy = new UpdateValueStrategy(); modelTargetStrategy.setAfterGetValidator(integerValidator); modelTargetStrategy.setConverter(ConverterFactory.createFromIntegerConverter(true, true)); boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy); fieldDecorators.add(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT)); // Binding not null widgetValue = WidgetProperties.selection().observe(notNullButton); modelValue = PojoObservables.observeDetailValue(selectionValue, "notNull", boolean.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue); // Binding virtual widgetValue = WidgetProperties.selection().observe(virtualButton); modelValue = PojoObservables.observeDetailValue(selectionValue, "virtual", boolean.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue); // Binding default widgetValue = WidgetProperties.text(SWT.FocusOut).observe(defaultText); modelValue = PojoObservables.observeDetailValue(selectionValue, "defaultExpr", String.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue); }
From source file:com.nextep.designer.dbgm.ui.editors.ForeignKeyFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider()); // Binding name IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText); IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "name", //$NON-NLS-1$ String.class); UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false)); Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT); // Binding description widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText); modelValue = PojoObservables.observeDetailValue(selectionValue, "description", String.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue, null, null); // Binding on update action widgetValue = WidgetProperties.text().observe(onUpdateCombo); modelValue = PojoObservables.observeDetailValue(selectionValue, "onUpdateAction", //$NON-NLS-1$ ForeignKeyAction.class); UpdateValueStrategy modelUpdateStrategy = new UpdateValueStrategy(); modelUpdateStrategy.setConverter(ConverterFactory.createForeignKeyActionModelConverter()); UpdateValueStrategy targetUpdateStrategy = new UpdateValueStrategy(); targetUpdateStrategy.setConverter(ConverterFactory.createForeignKeyActionTargetConverter()); boundValue = context.bindValue(widgetValue, modelValue, modelUpdateStrategy, targetUpdateStrategy); // Binding on delete action widgetValue = WidgetProperties.text().observe(onDeleteCombo); modelValue = PojoObservables.observeDetailValue(selectionValue, "onDeleteAction", //$NON-NLS-1$ ForeignKeyAction.class); modelUpdateStrategy = new UpdateValueStrategy(); modelUpdateStrategy.setConverter(ConverterFactory.createForeignKeyActionModelConverter()); targetUpdateStrategy = new UpdateValueStrategy(); targetUpdateStrategy.setConverter(ConverterFactory.createForeignKeyActionTargetConverter()); boundValue = context.bindValue(widgetValue, modelValue, modelUpdateStrategy, targetUpdateStrategy); }
From source file:com.nextep.designer.dbgm.ui.editors.IndexFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { // IObservableValue selectionValue = ViewersObservables // .observeSingleSelection(getSelectionProvider()); final IIndex index = getModel(); // Binding name IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText); IObservableValue modelValue = PojoProperties.value(IIndex.class, "indexName", String.class) //$NON-NLS-1$ .observe(index);/*from w w w . java2 s .c o m*/ // Observables.value(observeDetailValue(selectionValue, // "indexName", String.class); //$NON-NLS-1$ UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false)); Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT); // Binding description widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText); modelValue = PojoProperties.value(IIndex.class, "description", String.class).observe(index); //$NON-NLS-1$ // Observables // .observeDetailValue(selectionValue, "description", String.class); //$NON-NLS-1$ boundValue = context.bindValue(widgetValue, modelValue, null, null); // Binding index type widgetValue = WidgetProperties.text().observe(indexTypeCombo); modelValue = PojoProperties.value(IIndex.class, "indexType", IndexType.class) //$NON-NLS-1$ .observe(index); // Observables.observeDetailValue(selectionValue, "indexType", //$NON-NLS-1$ // IndexType.class); targetModelStrategy = new UpdateValueStrategy().setConverter(new IConverter() { @Override public Object getToType() { return IndexType.class; } @Override public Object getFromType() { return String.class; } @Override public Object convert(Object fromObject) { final String s = ((String) fromObject).replace(' ', '_').toUpperCase(); return IndexType.valueOf(s); } }); UpdateValueStrategy modelTargetStrategy = new UpdateValueStrategy().setConverter(new IConverter() { @Override public Object getToType() { return String.class; } @Override public Object getFromType() { return IndexType.class; } @Override public Object convert(Object fromObject) { final IndexType type = (IndexType) fromObject; return IFormatter.PROPPER_LOWER.format(type.name()).replace('_', ' '); } }); boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, modelTargetStrategy); }
From source file:com.nextep.designer.dbgm.ui.editors.PartitionsFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider()); // Binding name IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText); IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "name", String.class); //$NON-NLS-1$ UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false)); Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT); }
From source file:com.nextep.designer.dbgm.ui.editors.TableFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { final IBasicTable table = getModel(); // Name binding IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(nameText); IObservableValue modelValue = PojoProperties.value(IBasicTable.class, "name") //$NON-NLS-1$ .observe(table);//from w w w . java 2s . com UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(false)); Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); registerControlDecoration(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT)); // Short name binding widgetValue = WidgetProperties.text(SWT.FocusOut).observe(shortNameText); modelValue = PojoProperties.value(IBasicTable.class, "shortName").observe(table); //$NON-NLS-1$ targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNameValidator(true)); boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); registerControlDecoration(ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT)); // Description binding widgetValue = WidgetProperties.text(SWT.FocusOut).observe(descText); modelValue = PojoProperties.value(IBasicTable.class, "description").observe(table); //$NON-NLS-1$ targetModelStrategy = new UpdateValueStrategy(); boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); // Binding temporary widgetValue = WidgetProperties.selection().observe(temporaryCheck); modelValue = PojoProperties.value(IBasicTable.class, "temporary", boolean.class).observe( //$NON-NLS-1$ table); boundValue = context.bindValue(widgetValue, modelValue); }
From source file:com.nextep.designer.dbgm.ui.editors.TablePartitionFormEditor.java
License:Open Source License
@Override protected void doBindModel(DataBindingContext context) { IObservableValue selectionValue = ViewersObservables.observeSingleSelection(getSelectionProvider()); // Binding name IObservableValue widgetValue = WidgetProperties.text(SWT.FocusOut).observe(highValueText); IObservableValue modelValue = PojoObservables.observeDetailValue(selectionValue, "highValue", String.class); //$NON-NLS-1$ UpdateValueStrategy targetModelStrategy = new UpdateValueStrategy(); targetModelStrategy.setAfterConvertValidator(ValidatorFactory.createNotEmptyValidator("HIGH VALUE", false)); //$NON-NLS-1$ Binding boundValue = context.bindValue(widgetValue, modelValue, targetModelStrategy, null); ControlDecorationSupport.create(boundValue, SWT.TOP | SWT.LEFT); }