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);
      }
    }
  }
  protected void bindFields() {
    if (dataBindingContext != null) {
      dataBindingContext.dispose();
    }
    dataBindingContext = new EMFDataBindingContext();
    if (downloadOnly != null) {
      if (ModelHelper.getForm(element) instanceof ViewForm) {
        downloadOnly.setSelection(true);
        downloadOnly.setEnabled(false);
      } else {
        dataBindingContext.bindValue(
            SWTObservables.observeSelection(downloadOnly),
            EMFEditObservables.observeValue(
                editingDomain, element, FormPackage.Literals.FILE_WIDGET__DOWNLOAD_ONLY));
      }
    }

    dataBindingContext.bindValue(
        SWTObservables.observeSelection(imagePreview),
        EMFEditObservables.observeValue(
            editingDomain, element, FormPackage.Literals.FILE_WIDGET__USE_PREVIEW));

    IObservableValue value =
        EMFObservables.observeValue(element, FormPackage.Literals.DUPLICABLE__DUPLICATE);

    value.addValueChangeListener(
        new IValueChangeListener() {

          public void handleValueChange(ValueChangeEvent arg0) {
            if (useDocumentButton != null
                && !useDocumentButton.isDisposed()
                && element.getInputType() == FileWidgetInputType.DOCUMENT) {
              useDocumentButton.notifyListeners(SWT.Selection, new Event());
              /*}else if(!useResourceButton.isDisposed() && element.getInputType() == FileWidgetInputType.URL){
              useURLButton.notifyListeners(SWT.Selection,new Event());*/
            } else if (!useResourceButton.isDisposed()
                && element.getInputType() == FileWidgetInputType.RESOURCE) {
              useResourceButton.notifyListeners(SWT.Selection, new Event());
            }
            if (inputExpressionViewer != null
                && !getInputExpressionHint()
                    .equals(inputExpressionViewer.getMessage(IStatus.INFO))) {
              inputExpressionViewer.setMessage(getInputExpressionHint(), IStatus.INFO);
            }
          }
        });

    bindInputExpressionViewer();
    bindResourceText();
  }
  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 void bindResourceText() {
   if (resourceText != null
       && element.getInputType() == FileWidgetInputType.RESOURCE
       && !resourceText.isDisposed()) {
     dataBindingContext.bindValue(
         SWTObservables.observeText(resourceText, SWT.Modify),
         EMFEditObservables.observeValue(
             editingDomain, element, FormPackage.Literals.FILE_WIDGET__INITIAL_RESOURCE_PATH));
   }
 }
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    bindingContextsView.setCellFactory(
        new Callback<ListView<MBindingContext>, ListCell<MBindingContext>>() {

          @Override
          public ListCell<MBindingContext> call(ListView<MBindingContext> param) {
            return new BindingCell();
          }
        });

    EMFDataBindingContext dbc = new EMFDataBindingContext();

    {
      IJFXBeanValueProperty uiProp = JFXBeanProperties.value("text");
      IEMFValueProperty mProp =
          EMFProperties.value(ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID);
      dbc.bindValue(uiProp.observe(idField), mProp.observeDetail(master));
    }

    {
      IJFXBeanValueProperty uiProp = JFXBeanProperties.value("selected");
      IEMFValueProperty mProp =
          EMFProperties.value(UiPackageImpl.Literals.UI_ELEMENT__TO_BE_RENDERED);
      dbc.bindValue(uiProp.observe(renderField), mProp.observeDetail(master));
    }

    {
      IJFXBeanValueProperty uiProp = JFXBeanProperties.value("selected");
      IEMFValueProperty mProp = EMFProperties.value(UiPackageImpl.Literals.UI_ELEMENT__VISIBLE);
      dbc.bindValue(uiProp.observe(visibleField), mProp.observeDetail(master));
    }

    {
      IEMFListProperty mProp =
          EMFProperties.list(CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS);
      IObservableList mList = mProp.observeDetail(master);
      ObservableList<MBindingContext> l = AdapterFactory.adapt(mList);
      bindingContextsView.setItems(l);
    }
  }
  public void bind(EMFDataBindingContext context) {
    IObservableValue capExpressionObservable =
        SWTObservables.observeText(this.getTxtExpressionName(), SWT.Modify);

    IEMFValueProperty profileExpressionProperty =
        EMFEditProperties.value(
            editingService.getEditingDomain(),
            FeaturePath.fromList(expressionFeature, LibraryPackage.Literals.EXPRESSION__NAME));

    context.bindValue(
        capExpressionObservable, profileExpressionProperty.observe(owner), null, null);
  }
 public void setComboBindings(ScaComponent input, String id, Widget value) {
   IObservableValue scaProperty = SCAObservables.observeSimpleProperty(input, id);
   IObservableValue cPanelProperty = WidgetProperties.selection().observeDelayed(500, value);
   context.bindValue(cPanelProperty, scaProperty);
 }
  /* (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)));
  }
Esempio n. 9
0
  private Composite createForm(
      Composite parent, EMFDataBindingContext context, IObservableValue master, boolean isImport) {
    CTabFolder folder = new CTabFolder(parent, SWT.BOTTOM);

    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.ModelTooling_Common_TabDefault);

    parent = createScrollableContainer(folder);
    item.setControl(parent.getParent());

    IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);

    if (getEditor().isShowXMIId() || getEditor().isLiveModel()) {
      ControlFactory.createXMIId(parent, this);
    }

    if (isImport) {
      ControlFactory.createFindImport(parent, Messages, this, context);

      return folder;
    }

    ControlFactory.createTextField(
        parent,
        Messages.ModelTooling_Common_Id,
        master,
        context,
        textProp,
        EMFEditProperties.value(
            getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID));
    ControlFactory.createTextField(
        parent,
        Messages.CommandEditor_Name,
        master,
        context,
        textProp,
        EMFEditProperties.value(
            getEditingDomain(), CommandsPackageImpl.Literals.COMMAND__COMMAND_NAME));
    ControlFactory.createTextField(
        parent,
        Messages.CommandEditor_LabelDescription,
        master,
        context,
        textProp,
        EMFEditProperties.value(
            getEditingDomain(), CommandsPackageImpl.Literals.COMMAND__DESCRIPTION));

    // ------------------------------------------------------------
    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.CommandEditor_Category);
      l.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));

      Text t = new Text(parent, SWT.BORDER);
      TextPasteHandler.createFor(t);
      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      t.setLayoutData(gd);
      t.setEditable(false);
      context.bindValue(
          textProp.observeDelayed(200, t),
          EMFEditProperties.value(
                  getEditingDomain(),
                  FeaturePath.fromList(
                      CommandsPackageImpl.Literals.COMMAND__CATEGORY,
                      ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID))
              .observeDetail(getMaster()));

      final Button b = new Button(parent, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_FindEllipsis);
      b.setImage(createImage(ResourceProvider.IMG_Obj16_zoom));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              CommandCategorySelectionDialog dialog =
                  new CommandCategorySelectionDialog(
                      b.getShell(),
                      getEditor().getModelProvider(),
                      (MCommand) getMaster().getValue(),
                      Messages);
              dialog.open();
            }
          });
    }

    // ------------------------------------------------------------
    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.CommandEditor_Parameters);
      l.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));

      final TableViewer viewer =
          new TableViewer(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
      ObservableListContentProvider cp = new ObservableListContentProvider();
      viewer.setContentProvider(cp);
      viewer.setLabelProvider(new ComponentLabelProvider(getEditor(), Messages));

      GridData gd = new GridData(GridData.FILL_BOTH);
      viewer.getControl().setLayoutData(gd);

      IEMFEditListProperty mProp =
          EMFEditProperties.list(
              getEditingDomain(), CommandsPackageImpl.Literals.COMMAND__PARAMETERS);
      viewer.setInput(mProp.observeDetail(getMaster()));

      Composite buttonComp = new Composite(parent, SWT.NONE);
      buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
      GridLayout gl = new GridLayout();
      gl.marginLeft = 0;
      gl.marginRight = 0;
      gl.marginWidth = 0;
      gl.marginHeight = 0;
      buttonComp.setLayout(gl);

      Button b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_Up);
      b.setImage(createImage(ResourceProvider.IMG_Obj16_arrow_up));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (!viewer.getSelection().isEmpty()) {
                IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
                if (s.size() == 1) {
                  Object obj = s.getFirstElement();
                  MCommand container = (MCommand) getMaster().getValue();
                  int idx = container.getParameters().indexOf(obj) - 1;
                  if (idx >= 0) {
                    Command cmd =
                        MoveCommand.create(
                            getEditingDomain(),
                            getMaster().getValue(),
                            CommandsPackageImpl.Literals.COMMAND__PARAMETERS,
                            obj,
                            idx);

                    if (cmd.canExecute()) {
                      getEditingDomain().getCommandStack().execute(cmd);
                      viewer.setSelection(new StructuredSelection(obj));
                    }
                  }
                }
              }
            }
          });

      b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_Down);
      b.setImage(createImage(ResourceProvider.IMG_Obj16_arrow_down));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (!viewer.getSelection().isEmpty()) {
                IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
                if (s.size() == 1) {
                  Object obj = s.getFirstElement();
                  MCommand container = (MCommand) getMaster().getValue();
                  int idx = container.getParameters().indexOf(obj) + 1;
                  if (idx < container.getParameters().size()) {
                    Command cmd =
                        MoveCommand.create(
                            getEditingDomain(),
                            getMaster().getValue(),
                            CommandsPackageImpl.Literals.COMMAND__PARAMETERS,
                            obj,
                            idx);

                    if (cmd.canExecute()) {
                      getEditingDomain().getCommandStack().execute(cmd);
                      viewer.setSelection(new StructuredSelection(obj));
                    }
                  }
                }
              }
            }
          });

      b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_AddEllipsis);
      b.setImage(createImage(ResourceProvider.IMG_Obj16_table_add));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              handleAddCommandParameter();
            }
          });

      b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_Remove);
      b.setImage(createImage(ResourceProvider.IMG_Obj16_table_delete));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (!viewer.getSelection().isEmpty()) {
                List<?> keybinding = ((IStructuredSelection) viewer.getSelection()).toList();
                Command cmd =
                    RemoveCommand.create(
                        getEditingDomain(),
                        getMaster().getValue(),
                        CommandsPackageImpl.Literals.COMMAND__PARAMETERS,
                        keybinding);
                if (cmd.canExecute()) {
                  getEditingDomain().getCommandStack().execute(cmd);
                }
              }
            }
          });
    }

    item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.ModelTooling_Common_TabSupplementary);

    parent = createScrollableContainer(folder);
    item.setControl(parent.getParent());

    ControlFactory.createStringListWidget(
        parent,
        Messages,
        this,
        Messages.ModelTooling_ApplicationElement_Tags,
        ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__TAGS,
        VERTICAL_LIST_WIDGET_INDENT);

    folder.setSelection(0);

    return folder;
  }
Esempio n. 10
0
  private Composite createForm(Composite parent) {
    parent = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout(3, false);
    gl.horizontalSpacing = 10;
    parent.setLayout(gl);

    if (getEditor().isShowXMIId() || getEditor().isLiveModel()) {
      ControlFactory.createXMIId(parent, this);
    }

    IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);
    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.StringModelFragment_ParentId);
      l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

      Composite comp = new Composite(parent, SWT.NONE);
      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.horizontalSpan = 2;
      comp.setLayoutData(gd);
      gl = new GridLayout(2, false);
      gl.marginWidth = gl.marginHeight = 0;
      gl.verticalSpacing = 0;
      gl.marginLeft = gl.marginBottom = gl.marginRight = gl.marginTop = 0;
      comp.setLayout(gl);

      Text t = new Text(comp, SWT.BORDER);
      t.setEditable(false);
      gd = new GridData(GridData.FILL_HORIZONTAL);
      t.setLayoutData(gd);
      context.bindValue(
          textProp.observeDelayed(200, t),
          EMFEditProperties.value(
                  getEditingDomain(),
                  FragmentPackageImpl.Literals.STRING_MODEL_FRAGMENT__PARENT_ELEMENT_ID)
              .observeDetail(getMaster()));

      final Button b = new Button(comp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_FindEllipsis);
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              FindParentReferenceElementDialog dialog =
                  new FindParentReferenceElementDialog(
                      b.getShell(),
                      StringModelFragment.this,
                      (MStringModelFragment) getMaster().getValue());
              dialog.open();
            }
          });
    }

    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.StringModelFragment_Featurename);
      l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

      Composite comp = new Composite(parent, SWT.NONE);
      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.horizontalSpan = 2;
      comp.setLayoutData(gd);
      gl = new GridLayout(2, false);
      gl.marginWidth = gl.marginHeight = 0;
      gl.verticalSpacing = 0;
      gl.marginLeft = gl.marginBottom = gl.marginRight = gl.marginTop = 0;
      comp.setLayout(gl);

      Text t = new Text(comp, SWT.BORDER);
      gd = new GridData(GridData.FILL_HORIZONTAL);
      t.setLayoutData(gd);
      context.bindValue(
          textProp.observeDelayed(200, t),
          EMFEditProperties.value(
                  getEditingDomain(),
                  FragmentPackageImpl.Literals.STRING_MODEL_FRAGMENT__FEATURENAME)
              .observeDetail(getMaster()));

      final Button button = new Button(comp, SWT.PUSH | SWT.FLAT);
      button.setText(Messages.ModelTooling_Common_FindEllipsis);
      button.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              FeatureSelectionDialog dialog =
                  new FeatureSelectionDialog(
                      button.getShell(),
                      getEditingDomain(),
                      (MStringModelFragment) getMaster().getValue());
              dialog.open();
            }
          });
    }

    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.StringModelFragment_PositionInList);
      l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

      Text t = new Text(parent, SWT.BORDER);
      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.horizontalSpan = 2;
      t.setLayoutData(gd);
      context.bindValue(
          textProp.observeDelayed(200, t),
          EMFEditProperties.value(
                  getEditingDomain(),
                  FragmentPackageImpl.Literals.STRING_MODEL_FRAGMENT__POSITION_IN_LIST)
              .observeDetail(getMaster()));
    }

    // ------------------------------------------------------------
    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.StringModelFragment_Elements);
      l.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));

      final TableViewer viewer = new TableViewer(parent);
      viewer.setContentProvider(new ObservableListContentProvider());
      viewer.setLabelProvider(new ComponentLabelProvider(getEditor()));
      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.heightHint = 300;
      viewer.getControl().setLayoutData(gd);

      IEMFListProperty prop =
          EMFProperties.list(FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS);
      viewer.setInput(prop.observeDetail(getMaster()));

      Composite buttonComp = new Composite(parent, SWT.NONE);
      buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
      gl = new GridLayout(2, false);
      gl.marginLeft = 0;
      gl.marginRight = 0;
      gl.marginWidth = 0;
      gl.marginHeight = 0;
      buttonComp.setLayout(gl);

      Button b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_Up);
      b.setImage(getImage(b.getDisplay(), ARROW_UP));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (!viewer.getSelection().isEmpty()) {
                IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
                if (s.size() == 1) {
                  Object obj = s.getFirstElement();
                  MModelFragment container = (MModelFragment) getMaster().getValue();
                  int idx = container.getElements().indexOf(obj) - 1;
                  if (idx >= 0) {
                    Command cmd =
                        MoveCommand.create(
                            getEditingDomain(),
                            getMaster().getValue(),
                            FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS,
                            obj,
                            idx);

                    if (cmd.canExecute()) {
                      getEditingDomain().getCommandStack().execute(cmd);
                      viewer.setSelection(new StructuredSelection(obj));
                    }
                  }
                }
              }
            }
          });

      b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_Down);
      b.setImage(getImage(b.getDisplay(), ARROW_DOWN));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (!viewer.getSelection().isEmpty()) {
                IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
                if (s.size() == 1) {
                  Object obj = s.getFirstElement();
                  MModelFragment container = (MModelFragment) getMaster().getValue();
                  int idx = container.getElements().indexOf(obj) + 1;
                  if (idx < container.getElements().size()) {
                    Command cmd =
                        MoveCommand.create(
                            getEditingDomain(),
                            getMaster().getValue(),
                            FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS,
                            obj,
                            idx);

                    if (cmd.canExecute()) {
                      getEditingDomain().getCommandStack().execute(cmd);
                      viewer.setSelection(new StructuredSelection(obj));
                    }
                  }
                }
              }
            }
          });

      final ComboViewer childrenDropDown = new ComboViewer(buttonComp);
      childrenDropDown
          .getControl()
          .setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
      childrenDropDown.setContentProvider(new ArrayContentProvider());
      childrenDropDown.setLabelProvider(
          new LabelProvider() {
            @Override
            public String getText(Object element) {
              FeatureClass eclass = (FeatureClass) element;
              return eclass.label;
            }
          });
      childrenDropDown.setComparator(
          new ViewerComparator() {
            @Override
            public int compare(Viewer viewer, Object e1, Object e2) {
              FeatureClass eClass1 = (FeatureClass) e1;
              FeatureClass eClass2 = (FeatureClass) e2;
              return eClass1.label.compareTo(eClass2.label);
            }
          });

      List<FeatureClass> list = new ArrayList<FeatureClass>();
      Util.addClasses(ApplicationPackageImpl.eINSTANCE, list);
      list.addAll(
          getEditor()
              .getFeatureClasses(
                  FragmentPackageImpl.Literals.MODEL_FRAGMENT,
                  FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS));

      childrenDropDown.setInput(list);
      childrenDropDown.getCombo().select(0);

      b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setImage(getImage(b.getDisplay(), TABLE_ADD_IMAGE));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              EClass eClass =
                  ((FeatureClass)
                          ((IStructuredSelection) childrenDropDown.getSelection())
                              .getFirstElement())
                      .eClass;
              EObject eObject = EcoreUtil.create(eClass);

              Command cmd =
                  AddCommand.create(
                      getEditingDomain(),
                      getMaster().getValue(),
                      FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS,
                      eObject);

              if (cmd.canExecute()) {
                getEditingDomain().getCommandStack().execute(cmd);
                getEditor().setSelection(eObject);
              }
            }
          });

      b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
      b.setText(Messages.ModelTooling_Common_Remove);
      b.setImage(getImage(b.getDisplay(), TABLE_DELETE_IMAGE));
      b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
      b.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (!viewer.getSelection().isEmpty()) {
                List<?> elements = ((IStructuredSelection) viewer.getSelection()).toList();

                Command cmd =
                    RemoveCommand.create(
                        getEditingDomain(),
                        getMaster().getValue(),
                        FragmentPackageImpl.Literals.MODEL_FRAGMENT__ELEMENTS,
                        elements);
                if (cmd.canExecute()) {
                  getEditingDomain().getCommandStack().execute(cmd);
                }
              }
            }
          });
    }

    return parent;
  }
  @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);
  }
  /* (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)
   */
  public void createControl(
      final Composite composite,
      TabbedPropertySheetWidgetFactory widgetFactory,
      ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayout(new GridLayout(3, false));

    cCombo = widgetFactory.createCCombo(composite, SWT.BORDER);
    cCombo.setLayoutData(GridDataFactory.swtDefaults().hint(200, SWT.DEFAULT).create());
    final SimulationLoadProfileRepositoryStore profileStore =
        RepositoryManager.getInstance()
            .getRepositoryStore(SimulationLoadProfileRepositoryStore.class);
    for (IRepositoryFileStore artifact : profileStore.getChildren()) {
      cCombo.add(artifact.getDisplayName());
    }
    cCombo.setEditable(false);
    Button editLoadProfile = new Button(composite, SWT.FLAT);
    editLoadProfile.setText(Messages.edit);
    editLoadProfile.addSelectionListener(
        new SelectionAdapter() {
          /* (non-Javadoc)
           * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
           */
          @Override
          public void widgetSelected(SelectionEvent e) {
            EditSimulationLoadProfileWizard wizard =
                new EditSimulationLoadProfileWizard(
                    profileStore.getChild(
                        cCombo.getText()
                            + "."
                            + SimulationLoadProfileRepositoryStore.SIMULATION_LOADPROFILE_EXT));
            new CustomWizardDialog(Display.getCurrent().getActiveShell(), wizard).open();
          }
        });
    Button createLoadProfile = new Button(composite, SWT.FLAT);
    createLoadProfile.setText(Messages.create);
    createLoadProfile.addSelectionListener(
        new SelectionAdapter() {
          /* (non-Javadoc)
           * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
           */
          @Override
          public void widgetSelected(SelectionEvent e) {
            EditSimulationLoadProfileWizard wizard = new EditSimulationLoadProfileWizard();
            if (new CustomWizardDialog(Display.getCurrent().getActiveShell(), wizard).open()
                == IDialogConstants.OK_ID) {
              String id = wizard.getArtifact().getDisplayName();
              cCombo.add(id);
              cCombo.setText(id);
            }
          }
        });

    context = new EMFDataBindingContext();
    context.bindValue(
        SWTObservables.observeText(cCombo),
        EMFEditObservables.observeValue(
            editingDomain,
            eObject,
            SimulationPackage.Literals.SIMULATION_ABSTRACT_PROCESS__LOAD_PROFILE_ID));
    context.bindValue(
        SWTObservables.observeEnabled(editLoadProfile),
        SWTObservables.observeText(cCombo),
        new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
        new UpdateValueStrategy()
            .setConverter(
                new Converter(String.class, Boolean.class) {

                  public Object convert(Object fromObject) {
                    return ((String) fromObject).length() > 0;
                  }
                }));
  }