List of usage examples for org.eclipse.jface.databinding.swt.typed WidgetProperties enabled
public static <S extends Widget> IWidgetValueProperty<S, Boolean> enabled()
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet019TreeViewerWithListFactory.java
License:Open Source License
private void initExtraBindings(DataBindingContext dbc) { final IObservableValue<Bean> beanViewerSelection = ViewerProperties.singleSelection(Bean.class) .observe(beanViewer);/* ww w. j av a 2 s . co m*/ IObservableValue<Boolean> beanSelected = ComputedValue.create(() -> beanViewerSelection.getValue() != null); dbc.bindValue(WidgetProperties.enabled().observe(addChildBeanButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(removeBeanButton), beanSelected); clipboard = new WritableValue<>(); dbc.bindValue(WidgetProperties.enabled().observe(copyButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(pasteButton), ComputedValue.create(() -> clipboard.getValue() != null)); ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", Bean.class), BeanProperties.value(Bean.class, "text")); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet020TreeViewerWithSetFactory.java
License:Open Source License
private void initExtraBindings(DataBindingContext dbc) { final IObservableValue<Bean> beanViewerSelection = ViewerProperties.singleSelection(Bean.class) .observe(beanViewer);//from w w w. j a va 2 s. co m IObservableValue<Boolean> beanSelected = ComputedValue.create(() -> beanViewerSelection.getValue() != null); dbc.bindValue(WidgetProperties.enabled().observe(addChildBeanButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(removeBeanButton), beanSelected); clipboard = new WritableValue<>(); dbc.bindValue(WidgetProperties.enabled().observe(copyButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(pasteButton), ComputedValue.create(() -> clipboard.getValue() != null)); ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", Bean.class), BeanProperties.value(Bean.class, "text")); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet026AnonymousBeanProperties.java
License:Open Source License
private void bindUI() { ISetProperty<Object, Object> treeChildrenProperty = new DelegatingSetProperty<Object, Object>() { ISetProperty<ApplicationModel, ContactGroup> modelGroups = BeanProperties.set(ApplicationModel.class, "groups", ContactGroup.class); ISetProperty<ContactGroup, Contact> groupContacts = BeanProperties.set(ContactGroup.class, "contacts", Contact.class); @SuppressWarnings("unchecked") @Override// w w w.j a va 2s. c om protected ISetProperty<Object, Object> doGetDelegate(Object source) { if (source instanceof ApplicationModel) return (ISetProperty<Object, Object>) (Object) modelGroups; if (source instanceof ContactGroup) return (ISetProperty<Object, Object>) (Object) groupContacts; return null; } }; ViewerSupport.bind(contactViewer, model, treeChildrenProperty, BeanProperties.values("name", "status")); contactViewer.expandAll(); final IObservableValue<Object> selection = ViewerProperties.singleSelection().observe(contactViewer); DataBindingContext dbc = new DataBindingContext(); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText), BeanProperties.value("name").observeDetail(selection)); statusViewer.setContentProvider(new ArrayContentProvider()); statusViewer.setInput(statuses); dbc.bindValue(ViewerProperties.singleSelection().observe(statusViewer), BeanProperties.value("status").observeDetail(selection)); dbc.bindValue(WidgetProperties.enabled().observe(statusViewer.getControl()), ComputedValue.create(() -> selection.getValue() instanceof Contact)); }
From source file:org.eclipse.n4js.ui.wizard.classifiers.N4JSNewClassifierWizardPage.java
License:Open Source License
/** * Setup additional non-component contained bindings *//*www .j ava 2 s .co m*/ protected void setupBindings() { DataBindingContext dataBindingContext = this.getDataBindingContext(); IObservableValue<String> moduleSpecifierValue = BeanProperties .value(WorkspaceWizardModel.class, WorkspaceWizardModel.MODULE_SPECIFIER_PROPERTY, String.class) .observe(getModel()); IObservableValue<Boolean> suffixVisibilityValue = BeanProperties .value(SuffixText.class, SuffixText.SUFFIX_VISIBILITY_PROPERTY, Boolean.class) .observe(workspaceWizardControl.getModuleSpecifierText()); //// Only show the suffix on input values ending with a '/' character or empty module specifiers. dataBindingContext.bindValue(suffixVisibilityValue, moduleSpecifierValue, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(m -> { String moduleSpecifier = (String) m; return (moduleSpecifier.isEmpty() || moduleSpecifier.charAt(moduleSpecifier.length() - 1) == IPath.SEPARATOR); })); //// interface name to module specifier suffix binding IObservableValue<String> interfaceNameModelValue = BeanProperties .value(N4JSClassifierWizardModel.class, N4JSClassifierWizardModel.NAME_PROPERTY, String.class) .observe(getModel()); IObservableValue<String> greySuffixValue = BeanProperties .value(SuffixText.class, SuffixText.SUFFIX_PROPERTY, String.class) .observe(workspaceWizardControl.getModuleSpecifierText()); dataBindingContext.bindValue(greySuffixValue, interfaceNameModelValue, noUpdateValueStrategy(), new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_UPDATE)); //// Enable n4js <-> Definition value(external) is selected IObservableValue<Boolean> externalValue = BeanProperties .value(DefinitionFileModel.class, N4JSClassifierWizardModel.DEFINITION_FILE_PROPERTY, Boolean.class) .observe((DefinitionFileModel) getModel()); IObservableValue<Boolean> n4jsEnabled = WidgetProperties.enabled() .observe(otherClassifierModifiersComponent.getN4jsAnnotationBox()); dataBindingContext.bindValue(n4jsEnabled, externalValue, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(input -> getModel().isDefinitionFile() && AccessModifier.PRIVATE != getModel().getAccessModifier())); // One way binding of the access modifiers to the enabled state of internal checkbox IObservableValue<Boolean> internalEnabledValue = WidgetProperties.enabled() .observe(accessModifierComponent.getInternalAnnotationBox()); IObservableValue<AccessModifier> accessModifierSelectObservable = BeanProperties .value(N4JSClassifierWizardModel.class, N4JSClassifierWizardModel.ACCESS_MODIFIER_PROPERTY, AccessModifier.class) .observe(getModel()); dataBindingContext.bindValue(internalEnabledValue, accessModifierSelectObservable, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(object -> { if (object instanceof AccessModifier) { return isInternalAccessModifierEnabled((AccessModifier) object); } return false; })); // N4JS annotation checkbox disabled when access modifier is private IObservableValue<Boolean> n4jsEnabledValue = WidgetProperties.enabled() .observe(otherClassifierModifiersComponent.getN4jsAnnotationBox()); dataBindingContext.bindValue(n4jsEnabledValue, accessModifierSelectObservable, noUpdateValueStrategy(), WizardComponentDataConverters.strategyForPredicate(object -> { if (object instanceof AccessModifier) { return ((AccessModifier) object != AccessModifier.PRIVATE) && getModel().isDefinitionFile(); } return false; })); // Refresh wizard state on validation change IObservableValue<ValidationResult> observableValidationValue = BeanProperties .value(WorkspaceWizardModelValidator.VALIDATION_RESULT, ValidationResult.class) .observe(getValidator()); observableValidationValue.addValueChangeListener(new IValueChangeListener<ValidationResult>() { @Override public void handleValueChange(ValueChangeEvent<? extends ValidationResult> event) { onValidationChange(event.diff.getNewValue()); } }); }
From source file:org.eclipse.n4js.ui.wizard.workspace.WorkspaceWizardPage.java
License:Open Source License
private void setupBindings(WorkspaceWizardPageForm wizardForm) { databindingContext = new DataBindingContext(); WorkspaceWizardModelValidator<M> validator = getValidator(); // Project property binding IObservableValue<IPath> projectModelValue = BeanProperties .value(WorkspaceWizardModel.class, WorkspaceWizardModel.PROJECT_PROPERTY, IPath.class) .observe(model);//from ww w . j av a2s . c om IObservableValue<String> projectUI = WidgetProperties.text(SWT.Modify).observe(wizardForm.getProjectText()); // Note: No model to UI conversation here as IPath is castable to String (default behavior) databindingContext.bindValue(projectUI, projectModelValue, new StringToPathConverter().updatingValueStrategy(), new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_UPDATE)); // Source folder property binding IObservableValue<IPath> sourceFolderModelValue = BeanProperties .value(WorkspaceWizardModel.class, WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY, IPath.class) .observe(model); IObservableValue<String> sourceFolderUI = WidgetProperties.text(SWT.Modify) .observe(wizardForm.getSourceFolderText()); // Note: No model to UI conversation (see above) databindingContext.bindValue(sourceFolderUI, sourceFolderModelValue, new StringToPathConverter().updatingValueStrategy(), new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_UPDATE)); IObservableValue<Boolean> projectValidModelValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.PROJECT_PROPERTY_VALID, Boolean.class).observe(validator); IObservableValue<Boolean> sourceFolderBrowseEnabled = WidgetProperties.enabled() .observe(wizardForm.getSourceFolderBrowseButton()); databindingContext.bindValue(sourceFolderBrowseEnabled, projectValidModelValue, new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_UPDATE)); // Module specifier property binding IObservableValue<String> moduleSpecifierModelValue = BeanProperties .value(WorkspaceWizardModel.class, WorkspaceWizardModel.MODULE_SPECIFIER_PROPERTY, String.class) .observe(model); IObservableValue<String> moduleSpecifierUI = BeanProperties .value(SuffixText.class, SuffixText.TEXT_PROPERTY, String.class) .observe(wizardForm.getModuleSpecifierText()); databindingContext.bindValue(moduleSpecifierUI, moduleSpecifierModelValue); // Conditional activation of the browse buttons according to the precedent input fields validity IObservableValue<Boolean> moduleSpecifierBrowseEnabled = WidgetProperties.enabled() .observe(wizardForm.getModuleSpecifierBrowseButton()); IObservableValue<Boolean> sourceFolderValidValue = BeanProperties .value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.SOURCE_FOLDER_PROPERTY_VALID, Boolean.class) .observe(validator); IObservableValue<Boolean> projectValidValue = BeanProperties.value(WorkspaceWizardModelValidator.class, WorkspaceWizardModelValidator.PROJECT_PROPERTY_VALID, Boolean.class).observe(validator); ConditionalConverter moduleSpecifierBrowseableConverter = new ConditionalConverter() { @Override public boolean validate(Object object) { return validator.getSourceFolderValid() && validator.getProjectValid(); } }; // Bind model changes of project or source folder property to the enabled state of the module specifier browse // button. databindingContext.bindValue(moduleSpecifierBrowseEnabled, projectValidValue, new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_NEVER), moduleSpecifierBrowseableConverter.updatingValueStrategy()); databindingContext.bindValue(moduleSpecifierBrowseEnabled, sourceFolderValidValue, new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_NEVER), moduleSpecifierBrowseableConverter.updatingValueStrategy()); }