protected void bindInputExpressionViewer() {
    if (element.getInputType() == FileWidgetInputType.URL
        || element.getInputType() == FileWidgetInputType.DOCUMENT) {
      if (inputExpressionViewer != null && !inputExpressionViewer.getControl().isDisposed()) {
        Expression input = element.getInputExpression();
        if (input == null) {
          input = ExpressionFactory.eINSTANCE.createExpression();
          editingDomain
              .getCommandStack()
              .execute(
                  SetCommand.create(
                      editingDomain,
                      element,
                      FormPackage.Literals.WIDGET__INPUT_EXPRESSION,
                      input));
        }

        inputExpressionViewer.setEditingDomain(editingDomain);
        inputExpressionViewer.setInput(element);
        dataBindingContext.bindValue(
            ViewersObservables.observeSingleSelection(inputExpressionViewer),
            EMFEditObservables.observeValue(
                editingDomain, element, FormPackage.Literals.WIDGET__INPUT_EXPRESSION));
      }
    }
  }
  protected Control createInputExpressionComposite(
      Section section, TabbedPropertySheetWidgetFactory widgetFactory) {
    final Composite client = widgetFactory.createComposite(section);
    client.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    client.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());

    inputExpressionViewer =
        new ExpressionViewer(
            client,
            SWT.BORDER,
            widgetFactory,
            editingDomain,
            FormPackage.Literals.WIDGET__INPUT_EXPRESSION);
    inputExpressionViewer.addFilter(
        new AvailableExpressionTypeFilter(
            new String[] {
              ExpressionConstants.VARIABLE_TYPE,
              ExpressionConstants.SCRIPT_TYPE,
              ExpressionConstants.CONSTANT_TYPE,
              ExpressionConstants.DOCUMENT_REF_TYPE,
              ExpressionConstants.PARAMETER_TYPE
            }));

    inputExpressionViewer.setMessage(getInputExpressionHint(), IStatus.INFO);
    inputExpressionViewer
        .getControl()
        .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    return client;
  }
  private void createNameAndDescription(Composite composite) {
    Label nameLabel = new Label(composite, SWT.NONE);
    nameLabel.setText(Messages.dataNameLabel);
    final Text labelText = new Text(composite, SWT.BORDER);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    // Add an validator so that age can only be a number
    IValidator validator =
        new IValidator() {

          Set<String> existingDataNames = null;

          @Override
          public IStatus validate(Object arg0) {
            if (existingDataNames == null) {
              existingDataNames = new HashSet<String>();
              if (element != null) {
                for (SimulationData simuData : element.getSimulationData()) {
                  existingDataNames.add(simuData.getName());
                }
              }
            }

            if (existingDataNames.contains(labelText.getText())) {

              return ValidationStatus.error("Data name already exists.");
            }
            return ValidationStatus.ok();
          }
        };
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(validator);

    Binding bindingDataName =
        context.bindValue(
            SWTObservables.observeText(labelText, SWT.Modify),
            PojoObservables.observeValue(this, "dataName"),
            strategy,
            null);

    ControlDecorationSupport.create(bindingDataName, SWT.TOP | SWT.LEFT);
    // labelText.addModifyListener(updateButtonModifyListener) ;

    Label isExpressionLabel = new Label(composite, SWT.NONE);
    isExpressionLabel.setText(Messages.BasedOn);

    Composite radioBasedComposite = new Composite(composite, SWT.NONE);
    radioBasedComposite.setLayout(new GridLayout(2, true));

    isExpressionBased = new Button(radioBasedComposite, SWT.RADIO);
    isExpressionBased.setText(Messages.Expression);
    isExpressionBased.setSelection(expressionBased);
    isOtherBased = new Button(radioBasedComposite, SWT.RADIO);
    isOtherBased.setSelection(!expressionBased);
    isOtherBased.setText(Messages.AddSimulationDataWizardPage_probability);
    context.bindValue(
        SWTObservables.observeSelection(isExpressionBased),
        PojoObservables.observeValue(this, "expressionBased"));
    context.bindValue(
        SWTObservables.observeSelection(isOtherBased),
        PojoObservables.observeValue(this, "expressionBased"),
        new UpdateValueStrategy()
            .setConverter(
                new Converter(Boolean.class, Boolean.class) {
                  @Override
                  public Object convert(Object fromObject) {
                    return !(Boolean) fromObject;
                  }
                }),
        new UpdateValueStrategy()
            .setConverter(
                new Converter(Boolean.class, Boolean.class) {
                  @Override
                  public Object convert(Object fromObject) {
                    return !(Boolean) fromObject;
                  }
                }));

    Label expressionLabel = new Label(composite, SWT.NONE);
    expressionLabel.setText(Messages.Expression);

    ExpressionViewer expressionViewer =
        new ExpressionViewer(composite, SWT.BORDER, null); // FIXME: Expressionviewer
    expressionViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    if (element != null) {
      expressionViewer.setInput(element);
    } else {
      expressionViewer.setInput(data.eContainer());
    }
    expressionViewer.addFilter(
        new AvailableExpressionTypeFilter(
            new String[] {
              ExpressionConstants.CONSTANT_TYPE,
              ExpressionConstants.VARIABLE_TYPE,
              ExpressionConstants.SCRIPT_TYPE,
              ExpressionConstants.SIMULATION_VARIABLE_TYPE
            }));
    expressionViewer.setSelection(new StructuredSelection(dataExpression));

    context.bindValue(
        SWTObservables.observeVisible(expressionLabel),
        SWTObservables.observeSelection(isExpressionBased));
    context.bindValue(
        SWTObservables.observeVisible(expressionViewer.getControl()),
        SWTObservables.observeSelection(isExpressionBased));

    isOtherBased.addSelectionListener(updateButtonSelectionListener);
    isExpressionBased.addSelectionListener(updateButtonSelectionListener);
  }
예제 #4
0
  /* (non-Javadoc)
   * @see org.bonitasoft.studio.common.properties.IExtensibleGridPropertySectionContribution#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory, org.bonitasoft.studio.common.properties.ExtensibleGridPropertySection)
   */
  @Override
  public void createControl(
      Composite composite,
      TabbedPropertySheetWidgetFactory widgetFactory,
      ExtensibleGridPropertySection extensibleGridPropertySection) {
    SimulationTransition transition;
    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)));
  }