Example #1
0
  /** Adds validation overlay component to the control. */
  private void addValidationOverlay(
      final AttributeDescriptor descriptor,
      final IAttributeEditor editor,
      final Object defaultValue,
      final Control label) {
    final ControlDecoration decoration = new ControlDecoration(label, SWT.LEFT | SWT.BOTTOM);
    decoration.hide();

    final FieldDecoration requiredDecoration =
        FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);

    decoration.setImage(requiredDecoration.getImage());
    decoration.setDescriptionText("Invalid value");

    final IAttributeListener validationListener =
        new InvalidStateDecorationListener(decoration, descriptor, defaultValue);

    globalEventsProvider.addAttributeListener(validationListener);
    editor.addAttributeListener(validationListener);

    label.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            globalEventsProvider.removeAttributeListener(validationListener);
            editor.removeAttributeListener(validationListener);
            decoration.dispose();
          }
        });
  }
 ControlDecoration createDecorator(final Control control) {
   final ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
   final FieldDecoration fieldDecoration =
       FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
   controlDecoration.setImage(fieldDecoration.getImage());
   return controlDecoration;
 }
 private ControlDecoration createControlDecoration(Control control, Label label) {
   ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
   controlDecoration.setDescriptionText(
       label.getText() + " Not a valid entry.  Data must be numeric.");
   FieldDecoration fieldDecoration =
       FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
   controlDecoration.setImage(fieldDecoration.getImage());
   return controlDecoration;
 }
 /**
  * Enable/disable content assist decoration
  *
  * @param enabled
  */
 public void setDecoration(boolean enabled) {
   if (enabled) {
     this.decoration =
         new ControlDecoration(getSourceViewer().getTextWidget(), SWT.TOP | SWT.LEFT);
     this.decoration.setMarginWidth(25);
     this.decoration.setDescriptionText("Content Assist Available (Ctrl+Space)");
     this.decoration.setShowOnlyOnFocus(true);
     FieldDecoration dec =
         FieldDecorationRegistry.getDefault()
             .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
     this.decoration.setImage(dec.getImage());
   } else {
     this.decoration.dispose();
   }
 }
 private void createUIFieldDecorationTemplate() {
   // Decorate the combo with the info image
   int bits = SWT.TOP | SWT.LEFT;
   fControlDecoration = new ControlDecoration(fFieldTemplateCombo.getControl(), bits);
   // Configure decoration
   // No margin
   fControlDecoration.setMarginWidth(0);
   // Custom hover tip text
   fControlDecoration.setDescriptionText(
       PDEUIMessages.SplashConfigurationSection_msgDecorationTemplateSupport);
   // Custom hover properties
   fControlDecoration.setShowHover(true);
   // Hover image to use
   FieldDecoration contentProposalImage =
       FieldDecorationRegistry.getDefault()
           .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
   fControlDecoration.setImage(contentProposalImage.getImage());
   // Hide the decoration initially
   fControlDecoration.hide();
 }
  /**
   * @param controlDecoration
   * @param validator
   */
  public WrappingValidator(
      ControlDecoration controlDecoration,
      IValidator validator,
      boolean onlyChangeDecoration,
      boolean updateMessage) {
    this.controlDecoration = controlDecoration;
    this.validator = validator;
    this.onlyChangeDecoration = onlyChangeDecoration;
    this.updateMessage = updateMessage;

    FieldDecoration fieldDecoration =
        FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    error = fieldDecoration.getImage();
    fieldDecoration =
        FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
    warn = fieldDecoration.getImage();
    fieldDecoration =
        FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
    info = fieldDecoration.getImage();
  }
Example #7
0
  @Override
  protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);

    Button okButton = getButton(IDialogConstants.OK_ID);
    okButtonDecoration = new ControlDecoration(okButton, SWT.TOP | SWT.LEFT);
    okButton.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            okButtonDecoration.dispose();
          }
        });
    okButtonDecoration.hide();
    okButtonDecoration.setMarginWidth(1);
    okButtonDecoration.setImage(warningDecoration.getImage());
    okButtonDecoration.setDescriptionText(
        "The dialog contains warnings. Closing the dialog is discouraged.");
  }
  @Override
  public void createControl(Composite parent) {
    FieldDecoration infoDecor =
        FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);

    // Create controls
    super.createControl(parent);
    Composite control = (Composite) getControl();

    Group grpProjectSettings = new Group(control, SWT.NONE);
    grpProjectSettings.setText("Project Settings");

    new Label(grpProjectSettings, SWT.NONE).setText("Version:");
    txtVersion = new Text(grpProjectSettings, SWT.BORDER);

    new Label(grpProjectSettings, SWT.NONE).setText("Name:");
    txtName = new Text(grpProjectSettings, SWT.BORDER);

    ControlDecoration txtNameDecor = new ControlDecoration(txtName, SWT.LEFT | SWT.CENTER);
    txtNameDecor.setImage(infoDecor.getImage());
    txtNameDecor.setDescriptionText("Defines a human-readable name for the bundle");

    new Label(grpProjectSettings, SWT.NONE).setText("Description:");
    txtDescription = new Text(grpProjectSettings, SWT.BORDER);

    ControlDecoration txtDescDecor = new ControlDecoration(txtDescription, SWT.LEFT | SWT.CENTER);
    txtDescDecor.setImage(infoDecor.getImage());
    txtDescDecor.setDescriptionText("Defines a short human-readable description for the bundle");

    new Label(grpProjectSettings, SWT.NONE).setText("Provider:");
    txtVendor = new Text(grpProjectSettings, SWT.BORDER);

    ControlDecoration txtVendorDecor = new ControlDecoration(txtVendor, SWT.LEFT | SWT.CENTER);
    txtVendorDecor.setImage(infoDecor.getImage());
    txtVendorDecor.setDescriptionText(
        "The name of the company, organisation or individual providing the bundle");

    // Set values
    txtDescription.setText(description);
    txtVersion.setText(version.toString());
    txtVendor.setText(vendor);
    txtName.setText(name);

    // Add listeners
    ModifyListener txtModListener =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            description = txtDescription.getText();
            vendor = txtVendor.getText();
            name = txtName.getText();

            validateSettings();
          }
        };
    txtDescription.addModifyListener(txtModListener);
    txtVersion.addModifyListener(txtModListener);
    txtVendor.addModifyListener(txtModListener);
    txtName.addModifyListener(txtModListener);

    // Layout
    control.setLayout(new GridLayout());
    grpProjectSettings.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    grpProjectSettings.setLayout(new GridLayout(2, false));
    txtDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    txtVersion.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    txtVendor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    txtName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
  }
  /* (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)));
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
   */
  @Override
  public Control createControl(
      final Composite subComposite,
      final IElementParameter param,
      final int numInRow,
      final int nbInRow,
      final int top,
      final Control lastControl) {
    this.curParameter = param;
    FormData data;
    Button btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH); // $NON-NLS-1$

    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));

    data = new FormData();
    data.left = new FormAttachment(0, 120);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btnEdit.setLayoutData(data);
    btnEdit.setData(NAME, ICON_SELECTION);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.setEnabled(!param.isReadOnly());
    btnEdit.addSelectionListener(listenerSelection);

    DecoratedField dField =
        new DecoratedField(
            subComposite,
            SWT.NONE,
            new IControlCreator() {

              @Override
              public Control createControl(Composite parent, int style) {

                return new Label(parent, style);
              }
            });
    // revert btn
    Button btnRevert =
        getWidgetFactory()
            .createButton(
                subComposite,
                Messages.getString("IconSelectionController.Revert"),
                SWT.PUSH); //$NON-NLS-1$

    data = new FormData();
    data.left = new FormAttachment(btnEdit, 5);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btnRevert.setLayoutData(data);
    btnRevert.setData(NAME, ICON_REVERT);
    btnRevert.setData(PARAMETER_NAME, param.getName());
    btnRevert.setEnabled(!param.isReadOnly());
    btnRevert.addSelectionListener(listenerSelection);

    if (param.isRequired()) {
      FieldDecoration decoration =
          FieldDecorationRegistry.getDefault()
              .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
      dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    if (param.isRepositoryValueUsed()) {
      FieldDecoration decoration =
          FieldDecorationRegistry.getDefault()
              .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
      decoration.setDescription(
          Messages.getString("FileController.decoration.description")); // $NON-NLS-1$
      dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }

    Control cLayout = dField.getLayoutControl();
    filePathText = (Label) dField.getControl();
    String file = (String) elem.getPropertyValue(PARAMETER_NAME);
    if (file != null) {
      // ImageData imageData = new ImageData(file);
      // image = new Image(composite.getShell().getDisplay(), imageData);
      // filePathText.setImage(image);
    }

    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName(), 0);
    data = new FormData();
    if (lastControl != null) {
      data.left = new FormAttachment(lastControl, 0);
    } else {
      data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
      labelLabel.setAlignment(SWT.RIGHT);
    }

    // **************************
    data = new FormData();
    int currentLabelWidth = 50;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();

    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
      currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }

    if (numInRow == 1) {
      if (lastControl != null) {
        data.left = new FormAttachment(lastControl, currentLabelWidth);
      } else {
        data.left = new FormAttachment(0, currentLabelWidth);
      }
    } else {
      data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.top = new FormAttachment(btnEdit, 0, SWT.CENTER);
    data.height = 34;
    data.width = 30;
    cLayout.setLayoutData(data);

    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
  }