/** {@inheritDoc} */ @Override public void setConverters(IConverter targetToModel, IConverter modelToTarget) { if (targetToModelStrategy == null) { targetToModelStrategy = new UpdateValueStrategy(); } if (modelToTargetStrategy == null) { modelToTargetStrategy = new UpdateValueStrategy(); } targetToModelStrategy.setConverter(targetToModel); modelToTargetStrategy.setConverter(modelToTarget); }
protected void bindSection() { if (context != null) { context.dispose(); } context = new EMFDataBindingContext(); if (getEObject() != null && dataTableViewer != null) { final IObservableList dataObservableList = EMFEditObservables.observeList(getEditingDomain(), getEObject(), getDataFeature()); dataTableViewer.setInput(dataObservableList); final UpdateValueStrategy enableStrategy = new UpdateValueStrategy(); enableStrategy.setConverter( new Converter(Data.class, Boolean.class) { @Override public Object convert(final Object fromObject) { return fromObject != null; } }); context.bindValue( SWTObservables.observeEnabled(updateDataButton), ViewersObservables.observeSingleSelection(dataTableViewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableStrategy); context.bindValue( SWTObservables.observeEnabled(removeDataButton), ViewersObservables.observeSingleSelection(dataTableViewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableStrategy); if (promoteDataButton != null) { final UpdateValueStrategy enableMoveStrategy = new UpdateValueStrategy(); enableMoveStrategy.setConverter( new Converter(Data.class, Boolean.class) { @Override public Object convert(final Object fromObject) { return fromObject != null && ModelHelper.getParentProcess(getEObject()) != null && !((Data) fromObject).isTransient(); } }); context.bindValue( SWTObservables.observeEnabled(promoteDataButton), ViewersObservables.observeSingleSelection(dataTableViewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableMoveStrategy); } } }
/** * @param composite * @return */ private Composite createBooleanConfigurationComposite(Composite composite) { Composite booleanComposite = new Composite(composite, SWT.NONE); booleanComposite.setLayout(new GridLayout(2, false)); Label nameLabel = new Label(booleanComposite, SWT.NONE); nameLabel.setText(Messages.AddSimulationDataWizardPage_ProbabilityOfTrueLabel); Text labelText = new Text(booleanComposite, SWT.BORDER); labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); // ControlDecoration controlDecoration = new ControlDecoration(labelText, // SWT.LEFT|SWT.TOP); // FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() // .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); // controlDecoration.setImage(fieldDecoration.getImage()); // controlDecoration.setDescriptionText(Messages.mustBeAPercentage); UpdateValueStrategy targetToModel = new UpdateValueStrategy(); targetToModel.setConverter( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), true)); targetToModel.setAfterGetValidator( new ProbabilityValidator( new StringToDoubleValidator( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false)))); Binding provider = context.bindValue( SWTObservables.observeText(labelText, SWT.Modify), PojoObservables.observeValue(this, "probabilityOfTrue"), targetToModel, new UpdateValueStrategy() .setConverter( NumberToStringConverter.fromDouble( BonitaNumberFormat.getPercentInstance(), true))); ControlDecorationSupport.create(provider, SWT.TOP | SWT.LEFT); return booleanComposite; }
@Override protected void bindExpression() { if (control.isVisible()) { super.bindExpression(); } else { if (expressionBinding != null && externalDataBindingContext != null) { externalDataBindingContext.removeBinding(expressionBinding); expressionBinding.dispose(); } final IObservableValue nameObservable = getExpressionNameObservable(); final UpdateValueStrategy targetToModelNameStrategy = new UpdateValueStrategy(); targetToModelNameStrategy.setConverter( new Converter(Boolean.class, String.class) { @Override public Object convert(final Object fromObject) { final String input = ((Boolean) fromObject).toString(); updateContentType(ExpressionConstants.CONSTANT_TYPE); updateContent(getContentFromInput(input)); refresh(); return input; } }); final UpdateValueStrategy modelToTargetNameStrategy = new UpdateValueStrategy(); modelToTargetNameStrategy.setConverter( new Converter(String.class, Boolean.class) { @Override public Object convert(final Object fromObject) { if (fromObject != null) { final String input = fromObject.toString(); if (input.equalsIgnoreCase(Boolean.TRUE.toString())) { return true; } } return false; } }); internalDataBindingContext.bindValue( SWTObservables.observeSelection(checkBoxControl), nameObservable, targetToModelNameStrategy, modelToTargetNameStrategy); } }
protected void showContent(String type) { IExpressionProvider provider = ExpressionEditorService.getInstance().getExpressionProvider(type); Assert.isNotNull(provider); for (Control c : contentComposite.getChildren()) { c.dispose(); } if (currentExpressionEditor != null) { currentExpressionEditor.dispose(); } currentExpressionEditor = provider.getExpressionEditor(inputExpression, context); currentExpressionEditor.setIsPageFlowContext(isPageFlowContext); if (currentExpressionEditor != null) { currentExpressionEditor.createExpressionEditor(contentComposite, isPassword); contentComposite.layout(true, true); if (helpControl != null) { // helpControl.setVisible(currentExpressionEditor.provideDialogTray()); helpControl.setVisible(false); if (currentExpressionEditor.provideDialogTray()) { ToolItem item = ((ToolBar) helpControl).getItem(0); item.setSelection(true); openTrayListener.handleEvent(new Event()); } else if (getTray() != null) { closeTray(); } } if (dataBindingContext != null) { dataBindingContext.dispose(); } dataBindingContext = new EMFDataBindingContext(); UpdateValueStrategy selectionToExpressionType = new UpdateValueStrategy(); IConverter convert = new Converter(IExpressionProvider.class, String.class) { @Override public Object convert(Object arg0) { return ((IExpressionProvider) arg0).getExpressionType(); } }; selectionToExpressionType.setConverter(convert); if (domain != null) { domain .getCommandStack() .execute( SetCommand.create( domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__TYPE, type)); } else { inputExpression.setType(type); } currentExpressionEditor.bindExpression( dataBindingContext, context, inputExpression, viewerTypeFilters, expressionViewer); currentExpressionEditor.addListener( new Listener() { @Override public void handleEvent(Event event) { Button okButton = getButton(OK); if (okButton != null && !okButton.isDisposed()) { okButton.setEnabled(currentExpressionEditor.canFinish()); } } }); DialogSupport.create(this, dataBindingContext); } }
@Override public void bindExpression( final EMFDataBindingContext dataBindingContext, final EObject context, final Expression inputExpression, final ViewerFilter[] filters, final ExpressionViewer expressionViewer) { final EObject finalContext = context; addExpressionButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { super.widgetSelected(e); expressionButtonListener(finalContext); } }); editorInputExpression = inputExpression; fillViewerInput(context); final IObservableValue contentObservable = EMFObservables.observeValue( inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT); final IObservableValue nameObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME); final IObservableValue returnTypeObservable = EMFObservables.observeValue( inputExpression, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); final IObservableValue referenceObservable = EMFObservables.observeValue( inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS); final UpdateValueStrategy selectionToName = new UpdateValueStrategy(); final IConverter nameConverter = new Converter(Parameter.class, String.class) { @Override public Object convert(final Object parameter) { return ((Parameter) parameter).getName(); } }; selectionToName.setConverter(nameConverter); final UpdateValueStrategy selectionToContent = new UpdateValueStrategy(); final IConverter contentConverter = new Converter(Parameter.class, String.class) { @Override public Object convert(final Object parameter) { return ((Parameter) parameter).getName(); } }; selectionToContent.setConverter(contentConverter); final UpdateValueStrategy selectionToReturnType = new UpdateValueStrategy(); final IConverter returnTypeConverter = new Converter(Parameter.class, String.class) { @Override public Object convert(final Object parameter) { return ((Parameter) parameter).getTypeClassname(); } }; selectionToReturnType.setConverter(returnTypeConverter); final UpdateValueStrategy selectionToReferencedData = new UpdateValueStrategy(); final IConverter referenceConverter = new Converter(Parameter.class, List.class) { @Override public Object convert(final Object parameter) { return Collections.singletonList(parameter); } }; selectionToReferencedData.setConverter(referenceConverter); final UpdateValueStrategy referencedDataToSelection = new UpdateValueStrategy(); final IConverter referencetoDataConverter = new Converter(List.class, Parameter.class) { @SuppressWarnings("unchecked") @Override public Object convert(final Object parameterList) { if (!((List<Parameter>) parameterList).isEmpty()) { final Parameter p = ((List<Parameter>) parameterList).get(0); final Collection<Parameter> inputParameters = (Collection<Parameter>) viewer.getInput(); for (final Parameter param : inputParameters) { if (param.getName().equals(p.getName()) && param.getTypeClassname().equals(p.getTypeClassname())) { return param; } } } return null; } }; referencedDataToSelection.setConverter(referencetoDataConverter); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), nameObservable, selectionToName, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), contentObservable, selectionToContent, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), returnTypeObservable, selectionToReturnType, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), referenceObservable, selectionToReferencedData, referencedDataToSelection); dataBindingContext.bindValue( SWTObservables.observeText(typeText, SWT.Modify), returnTypeObservable); }
private DataBindingContext initDataBindings() { DataBindingContext bindingContext = new DataBindingContext(); // IObservableValue btnCaseSensitiveObserveSelectionObserveWidget = SWTObservables.observeSelection(btnCaseSensitive); IObservableValue ecgModelCaseSensitiveObserveValue = PojoObservables.observeValue(ecgModel, "caseSensitive"); // $NON-NLS-1$ bindingContext.bindValue( btnCaseSensitiveObserveSelectionObserveWidget, ecgModelCaseSensitiveObserveValue, null, null); // IObservableValue btnRegualrExpressionObserveSelectionObserveWidget = SWTObservables.observeSelection(btnRegualarExpression); IObservableValue ecgModelRegularExpressionObserveValue = PojoObservables.observeValue(ecgModel, "regularExpression"); // $NON-NLS-1$ bindingContext.bindValue( btnRegualrExpressionObserveSelectionObserveWidget, ecgModelRegularExpressionObserveValue, null, null); // IObservableValue containingTextObserveTextObserveWidget = SWTObservables.observeSelection(containingText); IObservableValue ecgModelSearchStringObserveValue = PojoObservables.observeValue(ecgModel, "searchString"); // $NON-NLS-1$ bindingContext.bindValue( containingTextObserveTextObserveWidget, ecgModelSearchStringObserveValue, null, null); // IObservableValue containingEndTextObserveTextObserveWidget = SWTObservables.observeSelection(containingEndText); IObservableValue ecgModelSearchEndStringObserveValue = PojoObservables.observeValue(ecgModel, "searchEndString"); // $NON-NLS-1$ bindingContext.bindValue( containingEndTextObserveTextObserveWidget, ecgModelSearchEndStringObserveValue, null, null); // IObservableValue consoleListObserveSelectionObserveWidget = SWTObservables.observeSelection(consoleList); IObservableValue ecgModelSourceObserveValue = PojoObservables.observeValue(ecgModel, "source"); // $NON-NLS-1$ UpdateValueStrategy name2TextConsoleStrategy = new UpdateValueStrategy(); name2TextConsoleStrategy.setConverter(new Name2TextConsoleConverter()); UpdateValueStrategy textConsole2NameStrategy = new UpdateValueStrategy(); textConsole2NameStrategy.setConverter(new TextConsole2NameConverter()); bindingContext.bindValue( consoleListObserveSelectionObserveWidget, ecgModelSourceObserveValue, name2TextConsoleStrategy, textConsole2NameStrategy); // Listener for update dispose-state ecgModelSourceObserveValue.addValueChangeListener( new IValueChangeListener() { @Override public void handleValueChange(ValueChangeEvent event) { // when we change back to the origin source console we must set the origin disposal // state if (ecgModelOrig.getSource() == ecgModel.getSource()) { ecgModel.setSourceDisposed(ecgModelOrig.isSourceDisposed()); } else { ecgModel.setSourceDisposed(false); } } }); // IObservableValue btnNotMatchingObserveSelectionObserveWidget = SWTObservables.observeSelection(btnNotMatching); IObservableValue ecgModelNotMatchingObserveValue = PojoObservables.observeValue(ecgModel, "notMatching"); // $NON-NLS-1$ bindingContext.bindValue( btnNotMatchingObserveSelectionObserveWidget, ecgModelNotMatchingObserveValue, null, null); // IObservableValue btnWholeWordObserveSelectionObserveWidget = SWTObservables.observeSelection(btnWholeWord); IObservableValue ecgModelWholeWordObserveValue = PojoObservables.observeValue(ecgModel, "wholeWord"); // $NON-NLS-1$ bindingContext.bindValue( btnWholeWordObserveSelectionObserveWidget, ecgModelWholeWordObserveValue, null, null); // IObservableValue btnSetEndMarkerObserveSelectionObserveWidget = SWTObservables.observeSelection(btnSetEndMarker); IObservableValue ecgModelRangeMatchingObserveValue = PojoObservables.observeValue(ecgModel, "rangeMatching"); // $NON-NLS-1$ bindingContext.bindValue( btnSetEndMarkerObserveSelectionObserveWidget, ecgModelRangeMatchingObserveValue, null, null); // // ecgModelRangeMatchingObserveValue.addValueChangeListener( new IValueChangeListener() { @Override public void handleValueChange(ValueChangeEvent event) { updateRangeMatchingArrangement(); } }); // ecgModelRegularExpressionObserveValue.addValueChangeListener( new IValueChangeListener() { @Override public void handleValueChange(ValueChangeEvent event) { updateLblText(); } }); return bindingContext; }