/** {@inheritDoc} */
  @Override
  public void refresh(final Resource resource) {
    this.dcdResource = resource;

    final DeviceConfiguration dcd = ModelUtil.getDeviceConfiguration(this.dcdResource);

    setEditable(!getPage().getEditingDomain().isReadOnly(this.dcdResource));

    for (final Binding binding : this.bindings) {
      binding.dispose();
    }
    this.bindings.clear();

    final SoftPkg model = getSoftPkg();
    if (model == null) {
      return;
    }

    final DataBindingContext context = this.getPage().getEditor().getDataBindingContext();

    this.bindings.add(
        context.bindValue(
            WidgetProperties.text(SWT.Modify)
                .observeDelayed(
                    SCAFormEditor.getFieldBindingDelay(), this.client.getIdEntry().getText()),
            EMFEditObservables.observeValue(
                getEditingDomain(), dcd, DcdPackage.Literals.DEVICE_CONFIGURATION__ID),
            new EMFEmptyStringToNullUpdateValueStrategy(),
            null));

    this.bindings.add(
        context.bindValue(
            WidgetProperties.text(SWT.Modify)
                .observeDelayed(
                    SCAFormEditor.getFieldBindingDelay(), this.client.getNameEntry().getText()),
            EMFEditObservables.observeValue(
                getEditingDomain(), dcd, DcdPackage.Literals.DEVICE_CONFIGURATION__NAME),
            new EMFEmptyStringToNullUpdateValueStrategy(),
            null));

    this.bindings.add(
        context.bindValue(
            WidgetProperties.text(SWT.Modify)
                .observeDelayed(
                    SCAFormEditor.getFieldBindingDelay(),
                    this.client.getDescriptionEntry().getText()),
            EMFEditObservables.observeValue(
                getEditingDomain(), dcd, DcdPackage.Literals.DEVICE_CONFIGURATION__DESCRIPTION),
            new EMFEmptyStringToNullUpdateValueStrategy(),
            null));

    this.client.setEditable(SCAEditorUtil.isEditableResource(getPage(), this.dcdResource));
  }
Ejemplo n.º 2
0
  /**
   * Sets up data binding between the text fields and the connection details object. Also attaches a
   * "string required" validator to the "password" text field. This validator is configured to do
   * the following on validation failure<br>
   * <li>show an ERROR decorator
   * <li>disable the "Login" button
   */
  private void setupDataBinding() {
    DataBindingContext dataBindingContext =
        new DataBindingContext(SWTObservables.getRealm(Display.getCurrent()));
    UpdateValueStrategy passwordBindingStrategy =
        new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);

    // The Validator shows error decoration and disables OK button on
    // validation failure
    passwordBindingStrategy.setBeforeSetValidator(
        new StringRequiredValidator(
            "Please enter password!", guiHelper.createErrorDecoration(passwordText), okButton));

    dataBindingContext.bindValue(
        WidgetProperties.text(SWT.Modify).observe(passwordText),
        PojoProperties.value("password").observe(connectionDetails),
        passwordBindingStrategy,
        passwordBindingStrategy);

    UpdateValueStrategy userIdBindingStrategy =
        new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    dataBindingContext.bindValue(
        WidgetProperties.text(SWT.Modify).observe(userIdText),
        PojoProperties.value("userId").observe(connectionDetails),
        userIdBindingStrategy,
        userIdBindingStrategy);
  }
Ejemplo n.º 3
0
  @SuppressWarnings("unchecked")
  @Override
  public void createControl(final Composite parent) {
    parent.setLayout(new GridLayout());
    final Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(container);

    // registry selection
    final IObservableValue<IRegistry> registryAccountObservable =
        super.createRegistrySelectionControls(container);
    // image selection
    final IObservableValue<String> imageNameObservable = createImageSelectionControls(container);

    // force tagging
    final Button forceTaggingButton = new Button(container, SWT.CHECK);
    forceTaggingButton.setText(
        WizardMessages.getString("ImagePushPage.forcetagging.label")); // $NON-NLS-1$ );
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.CENTER)
        .grab(true, false)
        .span(2, 1)
        .applyTo(forceTaggingButton);
    dbc.bindValue(
        WidgetProperties.selection().observe(forceTaggingButton),
        BeanProperties.value(ImagePushPageModel.class, ImagePushPageModel.FORCE_TAGGING)
            .observe(getModel()));

    // keep tagged image upon completion
    final Button keepTaggedImageButton = new Button(container, SWT.CHECK);
    keepTaggedImageButton.setText(
        WizardMessages.getString("ImagePushPage.keeptaggedimage.label")); // $NON-NLS-1$ );
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.CENTER)
        .grab(true, false)
        .span(2, 1)
        .applyTo(keepTaggedImageButton);
    dbc.bindValue(
        WidgetProperties.selection().observe(keepTaggedImageButton),
        BeanProperties.value(ImagePushPageModel.class, ImagePushPageModel.KEEP_TAGGED_IMAGE)
            .observe(getModel()));

    // setup validation support
    WizardPageSupport.create(this, dbc);
    dbc.addValidationStatusProvider(
        getModel().new ImagePushValidator(imageNameObservable, registryAccountObservable));
    setControl(container);
  }
Ejemplo n.º 4
0
 private void bindSelectedWithWidget(String propertyName, Text widget) {
   String fullPropertyName = "selectedTask." + propertyName;
   IObservableValue model =
       BeanProperties.value(TaskProvider.class, fullPropertyName).observe(TaskProvider.INSTANCE);
   IObservableValue target = WidgetProperties.text(SWT.Modify).observe(widget);
   ctx.bindValue(target, model);
 }
Ejemplo n.º 5
0
 @SuppressWarnings("unchecked")
 private IObservableValue<String> createImageSelectionControls(final Composite container) {
   final Label nameLabel = new Label(container, SWT.NULL);
   nameLabel.setText(WizardMessages.getString("ImagePullPushPage.name.label")); // $NON-NLS-1$
   GridDataFactory.fillDefaults()
       .align(SWT.FILL, SWT.CENTER)
       .grab(false, false)
       .applyTo(nameLabel);
   final Combo imageNameCombo = new Combo(container, SWT.DROP_DOWN);
   imageNameCombo.setToolTipText(WizardMessages.getString("ImagePushName.toolTip")); // $NON-NLS-1$
   GridDataFactory.fillDefaults()
       .align(SWT.FILL, SWT.CENTER)
       .grab(true, false)
       .applyTo(imageNameCombo);
   final ComboViewer imageNameComboViewer = new ComboViewer(imageNameCombo);
   imageNameComboViewer.setContentProvider(new ArrayContentProvider());
   imageNameComboViewer.setInput(getModel().getImage().repoTags());
   // binding must take place after the input is set, so that default
   // repo/name can be selected.
   final IObservableValue<String> imageNameObservable =
       BeanProperties.value(ImagePushPageModel.class, ImagePullPushPageModel.SELECTED_IMAGE_NAME)
           .observe(getModel());
   dbc.bindValue(WidgetProperties.selection().observe(imageNameCombo), imageNameObservable);
   // filler for the last column
   GridDataFactory.fillDefaults()
       .align(SWT.FILL, SWT.CENTER)
       .grab(false, false)
       .applyTo(new Label(container, SWT.NONE));
   return imageNameObservable;
 }
Ejemplo n.º 6
0
  protected DataBindingContext initDataBindings() throws GkException {
    DataBindingContext bindingContext = new DataBindingContext();

    IObservableValue observeImageLblDisconnectedObserveWidget =
        WidgetProperties.image().observe(lblDisconnected);
    IObservableValue connectionImageBindingsObserveValue =
        BeanProperties.value("connectionImage").observe(bindings);
    bindingContext.bindValue(
        observeImageLblDisconnectedObserveWidget,
        connectionImageBindingsObserveValue,
        new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
        null);
    //
    controller.addEnableBinding(btnConnect, "connectionAllowed");
    controller.addEnableBinding(btnDisconnect, "disconnectionAllowed");

    controller.addTextDisplayBinding(lblDisconnected_1, "connectionStatus");

    controller.addItemsBinding(comboBaudrate, "choiceBaudrate");
    controller.addItemSelectionBinding(comboBaudrate, "baudrate");
    controller.addEnableReverseBinding(comboBaudrate, "connected");

    controller.addItemsBinding(comboSerialPort, "choiceSerialPort");
    controller.addItemSelectionBinding(comboSerialPort, "serialPort");
    controller.addEnableReverseBinding(comboSerialPort, "connected");

    controller.refreshSerialPortList();
    //
    return bindingContext;
  }
  @Override
  protected void doCreateControls(Composite container, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(container);

    Group labelsGroup = new Group(container, SWT.NONE);
    labelsGroup.setText("Labels");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(labelsGroup);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(6, 6).applyTo(labelsGroup);
    Composite tableContainer = new Composite(labelsGroup, SWT.NONE);

    this.viewer = createTable(tableContainer);
    GridDataFactory.fillDefaults()
        .span(1, 5)
        .align(SWT.FILL, SWT.FILL)
        .grab(true, true)
        .applyTo(tableContainer);
    ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(viewer))
        .to(BeanProperties.value(IResourceLabelsPageModel.PROPERTY_SELECTED_LABEL).observe(model))
        .in(dbc);
    viewer.setContentProvider(new ObservableListContentProvider());
    viewer.setInput(BeanProperties.list(IResourceLabelsPageModel.PROPERTY_LABELS).observe(model));

    Button addButton = new Button(labelsGroup, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(addButton);
    addButton.setText("Add");
    addButton.addSelectionListener(onAdd());

    Button editExistingButton = new Button(labelsGroup, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(editExistingButton);
    editExistingButton.setText("Edit");
    editExistingButton.addSelectionListener(onEdit());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(editExistingButton))
        .notUpdatingParticipant()
        .to(BeanProperties.value(IResourceLabelsPageModel.PROPERTY_SELECTED_LABEL).observe(model))
        .converting(new IsNotNullOrReadOnlyBooleanConverter())
        .in(dbc);

    Button removeButton = new Button(labelsGroup, SWT.PUSH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(removeButton);
    removeButton.setText("Remove");
    removeButton.addSelectionListener(onRemove());
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(removeButton))
        .notUpdatingParticipant()
        .to(BeanProperties.value(IResourceLabelsPageModel.PROPERTY_SELECTED_LABEL).observe(model))
        .converting(new IsNotNullOrReadOnlyBooleanConverter())
        .in(dbc);
  }
  protected void bind(DataBindingContext bindingContext) {
    // Name
    bindingContext.bindValue(
        WidgetProperties.text(SWT.FocusOut).observe(propertyComposite.getTextName()),
        EMFEditProperties.value(getEditingDomain(), ScrPackage.eINSTANCE.getProperty_Name())
            .observeDetail(getCurrentSelection()));

    // Type
    bindingContext.bindValue(
        ViewersObservables.observeSingleSelection(propertyComposite.getComboType()),
        EMFEditProperties.value(getEditingDomain(), ScrPackage.eINSTANCE.getProperty_Type())
            .observeDetail(getCurrentSelection()));

    // Value
    bindingContext.bindValue(
        WidgetProperties.text(SWT.FocusOut).observe(propertyComposite.getTextValue()),
        EMFEditProperties.value(getEditingDomain(), ScrPackage.eINSTANCE.getProperty_Value())
            .observeDetail(getCurrentSelection()));
  }
 protected DataBindingContext initDataBindings() {
   final DataBindingContext bindingContext = new DataBindingContext();
   //
   final IObservableValue observeTextTextLimboFileNameObserveWidget =
       WidgetProperties.text(SWT.Modify).observe(textLimboFileName);
   final IObservableValue loadLimboFileNameModelObserveValue =
       BeanProperties.value("loadLimboFileName").observe(model);
   bindingContext.bindValue(
       observeTextTextLimboFileNameObserveWidget, loadLimboFileNameModelObserveValue, null, null);
   //
   return bindingContext;
 }
    protected void bindGUI(DataBindingContext dbc) {
      // Since we're using a JFace Viewer, we do first wrap our Table...
      TableViewer peopleViewer = new TableViewer(duckFamily);
      peopleViewer.addFilter(
          new ViewerFilter() {
            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
              return element != UNKNOWN;
            }
          });

      ViewerSupport.bind(
          peopleViewer,
          viewModel.getPeople(),
          BeanProperties.values(
              Person.class,
              new String[] {
                "name",
                "mother.name",
                "father.name",
                "mother.mother.name",
                "mother.father.name",
                "father.mother.name",
                "father.father.name"
              }));

      IObservableValue masterSelection = ViewerProperties.singleSelection().observe(peopleViewer);

      dbc.bindValue(
          WidgetProperties.text(SWT.Modify).observe(nameText),
          BeanProperties.value(Person.class, "name").observeDetail(masterSelection));

      ComboViewer mothercomboViewer = new ComboViewer(motherCombo);
      ViewerSupport.bind(
          mothercomboViewer, viewModel.getPeople(), BeanProperties.value(Person.class, "name"));

      dbc.bindValue(
          ViewerProperties.singleSelection().observe(mothercomboViewer),
          BeanProperties.value(Person.class, "mother").observeDetail(masterSelection));

      ComboViewer fatherComboViewer = new ComboViewer(fatherCombo);
      ViewerSupport.bind(
          fatherComboViewer, viewModel.getPeople(), BeanProperties.value(Person.class, "name"));

      dbc.bindValue(
          ViewerProperties.singleSelection().observe(fatherComboViewer),
          BeanProperties.value(Person.class, "father").observeDetail(masterSelection));
    }
Ejemplo n.º 11
0
  private void bindControls() {

    // Bind source file path widget to UI model
    IObservableValue widgetValue = WidgetProperties.text(SWT.Modify).observe(_javaClassText);
    IObservableValue modelValue = null;
    if (isSourcePage()) {
      modelValue = BeanProperties.value(Model.class, "sourceFilePath").observe(model);
    } else {
      modelValue = BeanProperties.value(Model.class, "targetFilePath").observe(model);
    }
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setBeforeSetValidator(
        new IValidator() {

          @Override
          public IStatus validate(final Object value) {
            final String path = value == null ? null : value.toString().trim();
            if (path == null || path.isEmpty()) {
              return ValidationStatus.error(
                  "A source file path must be supplied for the transformation.");
            }
            NewTransformationWizard wizard = (NewTransformationWizard) getWizard();
            try {
              Class<?> tempClass = wizard.getLoader().loadClass(path);
              if (tempClass == null) {
                return ValidationStatus.error(
                    "Unable to find a source file with the supplied path");
              }
            } catch (ClassNotFoundException e) {
              return ValidationStatus.error("Unable to find a source file with the supplied path");
            }
            return ValidationStatus.ok();
          }
        });
    _binding = context.bindValue(widgetValue, modelValue, strategy, null);
    ControlDecorationSupport.create(
        _binding,
        decoratorPosition,
        _javaClassText.getParent(),
        new WizardControlDecorationUpdater());

    listenForValidationChanges();
  }
    protected void bindGUI(DataBindingContext bindingContext) {
      // Since we're using a JFace Viewer, we do first wrap our Table...
      TableViewer peopleViewer = new TableViewer(duckFamily);
      peopleViewer.addFilter(
          new ViewerFilter() {
            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
              return element != UNKNOWN;
            }
          });

      // Bind viewers to model
      ViewerSupport.bind(
          peopleViewer,
          viewModel.getPeople(),
          BeanProperties.values(
              new String[] {"name", "mother.name", "father.name", "mother.mother.name"}));

      // Bind viewer selection to detail fields
      IObservableValue selection = ViewersObservables.observeSingleSelection(peopleViewer);
      bindingContext.bindValue(
          WidgetProperties.text().observe(nameText),
          BeanProperties.value((Class) selection.getValueType(), "name", String.class)
              .observeDetail(selection));

      ComboViewer mothercomboViewer = new ComboViewer(motherCombo);
      ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), BeanProperties.value("name"));
      bindingContext.bindValue(
          ViewersObservables.observeSingleSelection(mothercomboViewer),
          BeanProperties.value((Class) selection.getValueType(), "mother", Person.class)
              .observeDetail(selection));

      ComboViewer fatherComboViewer = new ComboViewer(fatherCombo);
      ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), BeanProperties.value("name"));
      bindingContext.bindValue(
          ViewersObservables.observeSingleSelection(fatherComboViewer),
          BeanProperties.value((Class) selection.getValueType(), "father", Person.class)
              .observeDetail(selection));
    }
Ejemplo n.º 13
0
  protected void bindNestedPojoProperty(
      FormToolkit toolkit,
      final IMessageManager mmng,
      final IPropertyDescriptor complexProperty,
      Composite parent,
      Object value,
      PropertyDescriptor property,
      Class<?> complexType) {
    String labelText;
    String propertyName = property.getName();
    Class<?> propertyType = property.getPropertyType();
    labelText = capitalize(splitCamelCase(propertyName));
    if (complexProperty instanceof ComplexUnionPropertyDescriptor) {
      // lets fix up the background colour!
      Label label = new Label(parent, SWT.NONE);
      label.setText(labelText);
    } else {
      Label label = toolkit.createLabel(parent, labelText);
    }

    Control widget;
    Class refType = isBeanRef(value, propertyName);
    IObservable observable;
    if (boolean.class.isAssignableFrom(propertyType)
        || Boolean.class.isAssignableFrom(propertyType)) {
      Button checkbox = new Button(parent, SWT.CHECK | SWT.BORDER);
      widget = checkbox;
      ISWTObservableValue textValue = Forms.observe(checkbox);
      observable = textValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          textValue,
          checkbox);
    } else if (refType != null) {
      Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
      String[] beanRefs = getBeanRefs(refType);
      combo.setItems(beanRefs);
      toolkit.adapt(combo, true, true);
      widget = combo;

      ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
      observable = comboValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          comboValue,
          combo);
    } else if (isEndpointUri(value, propertyName)) {
      Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
      combo.setItems(getEndpointUris());
      toolkit.adapt(combo, true, true);
      widget = combo;

      ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
      observable = comboValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          comboValue,
          combo);
    } else if (Enum.class.isAssignableFrom(propertyType)) {
      ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY | SWT.BORDER);
      combo.setContentProvider(ArrayContentProvider.getInstance());
      combo.setInput(getEnumValues((Class<? extends Enum>) propertyType));

      IViewerObservableValue comboValue = ViewersObservables.observeSingleSelection(combo);
      observable = comboValue;
      Control control = combo.getControl();
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          comboValue,
          control);

      toolkit.adapt(control, true, true);
      widget = control;

    } else {
      Text text = toolkit.createText(parent, "");
      widget = text;
      // text.setToolTipText(tooltip);
      ISWTObservableValue textValue = Forms.observe(text);
      observable = textValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          textValue,
          text);
    }
    widget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (observable != null && node != null) {
      observable.addChangeListener(
          new IChangeListener() {

            @Override
            public void handleChange(ChangeEvent event) {
              // lets notify the node that its changed
              String id = complexProperty.getId().toString();
              fireNodePropertyChangedEvent(id);
            }
          });
    }
  }
 @Override
 public IObservableValue createObservableValue(Realm realm) {
   return WidgetProperties.text().observe(realm, group);
 }
 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);
 }
Ejemplo n.º 16
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;
  }
Ejemplo n.º 17
0
  protected Composite createForm(Composite parent, EMFDataBindingContext context) {
    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);
    }

    ControlFactory.createTextField(
        parent,
        Messages.ModelTooling_Common_Id,
        getMaster(),
        context,
        textProp,
        EMFEditProperties.value(
            getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID));

    ControlFactory.createBindingContextWiget(
        parent, Messages, this, Messages.ApplicationEditor_BindingContexts);

    ControlFactory.createCheckBox(
        parent,
        Messages.ModelTooling_UIElement_ToBeRendered,
        getMaster(),
        context,
        WidgetProperties.selection(),
        EMFEditProperties.value(
            getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__TO_BE_RENDERED));
    ControlFactory.createCheckBox(
        parent,
        Messages.ModelTooling_UIElement_Visible,
        getMaster(),
        context,
        WidgetProperties.selection(),
        EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__VISIBLE));

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

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

    ControlFactory.createTextField(
        parent,
        Messages.ModelTooling_UIElement_AccessibilityPhrase,
        getMaster(),
        context,
        textProp,
        EMFEditProperties.value(
            getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__ACCESSIBILITY_PHRASE));
    ControlFactory.createStringListWidget(
        parent,
        Messages,
        this,
        Messages.ModelTooling_Context_Variables,
        UiPackageImpl.Literals.CONTEXT__VARIABLES,
        VERTICAL_LIST_WIDGET_INDENT);
    ControlFactory.createStringListWidget(
        parent,
        Messages,
        this,
        Messages.AddonsEditor_Tags,
        ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__TAGS,
        VERTICAL_LIST_WIDGET_INDENT);
    ControlFactory.createMapProperties(
        parent,
        Messages,
        this,
        Messages.ModelTooling_Contribution_PersistedState,
        ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__PERSISTED_STATE,
        VERTICAL_LIST_WIDGET_INDENT);

    if (project == null) {
      createUITreeInspection(folder);
    }

    folder.setSelection(0);

    return folder;
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  protected void doCreateControls(final Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent);

    // userdoc link (JBIDE-20401)
    this.userdocLink = new StyledText(parent, SWT.WRAP); // text set in #showHideUserdocLink
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(userdocLink);
    showHideUserdocLink();
    IObservableValue userdocUrlObservable =
        BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USERDOCURL).observe(pageModel);
    StyledTextUtils.emulateLinkAction(userdocLink, r -> onUserdocLinkClicked(userdocUrlObservable));
    userdocUrlObservable.addValueChangeListener(
        new IValueChangeListener() {

          @Override
          public void handleValueChange(ValueChangeEvent event) {
            showHideUserdocLink();
          }
        });

    IObservableValue connectionFactoryObservable =
        BeanProperties.value(ConnectionWizardPageModel.PROPERTY_CONNECTION_FACTORY)
            .observe(pageModel);

    // filler
    Label fillerLabel = new Label(parent, SWT.NONE);
    GridDataFactory.fillDefaults().span(3, 3).hint(SWT.DEFAULT, 6).applyTo(fillerLabel);

    // existing connections combo
    Label connectionLabel = new Label(parent, SWT.NONE);
    connectionLabel.setText("Connection:");
    GridDataFactory.fillDefaults()
        .align(SWT.LEFT, SWT.CENTER)
        .hint(100, SWT.DEFAULT)
        .applyTo(connectionLabel);
    Combo connectionCombo = new Combo(parent, SWT.DEFAULT);
    GridDataFactory.fillDefaults()
        .span(2, 1)
        .align(SWT.FILL, SWT.CENTER)
        .grab(true, false)
        .applyTo(connectionCombo);
    ComboViewer connectionComboViewer = new ComboViewer(connectionCombo);
    connectionComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    connectionComboViewer.setLabelProvider(new ConnectionColumLabelProvider());
    connectionComboViewer.setInput(pageModel.getAllConnections());
    Binding selectedConnectionBinding =
        ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(connectionComboViewer))
            .validatingAfterGet(
                new IsNotNullValidator(
                    ValidationStatus.cancel("You have to select or create a new connection.")))
            .to(
                BeanProperties.value(
                        ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION, IConnection.class)
                    .observe(pageModel))
            .in(dbc);
    ControlDecorationSupport.create(
        selectedConnectionBinding,
        SWT.LEFT | SWT.TOP,
        null,
        new RequiredControlDecorationUpdater());

    // server type
    Label connectionFactoryLabel = new Label(parent, SWT.NONE);
    connectionFactoryLabel.setText("Server type:");
    GridDataFactory.fillDefaults()
        .align(SWT.LEFT, SWT.CENTER)
        .hint(100, SWT.DEFAULT)
        .applyTo(connectionFactoryLabel);
    Combo connectionFactoryCombo = new Combo(parent, SWT.DEFAULT);
    GridDataFactory.fillDefaults()
        .span(2, 1)
        .align(SWT.FILL, SWT.CENTER)
        .grab(true, false)
        .applyTo(connectionFactoryCombo);
    ComboViewer connectionFactoriesViewer = new ComboViewer(connectionFactoryCombo);
    connectionFactoriesViewer.setContentProvider(ArrayContentProvider.getInstance());
    connectionFactoriesViewer.setLabelProvider(
        new ColumnLabelProvider() {

          @Override
          public String getText(Object element) {
            if (!(element instanceof IConnectionFactory)) {
              return element.toString();
            } else {
              return ((IConnectionFactory) element).getName();
            }
          }
        });
    connectionFactoriesViewer.setInput(pageModel.getAllConnectionFactories());
    final IViewerObservableValue selectedServerType =
        ViewerProperties.singleSelection().observe(connectionFactoriesViewer);
    ValueBindingBuilder.bind(selectedServerType).to(connectionFactoryObservable).in(dbc);

    // server
    Button useDefaultServerCheckbox = new Button(parent, SWT.CHECK);
    useDefaultServerCheckbox.setText("Use default server");
    GridDataFactory.fillDefaults()
        .span(3, 1)
        .align(SWT.FILL, SWT.FILL)
        .applyTo(useDefaultServerCheckbox);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useDefaultServerCheckbox))
        .to(
            BeanProperties.value(
                    ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST, IConnection.class)
                .observe(pageModel))
        .in(dbc);

    IObservableValue hasDefaultHostObservable =
        BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HAS_DEFAULT_HOST)
            .observe(pageModel);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(useDefaultServerCheckbox))
        .notUpdating(hasDefaultHostObservable)
        .in(dbc);

    Label serverLabel = new Label(parent, SWT.NONE);
    serverLabel.setText("Server:");
    GridDataFactory.fillDefaults()
        .align(SWT.LEFT, SWT.CENTER)
        .hint(100, SWT.DEFAULT)
        .applyTo(serverLabel);
    Combo serversCombo = new Combo(parent, SWT.BORDER);
    ComboViewer serversViewer = new ComboViewer(serversCombo);
    serversViewer.setContentProvider(new ObservableListContentProvider());
    serversViewer.setInput(
        BeanProperties.list(ConnectionWizardPageModel.PROPERTY_ALL_HOSTS).observe(pageModel));
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.FILL)
        .grab(true, false)
        .applyTo(serversCombo);
    final IObservableValue serverUrlObservable = WidgetProperties.text().observe(serversCombo);
    serversCombo.addFocusListener(onServerFocusLost(serverUrlObservable));
    ValueBindingBuilder.bind(serverUrlObservable)
        .converting(new TrimTrailingSlashConverter())
        .to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_HOST).observe(pageModel))
        .in(dbc);

    MultiValidator serverUrlValidator =
        new MultiValidator() {

          @Override
          protected IStatus validate() {
            Object value = serverUrlObservable.getValue();
            if (!(value instanceof String) || StringUtils.isEmpty((String) value)) {
              return ValidationStatus.cancel("Please provide an OpenShift server url.");
            } else if (!UrlUtils.isValid((String) value)) {
              return ValidationStatus.error("Please provide a valid OpenShift server url.");
            }
            return ValidationStatus.ok();
          }
        };
    ControlDecorationSupport.create(
        serverUrlValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    dbc.addValidationStatusProvider(serverUrlValidator);

    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(serversCombo))
        .notUpdatingParticipant()
        .to(
            BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USE_DEFAULT_HOST)
                .observe(pageModel))
        .converting(new InvertingBooleanConverter())
        .in(dbc);

    // connect error
    dbc.addValidationStatusProvider(
        new MultiValidator() {
          IObservableValue observable =
              BeanProperties.value(
                      ConnectionWizardPageModel.PROPERTY_CONNECTED_STATUS, IStatus.class)
                  .observe(pageModel);

          @Override
          protected IStatus validate() {
            return (IStatus) observable.getValue();
          }
        });

    // connection editors
    Group authenticationDetailsGroup = new Group(parent, SWT.NONE);
    authenticationDetailsGroup.setText("Authentication");
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.FILL)
        .span(3, 1)
        .applyTo(authenticationDetailsGroup);
    GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup);
    // additional nesting required because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618
    Composite authenticationDetailsContainer = new Composite(authenticationDetailsGroup, SWT.None);
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.FILL)
        .grab(true, true)
        .applyTo(authenticationDetailsContainer);
    this.connectionEditors =
        new ConnectionEditorsStackedView(
            connectionFactoryObservable, this, authenticationDetailsContainer, dbc);
    connectionEditors.createControls();

    // adv editors
    Composite advEditorContainer = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(authenticationDetailsGroup);
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.FILL)
        .span(3, 1)
        .grab(true, true)
        .applyTo(advEditorContainer);
    this.advConnectionEditors =
        new AdvancedConnectionEditorsStackedView(
            connectionFactoryObservable, pageModel, advEditorContainer, dbc);
    advConnectionEditors.createControls();
  }
  @Override
  protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(6, 6).applyTo(parent);
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(container);

    // label
    final Label filePatternLabel = new Label(container, SWT.NONE);
    filePatternLabel.setText("Tail options:");
    GridDataFactory.fillDefaults()
        .align(SWT.LEFT, SWT.CENTER)
        .grab(false, false)
        .applyTo(filePatternLabel);
    // input text field
    final Text filePatternText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.CENTER)
        .span(1, 1)
        .grab(true, false)
        .applyTo(filePatternText);
    final IObservableValue filePatternTextObservable =
        WidgetProperties.text(SWT.Modify).observe(filePatternText);
    final IObservableValue filePatternModelObservable =
        BeanProperties.value(TailFilesWizardPageModel.PROPERTY_FILE_PATTERN).observe(pageModel);
    ValueBindingBuilder.bind(filePatternTextObservable).to(filePatternModelObservable).in(dbc);
    // reset button (in case user inputs something and wants/needs to revert)
    final Button resetButton = new Button(container, SWT.PUSH);
    resetButton.setText("Reset");
    GridDataFactory.fillDefaults()
        .hint(100, SWT.DEFAULT)
        .span(1, 1)
        .align(SWT.FILL, SWT.CENTER)
        .grab(false, false)
        .applyTo(resetButton);
    resetButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            pageModel.resetFilePattern();
          }
        });

    // gears selection container
    final Composite gearsSelectionContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.TOP)
        .grab(true, false)
        .span(3, 1)
        .applyTo(gearsSelectionContainer);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(gearsSelectionContainer);
    // enable tail logs on all gears at the same time
    final Label selectGearsLabel = new Label(gearsSelectionContainer, SWT.NONE);
    selectGearsLabel.setText("Please, select the gears on which you want to tail files:");
    GridDataFactory.fillDefaults()
        .align(SWT.LEFT, SWT.CENTER)
        .grab(true, false)
        .span(2, 1)
        .applyTo(selectGearsLabel);

    final Composite tableContainer = new Composite(gearsSelectionContainer, SWT.NONE);
    GridDataFactory.fillDefaults()
        .align(SWT.FILL, SWT.FILL)
        .grab(true, true)
        .span(1, 2)
        .applyTo(tableContainer);
    this.viewer = createTable(tableContainer);
    dbc.bindSet(
        ViewerProperties.checkedElements(IGearGroup.class).observe(viewer),
        BeanProperties.set(TailFilesWizardPageModel.PROPERTY_SELECTED_GEAR_GROUPS)
            .observe(pageModel));
    final Button selectAllButton = new Button(gearsSelectionContainer, SWT.PUSH);
    selectAllButton.setText("Select all");
    selectAllButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            pageModel.selectAllGears();
          }
        });
    GridDataFactory.fillDefaults()
        .hint(100, SWT.DEFAULT)
        .align(SWT.FILL, SWT.TOP)
        .grab(false, false)
        .applyTo(selectAllButton);
    final Button deselectAllButton = new Button(gearsSelectionContainer, SWT.PUSH);
    deselectAllButton.setText("Deselect all");
    deselectAllButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            pageModel.deselectAllGears();
          }
        });

    GridDataFactory.fillDefaults()
        .hint(100, SWT.DEFAULT)
        .align(SWT.FILL, SWT.TOP)
        .grab(false, false)
        .applyTo(deselectAllButton);
  }
Ejemplo n.º 20
0
  private void createDecoratedTextField(
      final IPropertyDescriptor descriptor,
      FormToolkit toolkit,
      Composite parent,
      final IMessageManager mmng) {

    final Object id = descriptor.getId();
    String labelText = descriptor.getDisplayName();
    String tooltip = Tooltips.tooltip(id.toString());
    GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    boolean isDescription = NODE_DESCRIPTION.equals(id);
    Control widget;

    boolean isComplexProperty = descriptor instanceof ComplexPropertyDescriptor;
    boolean isUnionProperty = descriptor instanceof ComplexUnionPropertyDescriptor;
    if (isComplexProperty) {
      widget =
          bindNestedComplexProperties(
              toolkit,
              parent,
              mmng,
              (ComplexPropertyDescriptor) descriptor,
              id,
              labelText,
              tooltip);
    } else {
      Label label = toolkit.createLabel(parent, labelText);
      label.setToolTipText(tooltip);

      if (isDescription) {
        label.setLayoutData(gd);
      }
      if (isUnionProperty) {
        widget =
            bindNestedComplexUnionProperties(
                toolkit,
                parent,
                mmng,
                id,
                labelText,
                tooltip,
                (ComplexUnionPropertyDescriptor) descriptor);
      } else if (descriptor instanceof ExpressionPropertyDescriptor) {
        // lets create a composite and add a text are and a combo box
        // ExpandableComposite composite =
        // toolkit.createExpandableComposite(parent, SWT.HORIZONTAL);
        Composite composite = toolkit.createComposite(parent);
        GridLayout layout = new GridLayout(3, false);
        zeroMargins(layout);
        composite.setLayout(layout);
        widget = composite;

        Text text = toolkit.createText(composite, "", SWT.BORDER);
        text.setToolTipText(tooltip);

        gd = new GridData(GridData.FILL_HORIZONTAL);
        // gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
        // gd.horizontalAlignment = SWT.LEFT;
        // gd.verticalIndent = 0;
        // gd.verticalAlignment = GridData.FILL;
        text.setLayoutData(gd);
        ISWTObservableValue textValue = Forms.observe(text);

        // NOTE this code only works if the LanguageExpressionBean is
        // not
        // replaced under our feet!
        final LanguageExpressionBean expression =
            LanguageExpressionBean.bindToNodeProperty(node, id);
        final String expressionPropertyName = "expression";
        Forms.bindBeanProperty(
            bindingContext,
            mmng,
            expression,
            expressionPropertyName,
            isMandatory(expression, expressionPropertyName),
            expressionPropertyName,
            textValue,
            text);

        String languageLabel = EditorMessages.propertiesLanguageTitle;
        toolkit.createLabel(composite, languageLabel);
        // toolkit.createSeparator(composite, SWT.SEPARATOR);

        Combo combo = new Combo(composite, SWT.NONE | SWT.BORDER);
        combo.setItems(new Languages().languageArray());
        toolkit.adapt(combo, true, true);

        ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
        Forms.bindBeanProperty(
            bindingContext,
            mmng,
            expression,
            "language",
            isMandatory(expression, "language"),
            languageLabel,
            comboValue,
            combo);

        String language = expression.getLanguage();
        if (language == null) {
          language = CamelModelHelper.getDefaultLanguageName();
          expression.setLanguage(language);
        }

        // now lets forward property events to the node
        expression.addPropertyChangeListener(
            new PropertyChangeListener() {
              /*
               * (non-Javadoc)
               *
               * @see
               * java.beans.PropertyChangeListener#propertyChange(java
               * .beans .PropertyChangeEvent)
               */
              @Override
              public void propertyChange(PropertyChangeEvent event) {
                node.firePropertyChange(id.toString(), null, expression);
              }
            });
      } else {
        String propertyName = getPropertyName(id);
        Class refType = isBeanRef(node, propertyName);
        if (refType != null) {
          Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
          String[] beanRefs = getBeanRefs(refType);
          combo.setItems(beanRefs);
          toolkit.adapt(combo, true, true);
          widget = combo;

          ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              comboValue,
              combo);
        } else if (isEndpointUri(node, propertyName)) {
          Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
          combo.setItems(getEndpointUris());
          toolkit.adapt(combo, true, true);
          widget = combo;

          ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              comboValue,
              combo);
        } else if (descriptor instanceof BooleanPropertyDescriptor) {
          Button checkbox = new Button(parent, SWT.CHECK);
          widget = checkbox;
          ISWTObservableValue textValue = Forms.observe(checkbox);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              textValue,
              checkbox);
        } else if (descriptor instanceof ListPropertyDescriptor) {
          if (CamelModelHelper.isPropertyListOFSetHeaders(id)) {
            Control control = bindSetHeaderTable(toolkit, parent, id);
            widget = control;
          } else {
            Control control = bindListOfValues(toolkit, parent, id);
            widget = control;
          }
        } else if (descriptor instanceof EnumPropertyDescriptor) {
          EnumPropertyDescriptor enumProperty = (EnumPropertyDescriptor) descriptor;
          ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY | SWT.BORDER);
          combo.setContentProvider(ArrayContentProvider.getInstance());
          combo.setInput(getEnumValues(enumProperty.getEnumType()));

          IViewerObservableValue comboValue = ViewersObservables.observeSingleSelection(combo);
          Control control = combo.getControl();
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              comboValue,
              control);

          toolkit.adapt(control, true, true);
          widget = control;
        } else {
          Text text;
          if (isDescription) {
            text =
                toolkit.createText(
                    parent, "", SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
          } else {
            text = toolkit.createText(parent, "", SWT.BORDER);
          }
          text.setToolTipText(tooltip);
          widget = text;
          ISWTObservableValue textValue = Forms.observe(text);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              textValue,
              text);
        }
      }
    }
    boolean isComplexOrUnion = isComplexProperty || isUnionProperty;
    if (isDescription || isComplexOrUnion) {
      gd = new GridData(GridData.FILL_BOTH);
      gd.heightHint = 90;
      gd.grabExcessVerticalSpace = true;
      gd.grabExcessHorizontalSpace = true;
      if (isComplexOrUnion) {
        gd.heightHint = -1;
      }
      if (isComplexProperty) {
        gd.horizontalSpan = 2;
      }

    } else {
      gd = new GridData(GridData.FILL_HORIZONTAL);
    }
    gd.widthHint = 250;
    widget.setLayoutData(gd);
  }
  /** {@inheritDoc} */
  @Override
  public void createControl(final Composite parent) {
    final Composite client = new Composite(parent, SWT.NULL);
    client.setLayout(new GridLayout(2, false));

    Label label;
    final GridDataFactory labelFactory = GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP);
    Text text;
    final GridDataFactory textFactory =
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false);

    label = new Label(client, SWT.NULL);
    label.setLayoutData(labelFactory.create());
    label.setText("Company:");
    text = new Text(client, SWT.BORDER);
    text.setLayoutData(textFactory.create());
    this.context.bindValue(
        WidgetProperties.text(SWT.Modify).observe(text),
        EMFObservables.observeValue(this.author, SpdPackage.Literals.AUTHOR__COMPANY),
        null,
        null);

    label = new Label(client, SWT.NULL);
    label.setLayoutData(labelFactory.create());
    label.setText("Webpage:");
    text = new Text(client, SWT.BORDER);
    text.setLayoutData(textFactory.create());
    this.context.bindValue(
        WidgetProperties.text(SWT.Modify).observe(text),
        EMFObservables.observeValue(this.author, SpdPackage.Literals.AUTHOR__WEBPAGE),
        null,
        null);

    label = new Label(client, SWT.NULL);
    label.setLayoutData(labelFactory.create());
    label.setText("Names:");
    final Composite namesComp = new Composite(client, SWT.NULL);
    namesComp.setLayoutData(
        new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL));
    final GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    namesComp.setLayout(layout);

    this.tableViewer = new TableViewer(namesComp, SWT.BORDER);
    this.tableViewer.setContentProvider(
        new IStructuredContentProvider() {

          @Override
          public void inputChanged(
              final Viewer viewer, final Object oldInput, final Object newInput) {
            // TODO Auto-generated method stub

          }

          @Override
          public void dispose() {
            // TODO Auto-generated method stub

          }

          @Override
          public Object[] getElements(final Object inputElement) {
            return ((Author) inputElement).getName().toArray();
          }
        });
    this.tableViewer.setLabelProvider(new LabelProvider());
    this.tableViewer.setInput(this.author);
    this.tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));

    final Button addButton = new Button(namesComp, SWT.PUSH);
    addButton.setText("Add");
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    addButton.addSelectionListener(
        new SelectionAdapter() {
          /** {@inheritDoc} */
          @Override
          public void widgetSelected(final SelectionEvent e) {
            handleAddName();
          }
        });

    final Button removeButton = new Button(namesComp, SWT.PUSH);
    removeButton.setText("Remove");
    removeButton.setEnabled(false);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    this.tableViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          @Override
          public void selectionChanged(final SelectionChangedEvent event) {
            removeButton.setEnabled(!event.getSelection().isEmpty());
          }
        });
    removeButton.addSelectionListener(
        new SelectionAdapter() {
          /** {@inheritDoc} */
          @Override
          public void widgetSelected(final SelectionEvent e) {
            AuthorWizardPage.this
                .author
                .getName()
                .remove(
                    ((IStructuredSelection) AuthorWizardPage.this.tableViewer.getSelection())
                        .getFirstElement());
            AuthorWizardPage.this.tableViewer.refresh();
          }
        });

    this.pageSupport = WizardPageSupport.create(this, this.context);

    this.setControl(client);
  }
  private Composite createForm(
      Composite parent,
      final EMFDataBindingContext context,
      WritableValue 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());

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

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

    if (isImport) {
      ControlFactory.createFindImport(parent, Messages, this, context);
      folder.setSelection(0);
      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.ModelTooling_UIElement_AccessibilityPhrase,
        getMaster(),
        context,
        textProp,
        EMFEditProperties.value(
            getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__ACCESSIBILITY_PHRASE));
    ControlFactory.createSelectedElement(
        parent, this, context, Messages.PerspectiveStackEditor_SelectedElement);

    // ------------------------------------------------------------
    {
      Label l = new Label(parent, SWT.NONE);
      l.setText(Messages.PerspectiveStackEditor_Perspectives);
      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(), Messages));
      GridData gd = new GridData(GridData.FILL_BOTH);
      viewer.getControl().setLayoutData(gd);

      IEMFListProperty prop =
          EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
      viewer.setInput(prop.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();
                  MElementContainer<?> container = (MElementContainer<?>) getMaster().getValue();
                  int idx = container.getChildren().indexOf(obj) - 1;
                  if (idx >= 0) {
                    if (Util.moveElementByIndex(
                        getEditingDomain(), (MUIElement) obj, getEditor().isLiveModel(), idx)) {
                      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();
                  MElementContainer<?> container = (MElementContainer<?>) getMaster().getValue();
                  int idx = container.getChildren().indexOf(obj) + 1;
                  if (idx < container.getChildren().size()) {
                    if (Util.moveElementByIndex(
                        getEditingDomain(), (MUIElement) obj, getEditor().isLiveModel(), idx)) {
                      viewer.setSelection(new StructuredSelection(obj));
                    }
                  }
                }
              }
            }
          });

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

      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<?> elements = ((IStructuredSelection) viewer.getSelection()).toList();

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

    ControlFactory.createCheckBox(
        parent,
        Messages.ModelTooling_UIElement_ToBeRendered,
        getMaster(),
        context,
        WidgetProperties.selection(),
        EMFEditProperties.value(
            getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__TO_BE_RENDERED));
    ControlFactory.createCheckBox(
        parent,
        Messages.ModelTooling_UIElement_Visible,
        getMaster(),
        context,
        WidgetProperties.selection(),
        EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__VISIBLE));

    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.CategoryEditor_Tags,
        ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__TAGS,
        VERTICAL_LIST_WIDGET_INDENT);
    ControlFactory.createMapProperties(
        parent,
        Messages,
        this,
        Messages.ModelTooling_Contribution_PersistedState,
        ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__PERSISTED_STATE,
        VERTICAL_LIST_WIDGET_INDENT);

    if (project == null) {
      createUITreeInspection(folder);
    }

    folder.setSelection(0);

    return folder;
  }
Ejemplo n.º 23
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 TabItem doCreateForm(
      TabFolder folder, EditingDomain domain, DataBindingContext dbc, IObservableValue master) {

    TabItem item = new TabItem(folder, SWT.NONE);
    IValueProperty textProp = WidgetProperties.text();
    dbc.bindValue(
        textProp.observe(item),
        EMFEditObservables.observeDetailValue(
            Realm.getDefault(), domain, master, EXTLibraryPackage.Literals.LIBRARY__WRITERS),
        new UpdateValueStrategy(),
        new UpdateValueStrategy().setConverter(new LengthConverter()));

    Composite comp = new Composite(folder, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    comp.setLayout(layout);

    TableViewer writerViewer =
        new TableViewer(
            comp, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
    writerViewer.getTable().setHeaderVisible(true);
    writerViewer.getTable().setLinesVisible(true);

    ObservableListContentProvider cp = new ObservableListContentProvider();
    writerViewer.setContentProvider(cp);

    CondiditionalTemplate[] tpl = new CondiditionalTemplate[3];
    tpl[0] =
        new CondiditionalTemplate("${0}") {

          @Override
          public boolean isTemplate(EObject element) {
            return element instanceof Writer && ((Writer) element).getFirstName() != null;
          }
        };
    tpl[1] =
        new CondiditionalTemplate("${0}") {

          @Override
          public boolean isTemplate(EObject element) {
            return element instanceof Writer && ((Writer) element).getLastName() != null;
          }
        };
    tpl[2] =
        new CondiditionalTemplate("-") {

          @Override
          public boolean isTemplate(EObject element) {
            return true;
          }
        };

    EStructuralFeature[] features = new EStructuralFeature[3];
    features[0] = EXTLibraryPackage.Literals.PERSON__FIRST_NAME;
    features[1] = EXTLibraryPackage.Literals.PERSON__LAST_NAME;

    IObservableMap[] map = EMFEditObservables.observeMaps(domain, cp.getKnownElements(), features);

    TableViewerColumn c = new TableViewerColumn(writerViewer, SWT.NONE);
    c.getColumn().setText("Firstname");
    layout.setColumnData(c.getColumn(), new ColumnWeightData(1, 120));
    c.setLabelProvider(
        new ObservableColumnLabelProvider(
            new IObservableMap[] {map[0]}, Arrays.asList(tpl[0], tpl[2])));

    c = new TableViewerColumn(writerViewer, SWT.NONE);
    c.getColumn().setText("Lastname");
    layout.setColumnData(c.getColumn(), new ColumnWeightData(1, 120));
    c.setLabelProvider(
        new ObservableColumnLabelProvider(
            new IObservableMap[] {map[1]}, Arrays.asList(tpl[1], tpl[2])));

    MenuManager mgr = new MenuManager();
    writerViewer.getControl().setMenu(mgr.createContextMenu(writerViewer.getControl()));
    getSite()
        .registerContextMenu(
            "org.eclipse.emf.examples.library.databinding.writer", mgr, writerViewer);

    writerViewer.setInput(
        EMFEditObservables.observeDetailList(
            Realm.getDefault(), domain, master, EXTLibraryPackage.Literals.LIBRARY__WRITERS));
    item.setControl(comp);

    return item;
  }
Ejemplo n.º 25
0
  @Override
  protected Control createContents(Composite parent) {
    Q7UIPlugin.getDisplay().addFilter(SWT.KeyUp, keyListener);

    createToolBar(parent);
    createTabFolder(parent);

    ITestCase model = getModel();
    Q7InternalTestCase internalModel =
        new Q7InternalTestCase(
            ModelManager.getModelManager().getModel(), "recording_snippet", scenario);

    scriptPart =
        new ScriptComposite(
            internalModel,
            model != null ? (IFile) getModel().getResource() : null,
            getShell(),
            SWT.SCROLL_LOCK);
    ComputedValue recordingMode =
        new ComputedValue() {
          @Override
          protected Object calculate() {
            return recordingSupport.getMode();
          }
        };
    dbc.bindValue(scriptPart.observeRecordingMode(), recordingMode);
    script = tabFolder.addTab(scriptPart);
    try {
      contextsTable = new ContextsTable(internalModel);
    } catch (ModelException e) {
      Q7UIPlugin.log(e);
    }
    contextsTable.setProject(getSavedProject());
    dbc.bindValue(contextsTable.observeRecordingMode(), recordingMode);
    tabFolder.addTab(contextsTable);

    try {
      verificationsTable = new VerificationsTable(internalModel);
    } catch (ModelException e) {
      Q7UIPlugin.log(e);
    }
    verificationsTable.setProject(getSavedProject());
    dbc.bindValue(verificationsTable.observeRecordingMode(), recordingMode);
    tabFolder.addTab(verificationsTable);

    DescriptionComposite descPart = new DescriptionComposite(scenario);
    dbc.bindValue(descPart.observeRecordingMode(), recordingMode);
    tabFolder.addTab(descPart);
    OptionsComposite optionsComposite = new OptionsComposite();
    tabFolder.addTab(optionsComposite);
    optionsComposite.setOptionChangeCallback(
        new Runnable() {
          public void run() {
            if (recordingSupport.getMode() == RecordingMode.Recording) {
              recordingSupport.sendFeatures();
            }
          }
        });

    selectTab(script);

    statusBar =
        new StatusBarComposite() {
          @Override
          protected void layout() {
            super.layout();
            tabFolder.layout(true);
          }

          @Override
          protected void handleError(final String taskMessage, Throwable e) {
            if (e instanceof CoreException
                && (e.getMessage().equals("Connection reset")
                    || e //$NON-NLS-1$
                        .getMessage()
                        .equals("Connection refused: connect"))) { // $NON-NLS-1$
              return; // Ignore connection lost exception, this situation
              // handled in RecordingSupport class
            }
            if (e instanceof CoreException) {
              final IStatus status = ((CoreException) e).getStatus();
              if (status instanceof ExecutionStatus && PlatformUI.isWorkbenchRunning()) {
                WorkbenchUtils.uiRun(
                    new Runnable() {
                      public void run() {
                        displayExecutionFailure((ExecutionStatus) status);
                      }
                    });
                return;
              }
            }
            super.handleError(taskMessage, e);
          };
        };
    statusBar.createControl(parent);
    // statusBar.getControl().addKeyListener(keyListener);
    dbc.bindValue(
        WidgetProperties.text().observe(getShell()),
        new ComputedValue() {
          @Override
          protected Object calculate() {
            StringBuilder text = new StringBuilder(Messages.ControlPanelWindow_Title);
            ITestCase model = getModel();
            if (model != null && model.exists()) {
              try {
                text.append(" - ").append(model.getElementName()); // $NON-NLS-1$
                text.append(" (") // $NON-NLS-1$
                    .append(model.getQ7Project().getName())
                    .append(")"); // $NON-NLS-1$
              } catch (ModelException e) {
                Q7UIPlugin.log(e);
              }
            }
            AutLaunch aut = recordingSupport.getAUT();
            if (aut != null) {
              text.append(" - ").append(aut.getAut().getName()); // $NON-NLS-1$
            }
            switch (recordingSupport.getMode()) {
              case Connecting:
                text.append(Messages.ControlPanelWindow_StatusConnection);
                break;
              case Recording:
                text.append(Messages.ControlPanelWindow_StatusRecording);
                break;
              case Asserting:
                text.append(Messages.ControlPanelWindow_StatusAsserting);
                break;
              case ImageRecognition:
                text.append(Messages.ControlPanelWindow_StatusImageRecognition);
                break;
              case Replaying:
                text.append(Messages.ControlPanelWindow_StatusReplaying);
                break;
              case WaitingForAUTRestart:
                text.append(Messages.ControlPanelWindow_StatusWaitingAUTToRestart);
                break;
              default:
                break;
            }
            return text.toString();
          }
        });

    tabFolder.setFocus();

    return tabFolder;
  }