private void validateFields() {
    String fileName = getFileName();
    if (!StringUtils.isSetAfterTrim(fileName)) {
      updateStatus(Messages.SaveCanvasAsTemplateWizardPage_10);
      return;
    }

    String name = getTemplateName();
    if (!StringUtils.isSetAfterTrim(name)) {
      updateStatus(Messages.SaveCanvasAsTemplateWizardPage_11);
      return;
    }

    updateStatus(null);
  }
  @Override
  public IFigure getToolTip() {
    if (!Preferences.doShowViewTooltips()) {
      return null;
    }

    ToolTipFigure toolTipFigure = (ToolTipFigure) super.getToolTip();

    if (toolTipFigure == null) {
      toolTipFigure = new ToolTipFigure();
      setToolTip(toolTipFigure);
    }

    String text = ArchimateLabelProvider.INSTANCE.getLabel(getDiagramModelObject());
    toolTipFigure.setText(text);

    if (fDiagramModelObject instanceof IDiagramModelArchimateObject) {
      IArchimateElement element =
          ((IDiagramModelArchimateObject) fDiagramModelObject).getArchimateElement();
      String type = ArchimateLabelProvider.INSTANCE.getDefaultName(element.eClass());
      if (!StringUtils.isSet(text)) { // Name was blank
        toolTipFigure.setText(type);
      }
      toolTipFigure.setType(
          Messages.AbstractDiagramModelObjectFigure_0 + " " + type); // $NON-NLS-1$
    }

    return toolTipFigure;
  }
예제 #3
0
  @Override
  public IFigure getToolTip() {
    if (fTooltip == null && Preferences.doShowViewTooltips()) {
      fTooltip = new MultiToolTipFigure();
      setToolTip(fTooltip);
    }

    if (fTooltip == null || !Preferences.doShowViewTooltips()) {
      return null;
    }

    String notes = getDiagramModelObject().getNotes();
    if (StringUtils.isSet(notes)) {
      fTooltip.setText(notes);
    } else {
      fTooltip.setText(Messages.CanvasStickyFigure_0);
    }

    return fTooltip;
  }
  @Override
  public void createControl(Composite parent) {
    GridData gd;
    Label label;

    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);

    Group fileComposite = new Group(container, SWT.NULL);
    fileComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout = new GridLayout(3, false);
    fileComposite.setLayout(layout);

    label = new Label(fileComposite, SWT.NULL);
    label.setText(Messages.SaveCanvasAsTemplateWizardPage_2);

    fFileTextField = new Text(fileComposite, SWT.BORDER | SWT.SINGLE);
    fFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    File newFile =
        new File(
            CURRENT_FOLDER,
            Messages.SaveCanvasAsTemplateWizardPage_3
                + CanvasTemplateManager.CANVAS_TEMPLATE_FILE_EXTENSION);
    fFileTextField.setText(newFile.getPath());
    // Single text control so strip CRLFs
    UIUtils.conformSingleTextControl(fFileTextField);
    fFileTextField.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            validateFields();
          }
        });

    Button fileButton = new Button(fileComposite, SWT.PUSH);
    fileButton.setText(Messages.SaveCanvasAsTemplateWizardPage_4);
    fileButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            File file = chooseFile();
            if (file != null) {
              fFileTextField.setText(file.getPath());
              CURRENT_FOLDER = file.getParentFile();
            }
          }
        });

    Group fieldGroup = new Group(container, SWT.NULL);
    fieldGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    layout = new GridLayout(2, false);
    fieldGroup.setLayout(layout);

    label = new Label(fieldGroup, SWT.NULL);
    label.setText(Messages.SaveCanvasAsTemplateWizardPage_5);

    fNameTextField = new Text(fieldGroup, SWT.BORDER | SWT.SINGLE);
    fNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (StringUtils.isSet(fCanvasModel.getName())) {
      fNameTextField.setText(fCanvasModel.getName());
    }
    // Single text control so strip CRLFs
    UIUtils.conformSingleTextControl(fNameTextField);
    fNameTextField.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            validateFields();
          }
        });

    label = new Label(fieldGroup, SWT.NULL);
    label.setText(Messages.SaveCanvasAsTemplateWizardPage_6);
    gd = new GridData(SWT.NULL, SWT.TOP, false, false);
    label.setLayoutData(gd);

    fDescriptionTextField = new Text(fieldGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    fDescriptionTextField.setLayoutData(gd);
    if (StringUtils.isSet(fCanvasModel.getDocumentation())) {
      fDescriptionTextField.setText(fCanvasModel.getDocumentation());
    }

    // Thumbnail

    Group thumbsGroup = new Group(container, SWT.NULL);
    thumbsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    layout = new GridLayout(2, false);
    thumbsGroup.setLayout(layout);

    fButtonIncludeThumbnail = new Button(thumbsGroup, SWT.CHECK);
    fButtonIncludeThumbnail.setText(Messages.SaveCanvasAsTemplateWizardPage_7);
    fButtonIncludeThumbnail.setSelection(true);
    fButtonIncludeThumbnail.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            fPreviewLabel.setEnabled(fButtonIncludeThumbnail.getSelection());
          }
        });

    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fButtonIncludeThumbnail.setLayoutData(gd);

    label = new Label(thumbsGroup, SWT.NULL);
    label.setText(Messages.SaveCanvasAsTemplateWizardPage_8 + "  "); // $NON-NLS-1$
    gd = new GridData(SWT.NULL, SWT.TOP, false, false);
    label.setLayoutData(gd);

    fPreviewLabel = new Label(thumbsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    gd.widthHint = 150;
    fPreviewLabel.setLayoutData(gd);

    // Dispose of the image here not in the main dispose() method because if the help system is
    // showing then
    // the TrayDialog is resized and this label is asked to relayout.
    fPreviewLabel.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            disposePreviewImage();
          }
        });

    Display.getCurrent()
        .asyncExec(
            new Runnable() {
              @Override
              public void run() {
                TemplateUtils.createThumbnailPreviewImage(fCanvasModel, fPreviewLabel);
              }
            });

    fPreviewLabel.addControlListener(
        new ControlAdapter() {
          int oldTime;

          @Override
          public void controlResized(ControlEvent e) {
            if (e.time - oldTime > 10) {
              disposePreviewImage();
              TemplateUtils.createThumbnailPreviewImage(fCanvasModel, fPreviewLabel);
            }
            oldTime = e.time;
          }
        });

    validateFields();
  }
예제 #5
0
 private void setText() {
   String text = getDiagramModelObject().getContent();
   getTextControl().setText(StringUtils.safeString(text));
 }