Example usage for org.eclipse.jface.databinding.swt SWTObservables observeText

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeText

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables observeText.

Prototype

@Deprecated
public static ISWTObservableValue observeText(Control control, int event) 

Source Link

Document

Returns an observable observing the text attribute of the provided control.

Usage

From source file:org.bonitasoft.studio.properties.sections.timer.cron.CronEditor.java

License:Open Source License

protected void createHourlyTab(TabFolder tablFolder) {
    final TabItem item = new TabItem(tablFolder, SWT.NONE);
    item.setText(Messages.hourly);/*w w w.  j  a  va  2s. c o m*/

    final Composite hourlyContent = new Composite(tablFolder, SWT.NONE);
    hourlyContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    hourlyContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).create());

    final Button everyRadio = new Button(hourlyContent, SWT.RADIO);
    everyRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    everyRadio.setText(Messages.every);

    context.bindValue(SWTObservables.observeSelection(everyRadio),
            PojoProperties.value("useEveryHour").observe(cronExpression));

    final Composite everyComposite = new Composite(hourlyContent, SWT.NONE);
    everyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    everyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final Text minuteText = new Text(everyComposite, SWT.BORDER | SWT.SINGLE);
    minuteText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create());

    UpdateValueStrategy hourFrequencyStrategy = new UpdateValueStrategy();
    hourFrequencyStrategy.setAfterGetValidator(dotValidator);
    hourFrequencyStrategy.setConverter(StringToNumberConverter.toInteger(true));
    hourFrequencyStrategy.setBeforeSetValidator(new FrequencyValidator());

    context.bindValue(SWTObservables.observeText(minuteText, SWT.Modify),
            PojoProperties.value("hourFrequencyForHourly").observe(cronExpression), hourFrequencyStrategy,
            null);

    final Label minuteLabel = new Label(everyComposite, SWT.NONE);
    minuteLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    minuteLabel.setText(Messages.hourLabel);

    final Button atRadio = new Button(hourlyContent, SWT.RADIO);
    atRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    atRadio.setText(Messages.at);

    final Composite atComposite = new Composite(hourlyContent, SWT.NONE);
    atComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    atComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(0, 0).create());

    final Combo hourCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER);
    hourCombo.setItems(HOURS_IN_DAY);

    UpdateValueStrategy hourStrategy = new UpdateValueStrategy();
    hourStrategy.setConverter(StringToNumberConverter.toInteger(true));
    UpdateValueStrategy hourStrategy2 = new UpdateValueStrategy();

    NumberFormat formatter = new DecimalFormat("#00");
    hourStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true));
    context.bindValue(SWTObservables.observeText(hourCombo),
            PojoProperties.value("atHour").observe(cronExpression), hourStrategy, hourStrategy2);

    final Combo minuteCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER);
    minuteCombo.setItems(MINUTES_IN_HOURS);

    UpdateValueStrategy minuteStrategy = new UpdateValueStrategy();
    minuteStrategy.setConverter(StringToNumberConverter.toInteger(true));
    UpdateValueStrategy minuteStrategy2 = new UpdateValueStrategy();
    minuteStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true));
    context.bindValue(SWTObservables.observeText(minuteCombo),
            PojoProperties.value("atMinute").observe(cronExpression), minuteStrategy, minuteStrategy2);

    final Combo secondCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER);
    secondCombo.setItems(MINUTES_IN_HOURS);

    final IObservableValue secondObservable = PojoProperties.value("atSecond").observe(cronExpression);
    UpdateValueStrategy secondStrategy = new UpdateValueStrategy();
    secondStrategy.setConverter(StringToNumberConverter.toInteger(true));
    UpdateValueStrategy secondStrategy2 = new UpdateValueStrategy();
    secondStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true));
    context.bindValue(SWTObservables.observeText(secondCombo), secondObservable, secondStrategy,
            secondStrategy2);

    item.setControl(hourlyContent);
}

From source file:org.bonitasoft.studio.properties.sections.timer.cron.CronEditor.java

License:Open Source License

protected void createMinutesTab(TabFolder tablFolder) {
    final TabItem item = new TabItem(tablFolder, SWT.NONE);
    item.setText(Messages.minutes);/*  ww  w  . ja  v a 2  s  .co m*/
    final Composite minuteContent = new Composite(tablFolder, SWT.NONE);
    minuteContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    minuteContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(15, 10).create());

    final Label everyLabel = new Label(minuteContent, SWT.NONE);
    everyLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    everyLabel.setText(Messages.every);

    final Text minuteText = new Text(minuteContent, SWT.BORDER | SWT.SINGLE);
    minuteText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create());

    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setAfterGetValidator(dotValidator);
    strategy.setConverter(StringToNumberConverter.toInteger(true));
    strategy.setBeforeSetValidator(new FrequencyValidator());
    context.bindValue(SWTObservables.observeText(minuteText, SWT.Modify),
            PojoProperties.value("minuteFrequencyForMinute").observe(cronExpression), strategy, null);

    final Label minuteLabel = new Label(minuteContent, SWT.NONE);
    minuteLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    minuteLabel.setText(Messages.minuteLabel);

    item.setControl(minuteContent);
    cronExpression.setMode(item.getText());
}

From source file:org.bonitasoft.studio.scripting.provider.ScriptExpressionEditor.java

License:Open Source License

@Override
public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context,
        Expression inputExpression, ViewerFilter[] filters, ExpressionViewer viewer) {
    this.inputExpression = inputExpression;
    IObservableValue nameModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__NAME);
    IObservableValue interpreterModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__INTERPRETER);
    //        IObservableValue propagationModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__PROPAGATE_VARIABLE_CHANGE) ;

    UpdateValueStrategy opposite = new UpdateValueStrategy();
    opposite.setConverter(new Converter(Boolean.class, Boolean.class) {

        @Override//from w w w.j  av a2 s .  co m
        public Object convert(Object fromObject) {
            return !(Boolean) fromObject;
        }
    });

    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setAfterConvertValidator(new EmptyInputValidator(Messages.name));
    ControlDecorationSupport
            .create(dataBindingContext.bindValue(SWTObservables.observeText(expressionNameText, SWT.Modify),
                    nameModelObservable, targetToModel, null), SWT.LEFT);
    dataBindingContext.bindValue(SWTObservables.observeSelection(expressionInterpreterCombo),
            interpreterModelObservable);
    nameModelObservable.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent arg0) {
            fireSelectionChanged();
        }
    });

    editor.bindExpression(dataBindingContext, context, inputExpression, filters, viewer);

    if (inputExpression.getReturnType() != null) {
        typeCombo.setInput(inputExpression.getReturnType());
    } else {
        typeCombo.setInput(new Object());
    }
    returnTypeModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE);
    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(typeCombo),
            returnTypeModelObservable);
    dataBindingContext.bindValue(SWTObservables.observeText(typeCombo.getCombo()), returnTypeModelObservable);

    typeCombo.getCombo().setEnabled(!inputExpression.isReturnTypeFixed());
    browseClassesButton.setEnabled(!inputExpression.isReturnTypeFixed());
}

From source file:org.bonitasoft.studio.simulation.expression.SimulationDataExpressionEditor.java

License:Open Source License

@Override
public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context,
        Expression inputExpression, ViewerFilter[] filters, ExpressionViewer viewer) {

    editorInputExpression = inputExpression;
    Set<SimulationData> input = new HashSet<SimulationData>();
    IExpressionProvider provider = ExpressionEditorService.getInstance()
            .getExpressionProvider(ExpressionConstants.SIMULATION_VARIABLE_TYPE);
    for (Expression e : provider.getExpressions(context)) {
        if (inputExpression.isReturnTypeFixed()) {
            if (e.getReturnType().equals(inputExpression.getReturnType())) {
                input.add((SimulationData) e.getReferencedElements().get(0));
            }//  w  w  w . jav  a2s . co m
        } else {
            input.add((SimulationData) e.getReferencedElements().get(0));
        }
    }
    viewer.setInput(input);

    IObservableValue contentObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__CONTENT);
    IObservableValue nameObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__NAME);
    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(SimulationData.class, String.class) {

        @Override
        public Object convert(Object data) {
            return ((SimulationData) data).getName();
        }

    };
    selectionToName.setConverter(nameConverter);

    UpdateValueStrategy selectionToContent = new UpdateValueStrategy();
    IConverter contentConverter = new Converter(SimulationData.class, String.class) {

        @Override
        public Object convert(Object data) {
            return ((SimulationData) data).getName();
        }

    };
    selectionToContent.setConverter(contentConverter);

    UpdateValueStrategy selectionToReturnType = new UpdateValueStrategy();
    IConverter returnTypeConverter = new Converter(SimulationData.class, String.class) {

        @Override
        public Object convert(Object data) {
            return SimulationDataUtil.getTechnicalTypeFor((SimulationData) data);
        }

    };
    selectionToReturnType.setConverter(returnTypeConverter);

    UpdateValueStrategy selectionToReferencedData = new UpdateValueStrategy();
    IConverter referenceConverter = new Converter(SimulationData.class, List.class) {

        @Override
        public Object convert(Object data) {
            if (data != null) {
                return Collections.singletonList(data);
            } else {
                return Collections.emptyList();
            }
        }

    };
    selectionToReferencedData.setConverter(referenceConverter);

    UpdateValueStrategy referencedDataToSelection = new UpdateValueStrategy();
    IConverter referencetoDataConverter = new Converter(List.class, SimulationData.class) {

        @Override
        public Object convert(Object dataList) {
            List<SimulationData> list = (List<SimulationData>) dataList;
            if (list.isEmpty()) {
                return null;
            } else {
                return list.get(0);
            }
        }

    };
    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);
}

From source file:org.bonitasoft.studio.simulation.properties.contributions.EstimatedTimeContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayout(new FillLayout());
    context = new EMFDataBindingContext();

    final Composite probaComposite = widgetFactory.createComposite(composite);
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 10;//from w ww.  j av  a2s.  co  m
    probaComposite.setLayout(layout);

    widgetFactory.createLabel(probaComposite, Messages.ExecutionTimePlus);//$NON-NLS-1$
    Text probaText = widgetFactory.createText(probaComposite, "", SWT.BORDER);
    probaText.setLayoutData(GridDataFactory.swtDefaults().hint(80, 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);

    ControlDecoration hint = new ControlDecoration(probaText, SWT.RIGHT | SWT.TOP);
    hint.setImage(Pics.getImage(PicsConstants.hint));
    hint.setDescriptionText(Messages.EstimatedTime_hint);

    context.bindValue(SWTObservables.observeText(probaText, SWT.Modify),
            EMFEditObservables.observeValue(editingDomain, eObject,
                    SimulationPackage.Literals.SIMULATION_ACTIVITY__ESTIMATED_TIME),
            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.LoopContribution.java

License:Open Source License

@Override
public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    SimulationTransition transition;/*from  w  ww .  j ava  2 s  .c  o m*/
    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.MaximumTimeContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayout(new FillLayout());
    context = new EMFDataBindingContext();

    final Composite probaComposite = widgetFactory.createComposite(composite);
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 10;// w w  w  . j  a va 2s  . com
    probaComposite.setLayout(layout);

    widgetFactory.createLabel(probaComposite, Messages.ExecutionTimePlus);//$NON-NLS-1$
    Text probaText = widgetFactory.createText(probaComposite, "", SWT.BORDER);
    probaText.setLayoutData(GridDataFactory.swtDefaults().hint(80, 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);

    ControlDecoration hint = new ControlDecoration(probaText, SWT.RIGHT | SWT.TOP);
    hint.setImage(Pics.getImage(PicsConstants.hint));
    hint.setDescriptionText(Messages.EstimatedTime_hint);

    context.bindValue(SWTObservables.observeText(probaText, SWT.Modify),
            EMFEditObservables.observeValue(editingDomain, eObject,
                    SimulationPackage.Literals.SIMULATION_ACTIVITY__MAXIMUM_TIME),
            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;/*from   w  ww .  j ava  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);
        }
    }

}

From source file:org.bonitasoft.studio.simulation.wizards.AddSimulationDataWizardPage.java

License:Open Source License

/**
 * @param composite//  w  ww .  j  ava2s.com
 * @return
 */
private Composite createNumberConfigurationComposite(final Composite composite) {

    final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.V_SCROLL);
    scrolledComposite.setLayout(new FillLayout());
    final Composite typeComposite = new Composite(scrolledComposite, SWT.NONE);
    typeComposite.setLayout(new GridLayout(1, false));
    DynamicAddRemoveLineComposite literalsComposite = new DynamicAddRemoveLineComposite(typeComposite,
            SWT.NONE) {
        @Override
        protected void lineRemoved(int i) {
            ranges.remove(i);

            getShell().pack(true);
            getShell().layout(true, true);

            scrolledComposite.setMinSize(typeComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            scrolledComposite.setAlwaysShowScrollBars(false);
            scrolledComposite.setExpandHorizontal(true);
            scrolledComposite.setExpandVertical(true);
            scrolledComposite.setContent(typeComposite);
            if (getContainer().getCurrentPage() != null) {
                getContainer().updateButtons();
            }
        }

        @Override
        protected void lineAdded(int i) {
            getShell().pack(true);
            getShell().layout(true, true);

            scrolledComposite.setMinSize(typeComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            scrolledComposite.setAlwaysShowScrollBars(false);
            scrolledComposite.setExpandHorizontal(true);
            scrolledComposite.setExpandVertical(true);
            scrolledComposite.setContent(typeComposite);
            if (getContainer().getCurrentPage() != null) {
                getContainer().updateButtons();
            }
        }

        @Override
        protected Button createAddButton(Composite parent) {
            Button button = new Button(parent, SWT.FLAT);
            button.setText(Messages.addARange);
            return button;
        }

        @Override
        protected TabbedPropertySheetWidgetFactory getWidgetFactory() {
            return null;
        }

        @Override
        protected Composite getTopComposite() {
            return scrolledComposite;
        }

        @Override
        protected Control createLineComposite(Composite parent, Object object) {
            SimulationNumberRange range;
            if (object == null) {
                range = SimulationFactory.eINSTANCE.createSimulationNumberRange();
                ranges.add(range);
            } else {
                range = (SimulationNumberRange) object;
            }
            Composite composite = new Composite(parent, SWT.NONE);
            composite.setLayout(new GridLayout(6, false));
            //min
            Label minLabel = new Label(composite, SWT.NONE);
            minLabel.setText(Messages.AddSimulationDataWizardPage_min);
            Text minText = new Text(composite, SWT.BORDER);
            minText.setLayoutData(
                    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(100, SWT.DEFAULT).create());
            ControlDecoration minControlDecoration = new ControlDecoration(minText, SWT.LEFT | SWT.TOP);
            FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
            minControlDecoration.setImage(fieldDecoration.getImage());
            minControlDecoration.setDescriptionText(Messages.mustBeANumber);
            //max
            Label maxLiteral = new Label(composite, SWT.NONE);
            maxLiteral.setText(Messages.AddSimulationDataWizardPage_max);
            Text maxText = new Text(composite, SWT.BORDER);
            maxText.setLayoutData(
                    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(100, SWT.DEFAULT).create());
            ControlDecoration maxControlDecoration = new ControlDecoration(maxText, SWT.LEFT | SWT.TOP);
            fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
            maxControlDecoration.setImage(fieldDecoration.getImage());
            maxControlDecoration.setDescriptionText(Messages.mustBeANumber);
            //proba
            Label probaLabel = new Label(composite, SWT.NONE);
            probaLabel.setText(Messages.AddSimulationDataWizardPage_probability);
            Text probaText = new Text(composite, SWT.BORDER);
            probaText.setLayoutData(
                    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).hint(40, SWT.DEFAULT).create());
            //                ControlDecoration controlDecoration = new ControlDecoration(probaText, SWT.LEFT|SWT.TOP);
            //                fieldDecoration = FieldDecorationRegistry.getDefault()
            //                        .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
            //                controlDecoration.setImage(fieldDecoration.getImage());
            //                controlDecoration.setDescriptionText(Messages.mustBeAPercentage);
            //repartitionType

            //            Label repartitionLabel = new Label(composite, SWT.NONE);
            //            repartitionLabel.setText(Messages.AddSimulationDataWizardPage_repartition);
            //            ComboViewer comboViewer = new ComboViewer(new Combo(composite, SWT.READ_ONLY));
            //            comboViewer.setContentProvider(ArrayContentProvider.getInstance());
            //            comboViewer.setLabelProvider(new LabelProvider(){
            //               @Override
            //               public String getText(Object element) {
            //                  return ((RepartitionType)element).getName();
            //               }
            //            });
            //            comboViewer.setInput(RepartitionType.VALUES);

            context.bindValue(SWTObservables.observeText(minText, SWT.Modify),
                    EMFObservables.observeValue(range, SimulationPackage.Literals.SIMULATION_NUMBER_RANGE__MIN),
                    new UpdateValueStrategy().setConverter(StringToNumberConverter.toLong(false))
                            .setAfterGetValidator(new WrappingValidator(minControlDecoration,
                                    new StringToLongValidator(StringToNumberConverter.toLong(false)))),
                    new UpdateValueStrategy().setConverter(NumberToStringConverter.fromLong(false)));
            context.bindValue(SWTObservables.observeText(maxText, SWT.Modify),
                    EMFObservables.observeValue(range, SimulationPackage.Literals.SIMULATION_NUMBER_RANGE__MAX),
                    new UpdateValueStrategy().setConverter(StringToNumberConverter.toLong(false))
                            .setAfterGetValidator(new WrappingValidator(maxControlDecoration,
                                    new StringToLongValidator(StringToNumberConverter.toLong(false)))),
                    new UpdateValueStrategy().setConverter(NumberToStringConverter.fromLong(false)));
            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(probaText, SWT.Modify),
                    EMFObservables.observeValue(range,
                            SimulationPackage.Literals.SIMULATION_NUMBER_RANGE__PROBABILITY),
                    targetToModel, new UpdateValueStrategy().setConverter(NumberToStringConverter
                            .fromDouble(BonitaNumberFormat.getPercentInstance(), false)));
            //context.bindValue(ViewersObservables.observeSingleSelection(comboViewer), EMFObservables.observeValue(range, SimulationPackage.Literals.SIMULATION_NUMBER_RANGE__REPARTITION_TYPE));

            //            minText.addModifyListener(updateButtonModifyListener);
            //            maxText.addModifyListener(updateButtonModifyListener) ;
            //            probaText.addModifyListener(updateButtonModifyListener) ;
            ControlDecorationSupport.create(provider, SWT.TOP | SWT.LEFT);

            return composite;
        }
    };
    for (SimulationNumberRange range : ranges) {
        literalsComposite.addLine(range);
    }
    literalsComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    scrolledComposite.setMinSize(typeComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    scrolledComposite.setAlwaysShowScrollBars(false);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setContent(typeComposite);
    return scrolledComposite;
}

From source file:org.bonitasoft.studio.simulation.wizards.AddSimulationDataWizardPage.java

License:Open Source License

/**
 * @param composite/*from w  w  w.  j  ava 2 s  .  co m*/
 * @return
 */
private Composite createLiteralsConfigurationComposite(final Composite composite) {

    final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.V_SCROLL);
    scrolledComposite.setLayout(new FillLayout());

    final Composite typeComposite = new Composite(scrolledComposite, SWT.NONE);
    typeComposite.setLayout(new GridLayout(1, false));
    DynamicAddRemoveLineComposite literalsComposite = new DynamicAddRemoveLineComposite(typeComposite,
            SWT.NONE) {
        @Override
        protected void lineRemoved(int i) {
            literals.remove(i);

            getShell().pack(true);
            getShell().layout(true, true);

            scrolledComposite.setMinSize(typeComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            scrolledComposite.setAlwaysShowScrollBars(false);
            scrolledComposite.setExpandHorizontal(true);
            scrolledComposite.setExpandVertical(true);
            scrolledComposite.setContent(typeComposite);

            getContainer().updateButtons();
        }

        @Override
        protected void lineAdded(int i) {

            getShell().pack(true);
            getShell().layout(true, true);

            scrolledComposite.setMinSize(typeComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            scrolledComposite.setAlwaysShowScrollBars(false);
            scrolledComposite.setExpandHorizontal(true);
            scrolledComposite.setExpandVertical(true);
            scrolledComposite.setContent(typeComposite);
            if (getContainer().getCurrentPage() != null) {
                getContainer().updateButtons();
            }

        }

        @Override
        protected Button createAddButton(Composite parent) {
            Button button = new Button(parent, SWT.FLAT);
            button.setText(Messages.addALiteral);
            return button;
        }

        @Override
        protected TabbedPropertySheetWidgetFactory getWidgetFactory() {
            return null;
        }

        @Override
        protected Composite getTopComposite() {
            return scrolledComposite;
        }

        @SuppressWarnings("restriction")
        @Override
        protected Control createLineComposite(Composite parent, Object object) {
            SimulationLiteral literal;
            if (object == null) {
                literal = SimulationFactory.eINSTANCE.createSimulationLiteral();
                literals.add(literal);
            } else {
                literal = (SimulationLiteral) object;
            }
            Composite composite = new Composite(parent, SWT.NONE);
            composite.setLayout(new GridLayout(4, false));
            Label literalLabel = new Label(composite, SWT.NONE);
            literalLabel.setText(Messages.dataNameLabel);
            Text literalText = new Text(composite, SWT.BORDER);
            literalText.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
                    .grab(false, false).hint(200, SWT.DEFAULT).create());
            //literalText.addModifyListener(updateButtonModifyListener) ;
            Label probaLabel = new Label(composite, SWT.NONE);
            probaLabel.setText(Messages.AddSimulationDataWizardPage_probability);
            Text probaText = new Text(composite, SWT.BORDER);
            probaText.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false)
                    .hint(60, 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);
            context.bindValue(SWTObservables.observeText(literalText, SWT.Modify),
                    EMFObservables.observeValue(literal, SimulationPackage.Literals.SIMULATION_LITERAL__VALUE));
            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(probaText, SWT.Modify),
                    EMFObservables.observeValue(literal,
                            SimulationPackage.Literals.SIMULATION_LITERAL__PROBABILITY),
                    targetToModel, new UpdateValueStrategy().setConverter(NumberToStringConverter
                            .fromDouble(BonitaNumberFormat.getPercentInstance(), false)));

            ControlDecorationSupport.create(provider, SWT.TOP | SWT.LEFT);
            probaText.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                    if (getContainer().getCurrentPage() != null) {
                        getContainer().updateButtons();
                    }

                }
            });
            return composite;
        }
    };
    for (SimulationLiteral literal : literals) {
        literalsComposite.addLine(literal);
    }
    literalsComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    scrolledComposite.setMinSize(typeComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    scrolledComposite.setAlwaysShowScrollBars(false);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setContent(typeComposite);
    return scrolledComposite;
}