List of usage examples for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection
public static IViewerValueProperty singleSelection()
From source file:org.bonitasoft.studio.properties.sections.general.TransitionConditionContribution.java
License:Open Source License
private void refreshBindings() { if (conditionSection != null && !conditionSection.isDisposed()) { if (dataBindingContext != null) { dataBindingContext.dispose(); }// w w w. j ava2s .c om final IConverter conditionConverter = new Converter(Boolean.class, Boolean.class) { @Override public Object convert(final Object fromObject) { if (transition != null && transition.getSource() instanceof CatchLinkEvent) { return false; } return !(Boolean) fromObject; } }; final IConverter defaultConverter = new Converter(Boolean.class, Boolean.class) { @Override public Object convert(final Object fromObject) { if (transition != null && transition.getSource() instanceof CatchLinkEvent) { return false; } else { final SourceElement elem = transition.getSource(); boolean alreadyExistDefault = false; for (final Connection c : elem.getOutgoing()) { if (c instanceof SequenceFlow) { if (((SequenceFlow) c).isIsDefault() && !c.equals(transition)) { alreadyExistDefault = true; } } } if (alreadyExistDefault) { return false; } else { return true; } } } }; final UpdateValueStrategy useExpressionTargetToModel = new UpdateValueStrategy(); useExpressionTargetToModel.setConverter(new Converter(Boolean.class, SequenceFlowConditionType.class) { @Override public Object convert(final Object fromObject) { if ((Boolean) fromObject) { return SequenceFlowConditionType.EXPRESSION; } else { return SequenceFlowConditionType.DECISION_TABLE; } } }); final UpdateValueStrategy useDescisionTargetToModel = new UpdateValueStrategy(); useDescisionTargetToModel.setConverter(new Converter(Boolean.class, SequenceFlowConditionType.class) { @Override public Object convert(final Object fromObject) { if ((Boolean) fromObject) { return SequenceFlowConditionType.DECISION_TABLE; } else { return SequenceFlowConditionType.EXPRESSION; } } }); final UpdateValueStrategy useExpressionModelToTarget = new UpdateValueStrategy(); useExpressionModelToTarget.setConverter(new Converter(SequenceFlowConditionType.class, Boolean.class) { @Override public Object convert(final Object fromObject) { if (fromObject == SequenceFlowConditionType.EXPRESSION) { return true; } else { return false; } } }); final UpdateValueStrategy useDecisionModelToTarget = new UpdateValueStrategy(); useDecisionModelToTarget.setConverter(new Converter(SequenceFlowConditionType.class, Boolean.class) { @Override public Object convert(final Object fromObject) { return fromObject == SequenceFlowConditionType.DECISION_TABLE; } }); dataBindingContext = new EMFDataBindingContext(); final IObservableValue typeValue = EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__CONDITION_TYPE); typeValue.addValueChangeListener(new IValueChangeListener() { @Override public void handleValueChange(final ValueChangeEvent event) { if (conditionSection != null && !conditionSection.isDisposed()) { if (event.diff.getNewValue() == SequenceFlowConditionType.EXPRESSION && (conditionViewer == null || conditionViewer.getControl().isDisposed())) { if (conditionSection.getClient() != null) { conditionSection.getClient().dispose(); } conditionSection.setClient(createExpressionComposite(conditionSection, widgetFactory)); conditionSection.setExpanded(true); } else if (event.diff.getNewValue() == SequenceFlowConditionType.DECISION_TABLE && conditionViewer != null && !conditionViewer.getControl().isDisposed()) { if (conditionSection.getClient() != null) { conditionSection.getClient().dispose(); } conditionSection .setClient(createDecisionTableComposite(conditionSection, widgetFactory)); conditionSection.setExpanded(true); } refreshBindings(); } } }); dataBindingContext.bindValue(SWTObservables.observeSelection(useExpressionCondition), typeValue, useExpressionTargetToModel, useExpressionModelToTarget); dataBindingContext.bindValue(SWTObservables.observeSelection(useDecisionTable), typeValue, useDescisionTargetToModel, useDecisionModelToTarget); dataBindingContext.bindValue(SWTObservables.observeSelection(defaultCheckBox), EMFEditObservables .observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT)); dataBindingContext.bindValue(SWTObservables.observeEnabled(defaultCheckBox), EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT), new UpdateValueStrategy().setConverter(defaultConverter), new UpdateValueStrategy().setConverter(defaultConverter)); if (conditionViewer != null && !conditionViewer.getControl().isDisposed()) { dataBindingContext.bindValue(SWTObservables.observeEnabled(conditionViewer.getControl()), EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT), new UpdateValueStrategy().setConverter(conditionConverter), new UpdateValueStrategy().setConverter(conditionConverter)); // dataBindingContext.bindValue(SWTObservables.observeEnabled(conditionViewer.getToolbar()), // EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),new UpdateValueStrategy().setConverter(conditionConverter),new UpdateValueStrategy().setConverter(conditionConverter)); conditionViewer.setEditingDomain(editingDomain); dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(conditionViewer), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.SEQUENCE_FLOW__CONDITION) .observe(transition)); conditionViewer.setInput(transition); dataBindingContext.bindValue(SWTObservables.observeSelection(useExpressionCondition), SWTObservables.observeEnabled(conditionViewer.getControl())); } dataBindingContext.bindValue(SWTObservables.observeEnabled(useExpressionCondition), EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT), new UpdateValueStrategy().setConverter(conditionConverter), new UpdateValueStrategy().setConverter(conditionConverter)); dataBindingContext.bindValue(SWTObservables.observeEnabled(useDecisionTable), EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT), new UpdateValueStrategy().setConverter(conditionConverter), new UpdateValueStrategy().setConverter(conditionConverter)); if (updateTableButton != null && !updateTableButton.isDisposed()) { dataBindingContext.bindValue(SWTObservables.observeEnabled(updateTableButton), EMFEditObservables.observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT), new UpdateValueStrategy().setConverter(conditionConverter), new UpdateValueStrategy().setConverter(conditionConverter)); } } }
From source file:org.bonitasoft.studio.properties.sections.loop.MultiInstantiationPropertyContribution.java
License:Open Source License
protected void bindMultiInstanciationParameters() { multiInstantiation = activity.getMultiInstantiation(); initMultiInstanciationModelIfNeeded(); context.bindValue(WidgetProperties.selection().observe(multiRadio), EMFEditProperties .value(editingDomain, ProcessPackage.Literals.ACTIVITY__IS_MULTI_INSTANCE).observe(activity)); bindCardinality();//from ww w. j a v a2s. co m bindCompletionCondition(); context.bindValue(WidgetProperties.selection().observe(sequentialButton), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__SEQUENTIAL) .observe(multiInstantiation)); /*Collection Data Chooser*/ collectionDataChooser.setInput(new WritableList( ModelHelper.getAccessibleData(ModelHelper.getParentProcess(activity)), Data.class)); context.bindValue(ViewersObservables.observeSingleSelection(collectionDataChooser), EMFEditObservables.observeValue(editingDomain, multiInstantiation, ProcessPackage.Literals.MULTI_INSTANTIATION__COLLECTION_DATA_TO_MULTI_INSTANTIATE)); listOutputDataChooser.setInput(new WritableList( ModelHelper.getAccessibleData(ModelHelper.getParentProcess(activity)), Data.class)); /*List for output data*/ context.bindValue(ViewerProperties.singleSelection().observe(listOutputDataChooser), EMFEditProperties .value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__LIST_DATA_CONTAINING_OUTPUT_RESULTS) .observe(multiInstantiation)); /*Input Data Chooser*/ inputDataChooser.setInput(EMFObservables.observeList(activity, ProcessPackage.Literals.DATA_AWARE__DATA)); context.bindValue(ViewerProperties.singleSelection().observe(inputDataChooser), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__INPUT_DATA) .observe(multiInstantiation)); /*Output Data Chooser*/ outputDataChooser.setInput(EMFObservables.observeList(activity, ProcessPackage.Literals.DATA_AWARE__DATA)); context.bindValue(ViewerProperties.singleSelection().observe(outputDataChooser), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__OUTPUT_DATA) .observe(multiInstantiation)); bindFieldsForEnablement(); }
From source file:org.bonitasoft.studio.properties.sections.loop.MultiInstantiationPropertyContribution.java
License:Open Source License
protected void bindCompletionCondition() { context.bindValue(ViewerProperties.singleSelection().observe(completionConditionViewer), EMFEditProperties/*from ww w . j a v a2 s.com*/ .value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__COMPLETION_CONDITION) .observe(multiInstantiation)); Expression completionCondition = multiInstantiation.getCompletionCondition(); if (completionCondition == null) { completionCondition = ExpressionFactory.eINSTANCE.createExpression(); completionCondition.setReturnType(Boolean.class.getName()); completionCondition.setReturnTypeFixed(true); } completionConditionViewer.setContext(activity); completionConditionViewer.setInput(multiInstantiation); completionConditionViewer.setSelection(new StructuredSelection(completionCondition)); }
From source file:org.bonitasoft.studio.properties.sections.loop.MultiInstantiationPropertyContribution.java
License:Open Source License
protected void bindCardinality() { context.bindValue(WidgetProperties.selection().observe(useCardinalityButton), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__USE_CARDINALITY) .observe(multiInstantiation)); context.bindValue(ViewerProperties.singleSelection().observe(cardinalityExpression), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.MULTI_INSTANTIATION__CARDINALITY) .observe(multiInstantiation)); Expression cardinality = multiInstantiation.getCardinality(); if (cardinality == null) { cardinality = ExpressionFactory.eINSTANCE.createExpression(); cardinality.setReturnType(Integer.class.getName()); cardinality.setReturnTypeFixed(true); }/* w w w . j a v a2s.c o m*/ cardinalityExpression.setInput(multiInstantiation); cardinalityExpression.setSelection(new StructuredSelection(cardinality)); }
From source file:org.bonitasoft.studio.properties.sections.userxp.DynamicDescriptionPropertySectionContribution.java
License:Open Source License
protected void refreshDataBindingContext() { if (dataBindingContext != null) { dataBindingContext.dispose();//from w ww. j a va 2 s . c o m } dataBindingContext = new EMFDataBindingContext(); if (eObject != null && expressionViewer != null) { Expression selection = ((FlowElement) eObject).getDynamicDescription(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, eObject, ProcessPackage.Literals.FLOW_ELEMENT__DYNAMIC_DESCRIPTION, selection)); } dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(expressionViewer), EMFEditProperties .value(editingDomain, ProcessPackage.Literals.FLOW_ELEMENT__DYNAMIC_DESCRIPTION) .observe(eObject)); //expressionViewer.setSelection(new StructuredSelection(selection)) ; } }
From source file:org.bonitasoft.studio.properties.sections.userxp.DynamicLabelPropertySectionContribution.java
License:Open Source License
protected void refreshDataBindingContext() { if (dataBindingContext != null) { dataBindingContext.dispose();/* w w w .j a va 2 s . c om*/ } dataBindingContext = new EMFDataBindingContext(); if (eObject != null && expressionViewer != null) { Expression selection = ((FlowElement) eObject).getDynamicLabel(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, eObject, ProcessPackage.Literals.FLOW_ELEMENT__DYNAMIC_LABEL, selection)); } dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(expressionViewer), EMFEditProperties.value(editingDomain, ProcessPackage.Literals.FLOW_ELEMENT__DYNAMIC_LABEL) .observe(eObject)); //expressionViewer.setSelection(new StructuredSelection(selection)) ; } }
From source file:org.bonitasoft.studio.properties.sections.userxp.StepSummarySectionContribution.java
License:Open Source License
protected void refreshDataBindingContext() { if (context != null) { context.dispose();//from www.j a v a 2s .c o m } context = new EMFDataBindingContext(); if (eObject != null && expressionViewer != null) { Expression selection = ((FlowElement) eObject).getStepSummary(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, eObject, ProcessPackage.Literals.FLOW_ELEMENT__STEP_SUMMARY, selection)); } context.bindValue(ViewerProperties.singleSelection().observe(expressionViewer), EMFEditProperties .value(editingDomain, ProcessPackage.Literals.FLOW_ELEMENT__STEP_SUMMARY).observe(eObject)); expressionViewer.setSelection(new StructuredSelection(selection)); } }
From source file:org.bonitasoft.studio.simulation.properties.contributions.DataChangesContribution.java
License:Open Source License
@Override public void createControl(final Composite composite, final TabbedPropertySheetWidgetFactory widgetFactory, final ExtensibleGridPropertySection extensibleGridPropertySection) { composite.setLayout(new GridLayout(1, false)); context = new EMFDataBindingContext(); dynamicComposite = new DynamicAddRemoveLineComposite(composite, SWT.NONE) { @Override//w w w. ja va 2s .c om protected org.eclipse.swt.widgets.Button createAddButton(Composite parent) { org.eclipse.swt.widgets.Button addButton = new Button(parent, SWT.FLAT); addButton.setText(Messages.add); return addButton; }; @Override protected Control createLineComposite(Composite parent, Object object) { final DataChange dataChange; if (object instanceof DataChange) { dataChange = (DataChange) object; } else { dataChange = SimulationFactory.eINSTANCE.createDataChange(); AddCommand addCommand = new AddCommand(editingDomain, eObject, SimulationPackage.Literals.SIMULATION_ACTIVITY__DATA_CHANGE, dataChange); editingDomain.getCommandStack().execute(addCommand); } Composite lineComposite = getWidgetFactory().createComposite(parent); composites.add(lineComposite); lineComposite.setLayout(new GridLayout(5, false)); getWidgetFactory().createLabel(lineComposite, Messages.Data); final Combo combo = new Combo(lineComposite, SWT.READ_ONLY); combo.setLayoutData(GridDataFactory.swtDefaults().hint(85, SWT.DEFAULT).create()); final ComboViewer viewer = new ComboViewer(combo); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ((SimulationData) element).getName(); }; }); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer.setInput(ModelHelper.getParentProcess(eObject).getSimulationData()); if (dataChange.getData() != null) { viewer.setSelection(new StructuredSelection(dataChange.getData())); } getWidgetFactory().createLabel(lineComposite, Messages.Expression); final ExpressionViewer expressionText = new ExpressionViewer(lineComposite, SWT.BORDER, widgetFactory, editingDomain, SimulationPackage.Literals.DATA_CHANGE__VALUE); expressionText.addFilter( new AvailableExpressionTypeFilter(new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.SIMULATION_VARIABLE_TYPE, ExpressionConstants.SCRIPT_TYPE })); expressionText.getControl() .setLayoutData(GridDataFactory.swtDefaults().hint(250, SWT.DEFAULT).create()); Expression selection = dataChange.getValue(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, dataChange, SimulationPackage.Literals.DATA_CHANGE__VALUE, selection)); } context.bindValue(ViewerProperties.singleSelection().observe(expressionText), EMFEditProperties .value(editingDomain, SimulationPackage.Literals.DATA_CHANGE__VALUE).observe(dataChange)); expressionText.setInput(dataChange); //expressionText.setSelection(new StructuredSelection(selection)) ; Button createDataButton = new Button(lineComposite, SWT.FLAT); createDataButton.setText(Messages.createSimulationData); createDataButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { AddSimulationDataWizard wiz = new AddSimulationDataWizard( ModelHelper.getParentProcess(eObject), editingDomain); if (new WizardDialog(Display.getDefault().getActiveShell(), wiz) .open() == WizardDialog.OK) { viewer.setInput(ModelHelper.getParentProcess(eObject).getSimulationData()); viewer.setSelection(new StructuredSelection(wiz.getCreatedData())); // expressionText.reset() ; // expressionText.setText(GroovyUtil.GROOVY_PREFIX + wiz.getCreatedData().getName() + GroovyUtil.GROOVY_SUFFIX); } } }); createButtons.add(createDataButton); combos.add(combo); dataChanges.add(dataChange); bindings.add(context.bindValue(ViewersObservables.observeSingleSelection(viewer), EMFEditObservables .observeValue(editingDomain, dataChange, SimulationPackage.Literals.DATA_CHANGE__DATA))); return lineComposite; } @Override protected void lineRemoved(int i) { composites.remove(i); createButtons.remove(i); combos.remove(i); context.removeBinding(bindings.get(i)); bindings.remove(i); DataChange dataChange = dataChanges.get(i); RemoveCommand removeCommand = new RemoveCommand(editingDomain, eObject, SimulationPackage.Literals.SIMULATION_ACTIVITY__DATA_CHANGE, dataChange); editingDomain.getCommandStack().execute(removeCommand); dataChanges.remove(i); extensibleGridPropertySection.getTabbedPropertySheetPage().resizeScrolledComposite(); } @Override protected void lineAdded(int i) { extensibleGridPropertySection.getTabbedPropertySheetPage().resizeScrolledComposite(); } @Override protected TabbedPropertySheetWidgetFactory getWidgetFactory() { return widgetFactory; } @Override protected Composite getTopComposite() { return (Composite) extensibleGridPropertySection.getTabbedPropertySheetPage().getControl(); } }; dynamicComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); fillDynamicWidget(); }
From source file:org.bonitasoft.studio.simulation.properties.contributions.LoopContribution.java
License:Open Source License
@Override public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, ExtensibleGridPropertySection extensibleGridPropertySection) { SimulationTransition transition;//w w w. ja v a 2 s . com if (((Activity) eObject).getLoopTransition() == null) { transition = SimulationFactory.eINSTANCE.createSimulationTransition(); editingDomain.getCommandStack().execute(new SetCommand(editingDomain, eObject, SimulationPackage.Literals.SIMULATION_ACTIVITY__LOOP_TRANSITION, transition)); } else { transition = ((Activity) eObject).getLoopTransition(); } composite.setLayout(new GridLayout(2, false)); Composite radioComposite = widgetFactory.createComposite(composite); radioComposite.setLayout(new FillLayout()); radioComposite.setLayoutData(GridDataFactory.fillDefaults().create()); Button expressionRadio = widgetFactory.createButton(radioComposite, "Expression", SWT.RADIO); Button probaRadio = widgetFactory.createButton(radioComposite, "Probability", SWT.RADIO); final Composite stackComposite = widgetFactory.createComposite(composite); stackComposite.setLayoutData(GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).create()); final StackLayout stackLayout = new StackLayout(); stackComposite.setLayout(stackLayout); final Composite probaComposite = widgetFactory.createComposite(stackComposite); FillLayout layout = new FillLayout(); layout.marginWidth = 10; probaComposite.setLayout(layout); Text probaText = widgetFactory.createText(probaComposite, "", SWT.BORDER); ControlDecoration controlDecoration = new ControlDecoration(probaText, SWT.LEFT | SWT.TOP); FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); controlDecoration.setImage(fieldDecoration.getImage()); controlDecoration.setDescriptionText(Messages.mustBeAPercentage); final Composite expressionComposite = widgetFactory.createComposite(stackComposite); FillLayout layout2 = new FillLayout(); layout2.marginWidth = 10; expressionComposite.setLayout(layout2); ExpressionViewer expressionText = new ExpressionViewer(expressionComposite, SWT.BORDER, widgetFactory, editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION); Expression selection = transition.getExpression(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, transition, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION, selection)); } context.bindValue(ViewerProperties.singleSelection().observe(expressionText), EMFEditProperties.value(editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION) .observe(eObject)); expressionText.setInput(eObject); boolean useExpression = transition.isUseExpression(); if (useExpression) { stackLayout.topControl = expressionComposite; } else { stackLayout.topControl = probaComposite; } expressionRadio.setSelection(useExpression); probaRadio.setSelection(!useExpression); expressionRadio.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (((Button) e.getSource()).getSelection()) { stackLayout.topControl = expressionComposite; } else { stackLayout.topControl = probaComposite; } stackComposite.layout(); } }); context = new EMFDataBindingContext(); context.bindValue(SWTObservables.observeSelection(expressionRadio), EMFEditObservables.observeValue( editingDomain, transition, SimulationPackage.Literals.SIMULATION_TRANSITION__USE_EXPRESSION)); context.bindValue(SWTObservables.observeText(probaText, SWT.Modify), EMFEditObservables.observeValue(editingDomain, transition, SimulationPackage.Literals.SIMULATION_TRANSITION__PROBABILITY), new UpdateValueStrategy() .setConverter( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false)) .setAfterGetValidator(new WrappingValidator(controlDecoration, new StringToDoubleValidator(StringToNumberConverter .toDouble(BonitaNumberFormat.getPercentInstance(), false)))), new UpdateValueStrategy().setConverter( NumberToStringConverter.fromDouble(BonitaNumberFormat.getPercentInstance(), false))); }
From source file:org.bonitasoft.studio.simulation.properties.contributions.TransitionDataContribution.java
License:Open Source License
@Override public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, ExtensibleGridPropertySection extensibleGridPropertySection) { composite.setLayout(new GridLayout(2, false)); Composite radioComposite = widgetFactory.createComposite(composite); radioComposite.setLayout(new FillLayout()); radioComposite.setLayoutData(GridDataFactory.fillDefaults().create()); Button expressionRadio = widgetFactory.createButton(radioComposite, "Expression", SWT.RADIO); Button probaRadio = widgetFactory.createButton(radioComposite, "Probability", SWT.RADIO); final Composite stackComposite = widgetFactory.createComposite(composite); stackComposite.setLayoutData(GridDataFactory.fillDefaults().create()); final StackLayout stackLayout = new StackLayout(); stackComposite.setLayout(stackLayout); final Composite probaComposite = widgetFactory.createComposite(stackComposite); probaComposite.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).create()); GridLayout layout = new GridLayout(1, false); layout.marginWidth = 10;// w w w . ja v a 2 s . co m probaComposite.setLayout(layout); Text probaText = widgetFactory.createText(probaComposite, "", SWT.BORDER); probaText.setLayoutData( GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(50, SWT.DEFAULT).create()); ControlDecoration controlDecoration = new ControlDecoration(probaText, SWT.LEFT | SWT.TOP); FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); controlDecoration.setImage(fieldDecoration.getImage()); controlDecoration.setDescriptionText(Messages.mustBeAPercentage); final Composite expressionComposite = widgetFactory.createComposite(stackComposite); GridLayout layout2 = new GridLayout(2, false); layout2.marginWidth = 10; expressionComposite.setLayout(layout2); ExpressionViewer expressionText = new ExpressionViewer(expressionComposite, SWT.BORDER, widgetFactory, editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION); expressionText.getControl().setLayoutData( GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(250, SWT.DEFAULT).create()); expressionText.addFilter(new AvailableExpressionTypeFilter( new String[] { ExpressionConstants.VARIABLE_TYPE, ExpressionConstants.GROOVY, ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.PARAMETER_TYPE })); Expression selection = ((SimulationTransition) eObject).getExpression(); if (selection == null) { selection = ExpressionFactory.eINSTANCE.createExpression(); editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, eObject, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION, selection)); } if (context != null) { context.dispose(); } context = new EMFDataBindingContext(); context.bindValue(ViewerProperties.singleSelection().observe(expressionText), EMFEditProperties.value(editingDomain, SimulationPackage.Literals.SIMULATION_TRANSITION__EXPRESSION) .observe(eObject)); expressionText.setInput(eObject); Button createDataButton = new Button(expressionComposite, SWT.FLAT); createDataButton.setText(Messages.createSimulationData); createDataButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { AddSimulationDataWizard wiz = new AddSimulationDataWizard(ModelHelper.getParentProcess(eObject), editingDomain); WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wiz); if (dialog.open() == WizardDialog.OK) { // expressionText.reset() ; // expressionText.setText(GroovyUtil.GROOVY_PREFIX + wiz.getCreatedData().getName() + GroovyUtil.GROOVY_SUFFIX); } } }); boolean useExpression = ((SimulationTransition) eObject).isUseExpression(); if (useExpression) { stackLayout.topControl = expressionComposite; } else { stackLayout.topControl = probaComposite; } expressionRadio.setSelection(useExpression); probaRadio.setSelection(!useExpression); expressionRadio.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (((Button) e.getSource()).getSelection()) { stackLayout.topControl = expressionComposite; } else { stackLayout.topControl = probaComposite; } stackComposite.layout(); } }); context = new EMFDataBindingContext(); context.bindValue(SWTObservables.observeSelection(expressionRadio), EMFEditObservables.observeValue( editingDomain, eObject, SimulationPackage.Literals.SIMULATION_TRANSITION__USE_EXPRESSION)); context.bindValue(SWTObservables.observeText(probaText, SWT.Modify), EMFEditObservables.observeValue(editingDomain, eObject, SimulationPackage.Literals.SIMULATION_TRANSITION__PROBABILITY), new UpdateValueStrategy() .setConverter( StringToNumberConverter.toDouble(BonitaNumberFormat.getPercentInstance(), false)) .setAfterGetValidator(new WrappingValidator(controlDecoration, new StringToDoubleValidator(StringToNumberConverter .toDouble(BonitaNumberFormat.getPercentInstance(), false)))), new UpdateValueStrategy().setConverter( NumberToStringConverter.fromDouble(BonitaNumberFormat.getPercentInstance(), false))); if (eObject instanceof Connection) { if (((Connection) eObject).getSource() instanceof CatchLinkEvent) { radioComposite.setEnabled(false); probaText.setEnabled(false); } } }