List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeEnabled
@Deprecated public static ISWTObservableValue observeEnabled(Control control)
From source file:org.bonitasoft.studio.simulation.properties.contributions.LoadProfileContribution.java
License:Open Source License
public void createControl(final Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, ExtensibleGridPropertySection extensibleGridPropertySection) { composite.setLayout(new GridLayout(3, false)); cCombo = widgetFactory.createCCombo(composite, SWT.BORDER); cCombo.setLayoutData(GridDataFactory.swtDefaults().hint(200, SWT.DEFAULT).create()); final SimulationLoadProfileRepositoryStore profileStore = RepositoryManager.getInstance() .getRepositoryStore(SimulationLoadProfileRepositoryStore.class); for (IRepositoryFileStore artifact : profileStore.getChildren()) { cCombo.add(artifact.getDisplayName()); }// w ww . j ava2 s . co m cCombo.setEditable(false); Button editLoadProfile = new Button(composite, SWT.FLAT); editLoadProfile.setText(Messages.edit); editLoadProfile.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { EditSimulationLoadProfileWizard wizard = new EditSimulationLoadProfileWizard(profileStore.getChild( cCombo.getText() + "." + SimulationLoadProfileRepositoryStore.SIMULATION_LOADPROFILE_EXT)); new CustomWizardDialog(Display.getCurrent().getActiveShell(), wizard).open(); } }); Button createLoadProfile = new Button(composite, SWT.FLAT); createLoadProfile.setText(Messages.create); createLoadProfile.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { EditSimulationLoadProfileWizard wizard = new EditSimulationLoadProfileWizard(); if (new CustomWizardDialog(Display.getCurrent().getActiveShell(), wizard) .open() == IDialogConstants.OK_ID) { String id = wizard.getArtifact().getDisplayName(); cCombo.add(id); cCombo.setText(id); } } }); context = new EMFDataBindingContext(); context.bindValue(SWTObservables.observeText(cCombo), EMFEditObservables.observeValue(editingDomain, eObject, SimulationPackage.Literals.SIMULATION_ABSTRACT_PROCESS__LOAD_PROFILE_ID)); context.bindValue(SWTObservables.observeEnabled(editLoadProfile), SWTObservables.observeText(cCombo), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(new Converter(String.class, Boolean.class) { public Object convert(Object fromObject) { return ((String) fromObject).length() > 0; } })); }
From source file:org.bonitasoft.studio.xml.ui.XPathExpressionEditor.java
License:Open Source License
@Override public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context, Expression inputExpression, ViewerFilter[] filters, ExpressionViewer expressionViewer) { editorInputExpression = inputExpression; Set<Data> input = new HashSet<Data>(); IExpressionProvider provider = ExpressionEditorService.getInstance() .getExpressionProvider(ExpressionConstants.VARIABLE_TYPE); for (Expression e : provider.getExpressions(context)) { EObject data = e.getReferencedElements().get(0); if (data instanceof XMLData) { input.add((XMLData) data);//from w w w .j a v a 2s . c om } } viewer.setInput(input); IObservableValue nameObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME); IObservableValue contentObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT); final IObservableValue returnTypeObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); IObservableValue referenceObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS); UpdateValueStrategy selectionToName = new UpdateValueStrategy(); IConverter nameConverter = new Converter(String.class, String.class) { @Override public Object convert(Object data) { if (data instanceof Data) { XMLData xmlData = (XMLData) data; return xmlData.getName() + " - " + editorInputExpression.getContent(); } else if (data instanceof String) { final XMLData xmlData = (XMLData) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); return xmlData.getName() + " - " + data; } return null; } }; selectionToName.setConverter(nameConverter); UpdateValueStrategy selectionToContent = new UpdateValueStrategy(); IConverter contentConverter = new Converter(Object.class, String.class) { @Override public Object convert(Object value) { if (!xsdViewer.getSelection().isEmpty()) { return computeXPath((ITreeSelection) xsdViewer.getSelection()); } Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection instanceof Data) { return ((Data) selection).getName(); } return null; } }; selectionToContent.setConverter(contentConverter); UpdateValueStrategy contentToSelection = new UpdateValueStrategy(); IConverter methodToSelectionConverter = new Converter(String.class, Object.class) { @Override public Object convert(Object xPathExpression) { if (xPathExpression instanceof String) { ITreeSelection selection = new org.eclipse.jface.viewers.TreeSelection(createTreePath( (String) xPathExpression, (XSDContentProvider) xsdViewer.getContentProvider())); return selection.getFirstElement(); } return null; } }; contentToSelection.setConverter(methodToSelectionConverter); UpdateValueStrategy selectionToReturnType = new UpdateValueStrategy(); selectionToReturnType.setConverter(new Converter(Object.class, String.class) { @Override public Object convert(Object element) { if (editorInputExpression.isReturnTypeFixed()) { return returnTypeObservable.getValue(); } else { return XPathReturnType.getType(element); } } }); UpdateValueStrategy selectionToReferencedData = new UpdateValueStrategy(); IConverter referenceConverter = new Converter(Data.class, List.class) { @Override public Object convert(Object data) { if (data != null) { XMLData xmlData = (XMLData) data; dataName = xmlData.getName(); String namespace = xmlData.getNamespace(); String element = xmlData.getType(); XSDRepositoryStore xsdStore = (XSDRepositoryStore) RepositoryManager.getInstance() .getRepositoryStore(XSDRepositoryStore.class); XSDElementDeclaration root = xsdStore.findElementDeclaration(namespace, element); XSDElementDeclaration existingElement = ((XSDContentProvider) xsdViewer.getContentProvider()) .getElement(); if (existingElement == null || !existingElement.equals(root)) { ((XSDContentProvider) xsdViewer.getContentProvider()).setElement(root); } return Collections.singletonList(data); } else { return Collections.emptyList(); } } }; selectionToReferencedData.setConverter(referenceConverter); UpdateValueStrategy referencedDataToSelection = new UpdateValueStrategy(); IConverter referencetoDataConverter = new Converter(List.class, Data.class) { @Override public Object convert(Object dataList) { Data d = ((List<Data>) dataList).get(0); Collection<Data> inputData = (Collection<Data>) viewer.getInput(); for (Data data : inputData) { if (data.getName().equals(d.getName()) && data.getDataType().getName().equals(d.getDataType().getName())) { XMLData xmlData = (XMLData) data; dataName = xmlData.getName(); String namespace = xmlData.getNamespace(); String element = xmlData.getType(); XSDRepositoryStore xsdStore = (XSDRepositoryStore) RepositoryManager.getInstance() .getRepositoryStore(XSDRepositoryStore.class); XSDElementDeclaration root = xsdStore.findElementDeclaration(namespace, element); ((XSDContentProvider) xsdViewer.getContentProvider()).setElement(root); return data; } } return null; } }; referencedDataToSelection.setConverter(referencetoDataConverter); UpdateValueStrategy enableStrategy = new UpdateValueStrategy(); enableStrategy.setConverter(new Converter(Object.class, Boolean.class) { @Override public Object convert(Object fromObject) { return fromObject != null; } }); dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(viewer), referenceObservable, selectionToReferencedData, referencedDataToSelection); dataBindingContext.bindValue(SWTObservables.observeText(text, SWT.Modify), nameObservable, selectionToName, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue(SWTObservables.observeEnabled(xsdViewer.getTree()), ViewersObservables.observeSingleSelection(viewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableStrategy); dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(xsdViewer), contentObservable, selectionToContent, contentToSelection); dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(xsdViewer), returnTypeObservable, selectionToReturnType, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(typeCombo), returnTypeObservable); }
From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet019TreeViewerWithListFactory.java
License:Open Source License
private void initExtraBindings(DataBindingContext dbc) { final IObservableValue beanViewerSelection = ViewersObservables.observeSingleSelection(beanViewer); IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) { protected Object calculate() { return Boolean.valueOf(beanViewerSelection.getValue() != null); }/*from w w w .j a v a 2 s . c om*/ }; dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), beanSelected); dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), beanSelected); clipboard = new WritableValue(); dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); dbc.bindValue(SWTObservables.observeEnabled(pasteButton), new ComputedValue(Boolean.TYPE) { protected Object calculate() { return Boolean.valueOf(clipboard.getValue() != null); } }); ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", Bean.class), BeanProperties.value(Bean.class, "text")); }
From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet020TreeViewerWithSetFactory.java
License:Open Source License
private void initExtraBindings(DataBindingContext dbc) { final IObservableValue beanViewerSelection = ViewersObservables.observeSingleSelection(beanViewer); IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) { protected Object calculate() { return Boolean.valueOf(beanViewerSelection.getValue() != null); }// www. ja v a2s . co m }; dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), beanSelected); dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), beanSelected); clipboard = new WritableValue(); dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); dbc.bindValue(SWTObservables.observeEnabled(pasteButton), new ComputedValue(Boolean.TYPE) { protected Object calculate() { return Boolean.valueOf(clipboard.getValue() != null); } }); ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", Bean.class), BeanProperties.value(Bean.class, "text")); }
From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.RangeBlock.java
License:Open Source License
public Control createContents(Composite parent) { final Realm realm = bindings.getValidationRealm(); Composite result = group(parent, DiagramUIPrintingMessages.JPSPrintDialog_PrintRange); layout(result, 4);/* w ww .j a v a2s . c om*/ Button allRadio = radio(result, DiagramUIPrintingMessages.JPSPrintDialog_All); layoutSpanHorizontal(allRadio, 4); final IObservableValue allValue = BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_ALL_PAGES); bindings.bindValue(SWTObservables.observeSelection(allRadio), allValue, null, null); Button rangeRadio = radio(result, DiagramUIPrintingMessages.JPSPrintDialog_Pages); layoutSpanHorizontal(rangeRadio, 4); IObservableValue rangeValue = new ComputedValue(realm) { protected Object calculate() { return Boolean.valueOf(!((Boolean) allValue.getValue()).booleanValue()); } }; bindings.bindValue(SWTObservables.observeSelection(rangeRadio), rangeValue, null, null); layoutHorizontalIndent(label(result, DiagramUIPrintingMessages.JPSPrintDialog_From)); Text textFrom = text(result, 20); layoutHorizontalIndent(label(result, DiagramUIPrintingMessages.JPSPrintDialog_To)); Text textTo = text(result, 20); bindings.bindValue(SWTObservables.observeText(textFrom, SWT.Modify), BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_RANGE_FROM), null, null); bindings.bindValue(SWTObservables.observeEnabled(textFrom), rangeValue, null, null); bindings.bindValue(SWTObservables.observeText(textTo, SWT.Modify), BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_RANGE_TO), null, null); bindings.bindValue(SWTObservables.observeEnabled(textTo), rangeValue, null, null); return result; }
From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.ScalingBlock.java
License:Open Source License
public Control createContents(Composite parent) { final Realm realm = bindings.getValidationRealm(); Composite result = group(parent, DiagramUIPrintingMessages.JPSPrintDialog_Scaling); layout(result, 5);//from w ww.j av a2 s.c o m Button adjustRadio = radio(result, DiagramUIPrintingMessages.JPSPrintDialog_Adjust); layoutSpanHorizontal(adjustRadio, 2); Text textScale = text(result, 20); layoutSpanHorizontal(blank(result), 2); final IObservableValue scalingValue = BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_PERCENT_SCALING); bindings.bindValue(SWTObservables.observeSelection(adjustRadio), scalingValue, null, null); bindings.bindValue(SWTObservables.observeText(textScale, SWT.Modify), BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_SCALE_FACTOR), null, null); bindings.bindValue(SWTObservables.observeEnabled(textScale), scalingValue, null, null); Button fitToRadio = radio(result, DiagramUIPrintingMessages.JPSPrintDialog_FitTo); IObservableValue fitToValue = new ComputedValue(realm) { protected Object calculate() { return Boolean.valueOf(!((Boolean) scalingValue.getValue()).booleanValue()); } }; bindings.bindValue(SWTObservables.observeSelection(fitToRadio), fitToValue, null, null); layoutHorizontalIndent(layoutAlignRight(label(result, DiagramUIPrintingMessages.JPSPrintDialog_PagesWide))); Text textWide = text(result, 20); layoutHorizontalIndent(layoutAlignRight(label(result, DiagramUIPrintingMessages.JPSPrintDialog_PagesTall))); Text textTall = text(result, 20); bindings.bindValue(SWTObservables.observeText(textWide, SWT.Modify), BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_FIT_TO_WIDTH), null, null); bindings.bindValue(SWTObservables.observeEnabled(textWide), fitToValue, null, null); bindings.bindValue(SWTObservables.observeText(textTall, SWT.Modify), BeansObservables.observeValue(realm, options, PrintOptions.PROPERTY_FIT_TO_HEIGHT), null, null); bindings.bindValue(SWTObservables.observeEnabled(textTall), fitToValue, null, null); return result; }
From source file:org.eclipse.jubula.client.ui.dialogs.AbstractValidatedDialog.java
License:Open Source License
/** * {@inheritDoc}//from w w w . jav a2 s . c o m */ protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); IObservableValue okButtonEnablement = SWTObservables.observeEnabled(getButton(IDialogConstants.OK_ID)); AggregateValidationStatus validationStatus = new AggregateValidationStatus( m_validationContext.getValidationStatusProviders(), AggregateValidationStatus.MAX_SEVERITY); validationStatus.addValueChangeListener(new DialogStatusMessageListener(this)); new DataBindingContext().bindValue(okButtonEnablement, validationStatus, null, new UpdateValueStrategy().setConverter(new StatusToEnablementConverter())); }
From source file:org.eclipse.jubula.client.ui.rcp.editors.ObjectMappingConfigComponent.java
License:Open Source License
/** * /* w ww. j a v a 2s . c o m*/ * @param boundProperty The model property to use for databinding for * the created UI elements. * @param bindingContext The context to use for databinding for the created * UI elements. * @param factorScale Slider to bind. * @param factorText Label to bind. * @param lockCheckbox Checkbox to bind. * @param masterObservable Observable for the master element for which these * UI elements serve as detail. Essentially, the * created UI elements represent detailed * information about this element. * @param editor The editor containing the factor UI elements. */ private void bindFactor(String boundProperty, final DataBindingContext bindingContext, final Scale factorScale, Label factorText, Button lockCheckbox, IObservableValue masterObservable, IJBEditor editor) { IObservableValue uiElement = SWTObservables.observeSelection(factorScale); IObservableValue modelElement = BeansObservables.observeDetailValue(masterObservable, boundProperty, double.class); bindingContext.bindValue(uiElement, modelElement, new JBEditorUpdateValueStrategy(UpdateValueStrategy.POLICY_ON_REQUEST) .setConverter(m_sliderToModelConverter), new UpdateValueStrategy().setConverter(m_modelToSliderConverter)); uiElement = SWTObservables.observeText(factorText); bindingContext.bindValue(uiElement, modelElement, new UpdateValueStrategy().setConverter(m_labelToModelConverter), new UpdateValueStrategy().setConverter(m_modelToLabelConverter)); IObservableValue checkboxSelection = SWTObservables.observeSelection(lockCheckbox); uiElement = SWTObservables.observeEnabled(factorScale); bindingContext.bindValue(uiElement, masterObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToEnablementConverter)); bindingContext.bindValue(uiElement, checkboxSelection, new UpdateValueStrategy().setConverter(m_inverseBooleanConverter), new UpdateValueStrategy().setConverter(m_inverseBooleanConverter)); uiElement = SWTObservables.observeEnabled(factorText); bindingContext.bindValue(uiElement, masterObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToEnablementConverter)); bindingContext.bindValue(uiElement, checkboxSelection, new UpdateValueStrategy().setConverter(m_inverseBooleanConverter), new UpdateValueStrategy().setConverter(m_inverseBooleanConverter)); uiElement = SWTObservables.observeEnabled(lockCheckbox); bindingContext.bindValue(uiElement, masterObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToEnablementConverter)); }
From source file:org.eclipse.jubula.client.ui.rcp.editors.ObjectMappingConfigComponent.java
License:Open Source License
/** * Updates the binding between the given scale and its corresponding model * value. This is done by removing the old bindings and creating new ones. * /*from w w w .j a v a2 s . c o m*/ * @param boundProperty the property for the binding * @param bindingContext the binding context * @param factorScale the scale * @param masterObservable the observable */ private void updateBindFactor(String boundProperty, final DataBindingContext bindingContext, final Scale factorScale, IObservableValue masterObservable) { IObservableValue uiElement = SWTObservables.observeSelection(factorScale); IObservableValue modelElement = BeansObservables.observeDetailValue(masterObservable, boundProperty, double.class); removeBinding(uiElement, modelElement); bindingContext.bindValue(uiElement, modelElement, new JBEditorUpdateValueStrategy(UpdateValueStrategy.POLICY_ON_REQUEST) .setConverter(m_sliderToModelConverter), new UpdateValueStrategy().setConverter(m_modelToSliderConverter)); Label factorText = m_factorLabels.get(factorScale); uiElement = SWTObservables.observeText(factorText); removeBinding(uiElement, modelElement); bindingContext.bindValue(uiElement, modelElement, new UpdateValueStrategy().setConverter(m_labelToModelConverter), new UpdateValueStrategy().setConverter(m_modelToLabelConverter)); uiElement = SWTObservables.observeEnabled(factorScale); removeBinding(uiElement, masterObservable); bindingContext.bindValue(uiElement, masterObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToEnablementConverter)); }
From source file:org.eclipse.jubula.client.ui.rcp.editors.ObjectMappingConfigComponent.java
License:Open Source License
/** * Creates the labels and slider for the Threshold property as * well as the corresponding data bindings. * /*from w w w . j a v a 2 s. c o m*/ * @param parent Parent of the created components. * @param bindingContext The data binding context. * @param masterObservable Observable value used to determine * which model object is currently * being observed in detail. */ private void createThresholdSlider(Composite parent, DataBindingContext bindingContext, IObservableValue masterObservable) { String boundProperty = IObjectMappingProfilePO.PROP_THRESHOLD; // create Widget Label label = new Label(parent, SWT.NONE); label.setText(Messages.ObjectMappingPreferencePageThreshold); m_threshold = new Scale(parent, SWT.NONE); m_threshold.setMinimum(0); m_threshold.setMaximum(HUNDRED_PERCENT); m_threshold.setIncrement(STEP); m_threshold.setPageIncrement(STEP); m_threshold.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); m_thresholdText = new Label(parent, SWT.NONE); setLabelWidth(m_thresholdText); new Label(parent, SWT.NONE); ISWTObservableValue uiElement = SWTObservables.observeSelection(m_threshold); IObservableValue modelElement = BeansObservables.observeDetailValue(masterObservable, boundProperty, double.class); bindingContext.bindValue(uiElement, modelElement, new UpdateValueStrategy().setConverter(m_sliderToModelConverter), new UpdateValueStrategy().setConverter(m_modelToSliderConverter)); uiElement = SWTObservables.observeText(m_thresholdText); bindingContext.bindValue(uiElement, modelElement, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToLabelConverter)); uiElement = SWTObservables.observeEnabled(m_threshold); bindingContext.bindValue(uiElement, masterObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToEnablementConverter)); uiElement = SWTObservables.observeEnabled(m_thresholdText); bindingContext.bindValue(uiElement, masterObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy().setConverter(m_modelToEnablementConverter)); }