Пример #1
0
  /**
   * Add message drop down toolbar item
   *
   * @param parent
   * @return toolbar
   */
  protected ToolBar addMessageDropDown(Composite parent) {
    final ToolBar dropDownBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
    final ToolItem dropDownItem = new ToolItem(dropDownBar, SWT.PUSH);
    dropDownItem.setImage(
        PlatformUI.getWorkbench()
            .getSharedImages()
            .getImage("IMG_LCL_RENDERED_VIEW_MENU")); // $NON-NLS-1$
    final Menu menu = new Menu(dropDownBar);
    dropDownItem.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            menu.dispose();
          }
        });
    MenuItem preferencesItem = new MenuItem(menu, SWT.PUSH);
    preferencesItem.setText(UIText.CommitDialog_ConfigureLink);
    preferencesItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            String[] pages = new String[] {UIPreferences.PAGE_COMMIT_PREFERENCES};
            PreferencesUtil.createPreferenceDialogOn(getShell(), pages[0], pages, null).open();
          }
        });
    dropDownItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            Rectangle b = dropDownItem.getBounds();
            Point p = dropDownItem.getParent().toDisplay(new Point(b.x, b.y + b.height));
            menu.setLocation(p.x, p.y);
            menu.setVisible(true);
          }
        });
    return dropDownBar;
  }
  /**
   * @param parent
   * @param repository
   * @param pathList
   */
  public NonDeletedFilesTree(Composite parent, Repository repository, List<String> pathList) {
    super(createComposite(parent), SWT.BORDER);
    this.filePaths = pathList;

    Composite main = getTree().getParent();

    GridDataFactory.fillDefaults().grab(true, true).applyTo(getTree());

    final FileTreeContentProvider cp = new FileTreeContentProvider(repository);

    setContentProvider(cp);
    setLabelProvider(new FileTreeLabelProvider());
    setInput(this.filePaths);
    expandAll();

    final ToolBar dropDownBar = new ToolBar(main, SWT.FLAT | SWT.RIGHT);
    GridDataFactory.swtDefaults()
        .align(SWT.BEGINNING, SWT.BEGINNING)
        .grab(false, false)
        .applyTo(dropDownBar);
    final ToolItem dropDownItem = new ToolItem(dropDownBar, SWT.DROP_DOWN);
    Image dropDownImage = UIIcons.HIERARCHY.createImage();
    UIUtils.hookDisposal(dropDownItem, dropDownImage);
    dropDownItem.setImage(dropDownImage);
    final Menu menu = new Menu(dropDownBar);
    dropDownItem.addDisposeListener(
        new DisposeListener() {

          public void widgetDisposed(DisposeEvent e) {
            menu.dispose();
          }
        });
    dropDownItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            Rectangle b = dropDownItem.getBounds();
            Point p = dropDownItem.getParent().toDisplay(new Point(b.x, b.y + b.height));
            menu.setLocation(p.x, p.y);
            menu.setVisible(true);
          }
        });

    final MenuItem showRepoRelative = new MenuItem(menu, SWT.RADIO);
    showRepoRelative.setText(UIText.NonDeletedFilesTree_RepoRelativePathsButton);
    showRepoRelative.setSelection(true);
    showRepoRelative.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (showRepoRelative.getSelection()) {
              cp.setMode(Mode.REPO_RELATIVE_PATHS);
              setInput(getInput());
              expandAll();
            }
          }
        });

    final MenuItem showFull = new MenuItem(menu, SWT.RADIO);
    showFull.setText(UIText.NonDeletedFilesTree_FileSystemPathsButton);
    showFull.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (showFull.getSelection()) {
              cp.setMode(Mode.FULL_PATHS);
              setInput(getInput());
              expandAll();
            }
          }
        });

    final MenuItem showResource = new MenuItem(menu, SWT.RADIO);
    showResource.setText(UIText.NonDeletedFilesTree_ResourcePathsButton);
    showResource.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (showResource.getSelection()) {
              cp.setMode(Mode.RESOURCE_PATHS);
              setInput(getInput());
              expandAll();
            }
          }
        });
  }
Пример #3
0
  /**
   * Creates the progress monitor's UI parts and layouts them according to the given layout. If the
   * layout is <code>null</code> the part's default layout is used.
   *
   * @param layout The layout for the receiver.
   * @param progressIndicatorHeight The suggested height of the indicator
   */
  protected void initialize(Layout layout, int progressIndicatorHeight) {
    if (layout == null) {
      GridLayout l = new GridLayout();
      l.marginWidth = 0;
      l.marginHeight = 0;
      layout = l;
    }
    int numColumns = 1;
    if (fHasStopButton) numColumns++;
    setLayout(layout);

    if (layout instanceof GridLayout) ((GridLayout) layout).numColumns = numColumns;

    fLabel = new Label(this, SWT.LEFT);
    fLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, numColumns, 1));

    if (progressIndicatorHeight == SWT.DEFAULT) {
      GC gc = new GC(fLabel);
      FontMetrics fm = gc.getFontMetrics();
      gc.dispose();
      progressIndicatorHeight = fm.getHeight();
    }

    fProgressIndicator = new ProgressIndicator(this);
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;
    gd.verticalAlignment = GridData.CENTER;
    gd.heightHint = progressIndicatorHeight;
    fProgressIndicator.setLayoutData(gd);

    if (fHasStopButton) {
      fToolBar = new ToolBar(this, SWT.FLAT);

      gd = new GridData();
      gd.grabExcessHorizontalSpace = false;
      gd.grabExcessVerticalSpace = false;
      gd.verticalAlignment = GridData.CENTER;
      fToolBar.setLayoutData(gd);
      fStopButton = new ToolItem(fToolBar, SWT.PUSH);
      // It would have been nice to use the fCancelListener, but that
      // listener operates on the fCancelComponent which must be a control.
      fStopButton.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              setCanceled(true);
              if (fStopButton != null) {
                fStopButton.setEnabled(false);
              }
            }
          });
      final Image stopImage =
          ImageDescriptor.createFromFile(ProgressMonitorPart.class, "images/stop.gif")
              .createImage(getDisplay()); // $NON-NLS-1$
      final Cursor arrowCursor = new Cursor(this.getDisplay(), SWT.CURSOR_ARROW);
      fToolBar.setCursor(arrowCursor);
      fStopButton.setImage(stopImage);
      fStopButton.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              // RAP [rh] images don't support dispose
              //        			stopImage.dispose();
              arrowCursor.dispose();
            }
          });
      fStopButton.setToolTipText(
          JFaceResources.getString("ProgressMonitorPart.cancelToolTip")); // $NON-NLS-1$
    }
  }