public void build() {
    getParent().setLayout(new FillLayout());
    Composite stack = createFrame();
    stack.setLayout(new FormLayout());

    tabBar = new Composite(stack, SWT.NONE);
    tabBar.setLayout(new FormLayout());
    tabBar.setBackgroundImage(tabInactiveBgActive);
    FormData fdTabBar = new FormData();
    tabBar.setLayoutData(fdTabBar);
    fdTabBar.top = new FormAttachment(0);
    fdTabBar.left = new FormAttachment(0);
    fdTabBar.right = new FormAttachment(100);
    fdTabBar.height = tabInactiveBgActive.getBounds().height;

    if (rightCorner != null && leftCorner != null) {
      leftCornerLabel = new Label(stack.getParent(), SWT.NONE);
      leftCornerLabel.setImage(leftCorner);
      FormData fdLeftCorner = new FormData();
      leftCornerLabel.setLayoutData(fdLeftCorner);
      fdLeftCorner.left = new FormAttachment(0, 3);
      fdLeftCorner.top = new FormAttachment(0, 7);

      rightCornerLabel = new Label(stack.getParent(), SWT.NONE);
      rightCornerLabel.setImage(rightCorner);
      FormData fdRightCorner = new FormData();
      rightCornerLabel.setLayoutData(fdRightCorner);
      fdRightCorner.right = new FormAttachment(100, -3);
      fdRightCorner.top = new FormAttachment(0, 7);
      rightCornerLabel.moveAbove(null);
      leftCornerLabel.moveAbove(null);
      labelMap.put(LEFT, leftCornerLabel);
      labelMap.put(RIGHT, rightCornerLabel);
    }

    content = new Composite(stack, SWT.NONE);
    FormData fdContent = new FormData();
    content.setLayoutData(fdContent);
    fdContent.top = new FormAttachment(tabBar);
    fdContent.left = new FormAttachment(0);
    fdContent.right = new FormAttachment(100);
    fdContent.bottom = new FormAttachment(100);
  }
Пример #2
0
  protected String layoutBeforeChild(
      Control control,
      String labelText,
      String elementName,
      Map<String, String> attributes,
      Composite composite,
      SwtMetawidget metawidget) {

    // Add label

    if (SimpleLayoutUtils.needsLabel(labelText, elementName)) {
      Label label = new Label(composite, SWT.None);
      label.setData(NAME, attributes.get(NAME) + LABEL_NAME_SUFFIX);

      if (mLabelFont != null) {
        label.setFont(mLabelFont);
      }

      if (mLabelForeground != null) {
        label.setForeground(mLabelForeground);
      }

      label.setAlignment(mLabelAlignment);

      // Required

      String labelTextToUse = labelText;

      if (mRequiredText != null
          && TRUE.equals(attributes.get(REQUIRED))
          && !WidgetBuilderUtils.isReadOnly(attributes)
          && !metawidget.isReadOnly()) {
        if (mRequiredAlignment == SWT.CENTER) {
          labelTextToUse += mRequiredText;
        } else if (mRequiredAlignment == SWT.LEFT) {
          labelTextToUse = mRequiredText + labelTextToUse;
        }
      }

      if (mLabelSuffix != null) {
        labelTextToUse += mLabelSuffix;
      }

      label.setText(labelTextToUse);

      GridData labelLayoutData = new GridData();
      labelLayoutData.horizontalAlignment = SWT.FILL;
      labelLayoutData.verticalAlignment = SWT.FILL;

      label.setLayoutData(labelLayoutData);
      label.moveAbove(control);
    }

    return labelText;
  }
Пример #3
0
  public Upload(Composite parent, int style, int... uploadStyles) {
    super(parent, style);
    setLayout(FormLayoutFactory.defaults().create());

    fileUpload = new FileUpload(this, SWT.NONE);
    fileUpload.setLayoutData(FormDataFactory.filled().create());
    fileUpload.setText(i18n.get("select"));
    fileUpload.setData(RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE);
    setData(RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE);

    fileUpload.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent ev) {
            UIUtils.activateCallback("upload");
            fileUpload.submit(UploadService.registerHandler(Upload.this));
          }
        });

    if (ArrayUtils.contains(uploadStyles, SHOW_UPLOAD_BUTTON)) {
      log.info("SHOW_UPLOAD_BUTTON is not supported yet.");
    }

    if (ArrayUtils.contains(uploadStyles, SHOW_PROGRESS)) {
      fileUpload.setLayoutData(FormDataFactory.filled().noRight().create());

      progress = new ProgressBar(this, SWT.HORIZONTAL);
      progress.setLayoutData(FormDataFactory.filled().left(fileUpload).create());
      progress.setMaximum(Integer.MAX_VALUE);

      progressLabel = new Label(this, SWT.NONE);
      progressLabel.setLayoutData(FormDataFactory.filled().top(0, 5).left(fileUpload, 20).create());
      progressLabel.setText(i18n.get("progressLabel"));
      log.warn("not yet ported: progressLabel.setForeground( new Color( 0x60, 0x60, 0x60 ) ) ");
      progressLabel.moveAbove(progress);
    }
  }
Пример #4
0
  void doRename(boolean showPreview) {
    cancel();

    Image image = null;
    Label label = null;

    fShowPreview |= showPreview;
    try {
      ISourceViewer viewer = fEditor.getViewer();
      if (viewer instanceof SourceViewer) {
        SourceViewer sourceViewer = (SourceViewer) viewer;
        Control viewerControl = sourceViewer.getControl();
        if (viewerControl instanceof Composite) {
          Composite composite = (Composite) viewerControl;
          Display display = composite.getDisplay();

          // Flush pending redraw requests:
          while (!display.isDisposed() && display.readAndDispatch()) {}

          // Copy editor area:
          GC gc = new GC(composite);
          Point size;
          try {
            size = composite.getSize();
            image = new Image(gc.getDevice(), size.x, size.y);
            gc.copyArea(image, 0, 0);
          } finally {
            gc.dispose();
            gc = null;
          }

          // Persist editor area while executing refactoring:
          label = new Label(composite, SWT.NONE);
          label.setImage(image);
          label.setBounds(0, 0, size.x, size.y);
          label.moveAbove(null);
        }
      }

      String newName = fNamePosition.getContent();
      if (fOriginalName.equals(newName)) {
        return;
      }
      RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
      if (renameSupport == null) {
        return;
      }

      Shell shell = fEditor.getSite().getShell();
      if (renameSupport.hasUnresolvedNameReferences()) {
        fShowPreview = true;
      }
      boolean executed;
      if (fShowPreview) { // could have been updated by undoAndCreateRenameSupport(..)
        executed = renameSupport.openDialog(shell, true);
      } else {
        renameSupport.perform(shell, fEditor.getSite().getWorkbenchWindow());
        executed = true;
      }
      if (executed) {
        restoreFullSelection();
      }
    } catch (CoreException ex) {
      DartToolsPlugin.log(ex);
    } catch (InterruptedException ex) {
      // canceling is OK -> redo text changes in that case?
    } catch (InvocationTargetException ex) {
      DartToolsPlugin.log(ex);
    } catch (BadLocationException e) {
      DartToolsPlugin.log(e);
    } finally {
      if (label != null) {
        label.dispose();
      }
      if (image != null) {
        image.dispose();
      }
    }
  }
  public static void setDescription(MPart part, String description) {
    if (!(part.getWidget() instanceof Composite)) return;

    Composite c = (Composite) part.getWidget();

    // Do we already have a label?
    if (c.getChildren().length == 3) {
      Label label = (Label) c.getChildren()[0];
      if (description == null) description = ""; // $NON-NLS-1$
      // hide the label if there is no text to show
      boolean hasText = !description.equals(""); // $NON-NLS-1$
      label.setVisible(hasText);
      label.setText(description);
      label.setToolTipText(description);

      // also hide the separator
      c.getChildren()[1].setVisible(hasText);
      c.layout();
    } else if (c.getChildren().length == 1) {
      c.setLayout(
          new Layout() {

            @Override
            protected Point computeSize(
                Composite composite, int wHint, int hHint, boolean flushCache) {
              return new Point(0, 0);
            }

            @Override
            protected void layout(Composite composite, boolean flushCache) {
              Rectangle bounds = composite.getBounds();
              if (composite.getChildren().length == 1) {
                composite.getChildren()[0].setBounds(composite.getBounds());
              } else if (composite.getChildren().length == 3) {
                Label label = (Label) composite.getChildren()[0];
                Label separator = (Label) composite.getChildren()[1];
                Control partCtrl = composite.getChildren()[2];

                // if the label is not visible, give it a zero size
                int labelHeight =
                    label.isVisible() ? label.computeSize(bounds.width, SWT.DEFAULT).y : 0;
                label.setBounds(0, 0, bounds.width, labelHeight);

                int separatorHeight =
                    separator.isVisible() ? separator.computeSize(bounds.width, SWT.DEFAULT).y : 0;
                separator.setBounds(0, labelHeight, bounds.width, separatorHeight);

                partCtrl.setBounds(
                    0,
                    labelHeight + separatorHeight,
                    bounds.width,
                    bounds.height - labelHeight - separatorHeight);
              }
            }
          });

      Label separator = new Label(c, SWT.SEPARATOR | SWT.HORIZONTAL);
      separator.moveAbove(null);
      Label label = new Label(c, SWT.NONE);
      label.setText(description);
      label.setToolTipText(description);
      label.moveAbove(null);
      c.layout();
    }
  }