Beispiel #1
0
  private void addDecorator(Composite parent, final Text control) {
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.horizontalIndent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth();
    control.setLayoutData(gd);

    final ControlDecoration decoration = new ControlDecoration(control, SWT.TOP | SWT.LEFT, parent);
    decoration.hide();
    control.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            String name = control.getText();
            if (name.trim().isEmpty()) {
              decoration.setImage(
                  FieldDecorationRegistry.getDefault()
                      .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR)
                      .getImage());
              decoration.setDescriptionText(
                  Messages.getString("ActionDialog.ErrEmptyName")); // $NON-NLS-1$
              decoration.show();
            } else {
              decoration.hide();
            }
            validate();
          }
        });
  }
Beispiel #2
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();
          }
        });
  }
Beispiel #3
0
  /**
   * Creates the input score text.
   *
   * @param main the main
   * @param player the player
   */
  private void createInputScoreText(Composite main, IPlayer player) {
    Text inputScoreText = this.toolkit.createText(main, "", SWT.CENTER | SWT.BORDER);
    inputScoreText.setFont(OpenDartsFormsToolkit.getFont(OpenDartsFormsToolkit.FONT_SCORE_INPUT));
    inputScoreText.setEnabled(false);
    this.playerScoreInput.put(player, inputScoreText);

    // Tooltip
    ShortcutsTooltip tooltip = new ShortcutsTooltip(inputScoreText);
    tooltip.setPopupDelay(200);

    // layout
    int indent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth() + 2;
    GridDataFactory.fillDefaults()
        .grab(true, false)
        .indent(indent, SWT.DEFAULT)
        .hint(SWT.DEFAULT, 100)
        .applyTo(inputScoreText);

    // decoration
    ControlDecoration dec = new ControlDecoration(inputScoreText, SWT.TOP | SWT.LEFT);

    // listener
    TextInputListener listener =
        new TextInputListener(this.getSite().getShell(), inputScoreText, this.game, player, dec);
    inputScoreText.addKeyListener(listener);

    inputScoreText.addTraverseListener(new CancelTraverseListener());
  }
 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;
 }
Beispiel #6
0
  public static void addDecoration(Text text) {

    Image imageDecoration =
        FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION)
            .getImage();
    ControlDecoration decoration = new ControlDecoration(text, SWT.RIGHT | SWT.TOP);
    decoration.setImage(imageDecoration);
    decoration.setDescriptionText(POINTS);
    decoration.setMarginWidth(2);
  }
 private static ControlDecoration createDecoration(
     String text, String fieldDecorationImageKey, int position, Control control) {
   ControlDecoration decoration = new ControlDecoration(control, position);
   Image icon =
       FieldDecorationRegistry.getDefault().getFieldDecoration(fieldDecorationImageKey).getImage();
   decoration.setImage(icon);
   decoration.setDescriptionText(text);
   decoration.setShowHover(true);
   decoration.hide();
   return decoration;
 }
Beispiel #8
0
  /**
   * Adds little bulb decoration to given control. Bulb will appear in top left corner of control
   * after giving focus for this control.
   *
   * <p>After clicking on bulb image text from <code>tooltip</code> will appear.
   *
   * @param control instance of {@link Control} object with should be decorated
   * @param tooltip text value which should appear after clicking on bulb image.
   */
  public static void addBulbDecorator(final Control control, final String tooltip) {
    ControlDecoration dec = new ControlDecoration(control, SWT.TOP | SWT.LEFT);

    dec.setImage(
        FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL)
            .getImage());

    dec.setShowOnlyOnFocus(true);
    dec.setShowHover(true);

    dec.setDescriptionText(tooltip);
  }
  /**
   * @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();
  }
 /**
  * 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();
 }
  /*
   * (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) {
    if (param.getDisplayName().startsWith("!!")) { // $NON-NLS-1$
      if (param.getFieldType() == EParameterFieldType.MODULE_LIST) {
        param.setDisplayName(EParameterName.MODULE_LIST.getDisplayName());
      }
    }

    DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, cbCtrl);
    if (param.isRequired()) {
      FieldDecoration decoration =
          FieldDecorationRegistry.getDefault()
              .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
      dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }

    Control cLayout = dField.getLayoutControl();
    CCombo combo = (CCombo) dField.getControl();

    combo.setEditable(false);
    cLayout.setBackground(subComposite.getBackground());
    combo.setEnabled(!param.isReadOnly());
    combo.addSelectionListener(listenerSelection);
    if (elem instanceof Node) {
      combo.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }

    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    FormData 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 = STANDARD_LABEL_WIDTH;
    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(0, top);
    cLayout.setLayoutData(data);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);

    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(cLayout, 0, SWT.RIGHT);
    data.right =
        new FormAttachment(
            cLayout, ITabbedPropertyConstants.HSPACE + STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btnEdit.setLayoutData(data);
    btnEdit.setData(NAME, MODULE);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.setEnabled(!param.isReadOnly());
    btnEdit.addSelectionListener(listenerSelection);

    // **********************
    hashCurControls.put(param.getName(), combo);
    hashCurControls.put(param.getName() + BUTTON_EDIT, btnEdit);
    updateData();
    // this.dynamicTabbedPropertySection.updateColumnList(null);

    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return cLayout;
  }
  /*
   * (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;
  }
  /* (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)));
  }
  @Override
  public void createControl(Composite parent) {
    final Composite compo = new Composite(parent, SWT.NONE);
    compo.setLayout(new GridLayout(3, false));

    Label label = new Label(compo, SWT.NONE);
    label.setText("File");

    final Text text = new Text(compo, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(text);

    // decorator for text, starts with warning because the text starts empty
    final ControlDecoration controlDecoration = new ControlDecoration(text, SWT.RIGHT | SWT.TOP);
    controlDecoration.setDescriptionText("Please enter a new .fet file");
    controlDecoration.setImage(
        FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR)
            .getImage());

    // listener which validates the text: if the input is a non-existing file, and it's extension is
    // fet:
    // hides the decorator + puts the file in the model + sets the page to complete
    text.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (e.getSource() instanceof Text) {
              String text = ((Text) e.getSource()).getText();
              File f = new File(text);
              if (!f.exists() && getFileExtension(text).equals("fet")) {
                controlDecoration.hide();
                model.setFile(f);
                setPageComplete(true);
              } else {
                controlDecoration.show();
                model.setFile(null);
                setPageComplete(false);
              }
            }
          }
        });

    // button opens a save file dialog and sets the text to the selected file with path with .fet
    // appended to it
    Button saveButton = new Button(compo, SWT.NONE);
    saveButton.setText("Save...");
    GridDataFactory.fillDefaults().indent(5, 0).applyTo(saveButton);
    saveButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
            dialog.setFilterExtensions(new String[] {"*.fet"});
            String fileName = dialog.open();
            if (fileName != null) {
              fileName = fileName.endsWith(".fet") ? fileName : fileName + ".fet";
              text.setText(fileName);
            }
          }
        });

    setControl(compo);
  }
Beispiel #16
0
/**
 * Abstract subclass of <code>TitleAreaDialog</code> that creates its content using a <code>Builder
 * </code> provided by the implementor of this class.
 *
 * @author <a href="mailto:[email protected]">Philipp Kursawe</a>
 */
public abstract class BuiltTitleAreaDialog extends TitleAreaDialog implements BuilderProvider {

  private Builder builder;
  private ControlDecoration okButtonDecoration;
  final FieldDecoration warningDecoration =
      FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);

  /** @param parentShell */
  public BuiltTitleAreaDialog(final Shell parentShell) {
    super(parentShell);
  }

  @Override
  protected Control createDialogArea(final Composite parent) {
    final Composite client = new Composite((Composite) super.createDialogArea(parent), SWT.NULL);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(client);
    builder =
        createBuilder(client)
            .addDialogSupport(
                this,
                new AbstractObservableValue() {
                  public Object getValueType() {
                    return null;
                  }

                  @Override
                  protected Object doGetValue() {
                    return null;
                  }

                  @Override
                  protected void doSetValue(final Object value) {
                    if (value instanceof IStatus) {
                      final IStatus status = (IStatus) value;
                      final Button button = getButton(IDialogConstants.OK_ID);
                      if (button != null && !button.isDisposed()) {
                        button.setEnabled(status.getSeverity() != IStatus.ERROR);
                        if (status.getSeverity() == IStatus.WARNING) {
                          okButtonDecoration.show();
                        } else {
                          okButtonDecoration.hide();
                        }
                      }
                    }
                  }
                });
    return client;
  }

  @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
  protected void okPressed() {
    builder.updateModels();
    super.okPressed();
  }
}
  @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.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;
    this.paramFieldType = param.getFieldType();
    int nbLines = param.getNbLines();

    DecoratedField dField =
        new DecoratedField(
            subComposite,
            SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP,
            new SelectAllTextControlCreator());
    if (param.isRequired()) {
      FieldDecoration decoration =
          FieldDecorationRegistry.getDefault()
              .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
      dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();
    Text text = (Text) dField.getControl();

    editionControlHelper.register(param.getName(), text);

    FormData d = (FormData) text.getLayoutData();
    if (getAdditionalHeightSize() != 0) {
      nbLines += this.getAdditionalHeightSize() / text.getLineHeight();
    }
    d.height = text.getLineHeight() * nbLines;
    FormData data;
    text.getParent().setSize(subComposite.getSize().x, text.getLineHeight() * nbLines);
    cLayout.setBackground(subComposite.getBackground());
    // for bug 7580
    if (!(text instanceof Text)) {
      text.setEnabled(!param.isReadOnly());
    } else {
      text.setEditable(!param.isReadOnly());
    }
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    String fontType = preferenceStore.getString(TalendDesignerPrefConstants.MEMO_TEXT_FONT);
    FontData fontData = new FontData(fontType);
    Font font = new Font(null, fontData);
    addResourceDisposeListener(text, font);
    text.setFont(font);
    if (elem instanceof Node) {
      text.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    addDragAndDropTarget(text);

    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    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 = STANDARD_LABEL_WIDTH;
    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.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************
    hashCurControls.put(param.getName(), text);

    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);

    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return null;
  }