Exemple #1
0
  /**
   * Add expand all and collapse all toolbar items to the given toolbar bound to the given tree
   * viewer
   *
   * @param toolbar
   * @param viewer
   * @return given toolbar
   */
  public static ToolBar addExpansionItems(final ToolBar toolbar, final AbstractTreeViewer viewer) {
    ToolItem collapseItem = new ToolItem(toolbar, SWT.PUSH);
    Image collapseImage = UIIcons.COLLAPSEALL.createImage();
    UIUtils.hookDisposal(collapseItem, collapseImage);
    collapseItem.setImage(collapseImage);
    collapseItem.setToolTipText(UIText.UIUtils_CollapseAll);
    collapseItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            viewer.collapseAll();
          }
        });

    ToolItem expandItem = new ToolItem(toolbar, SWT.PUSH);
    Image expandImage = UIIcons.EXPAND_ALL.createImage();
    UIUtils.hookDisposal(expandItem, expandImage);
    expandItem.setImage(expandImage);
    expandItem.setToolTipText(UIText.UIUtils_ExpandAll);
    expandItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            viewer.expandAll();
          }
        });
    return toolbar;
  }
  private ToolBar createConfigureToolBar(Composite parent) {
    final ToolBar tb = new ToolBar(parent, SWT.NONE);

    final ToolItem config = new ToolItem(tb, SWT.DROP_DOWN);
    config.setImage(imageCache.get(CONFIG_ICON));
    config.setToolTipText("Options");
    config.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            final Rectangle r = config.getBounds();
            final Point p = new Point(r.x, r.y + r.height);
            optionsMenu.setLocation(tb.getDisplay().map(tb, null, p));
            optionsMenu.setVisible(true);
          }
        });

    hideItem = new ToolItem(tb, SWT.PUSH);
    hideItem.setImage(imageCache.get(UP_ICON));
    hideItem.setToolTipText("Hide Request Table");
    hideItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            toggleHideState();
          }
        });

    tb.pack();
    return tb;
  }
Exemple #3
0
  /**
   * Initialize the toolbar with icons and selection listeners in the appropriate part of the window
   */
  public void initToolbar() {

    Device dev = shell.getDisplay();
    try {
      exitImg = new Image(dev, "img/exit.png");
      //            openImg = new Image(dev, "img/open.png");
      playImg = new Image(dev, "img/play.png");
      //            pauseImg = new Image(dev, "img/pause.png");

    } catch (Exception e) {
      System.out.println("Cannot load images");
      System.out.println(e.getMessage());
      System.exit(1);
    }

    ToolBar toolBar = new ToolBar(shell, SWT.BORDER);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    toolBar.setLayoutData(gridData);

    ToolItem exit = new ToolItem(toolBar, SWT.PUSH);
    exit.setImage(exitImg);

    // ToolItem open = new ToolItem(toolBar, SWT.PUSH);
    // exit.setImage(openImg);

    ToolItem play = new ToolItem(toolBar, SWT.PUSH);
    play.setImage(playImg);

    //        ToolItem pause = new ToolItem(toolBar, SWT.PUSH);
    //        pause.setImage(pauseImg);

    toolBar.pack();

    exit.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.exit(0);
          }
        });

    // open.addSelectionListener(new SelectionAdapter() {
    //     @Override
    //     public void widgetSelected(SelectionEvent e) {
    //         FileDialog dialog = new FileDialog(shell, SWT.NULL);
    //         String path = dialog.open();
    //     }
    // });

    play.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            controller.RunAnimation();
          }
        });
  }
  private void createToolBar(Composite parent) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT);
    modeButton = new ToolItem(toolBar, SWT.CHECK);
    modeButton.setImage(HierarchyView.INHERITED_IMAGE);
    modeButton.setToolTipText("Show Inherited Members");
    modeButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            mode = !mode;
            getTreeViewer().refresh();
            getTreeViewer().expandToLevel(getDefaultLevel());
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {}
        });
    sortButton = new ToolItem(toolBar, SWT.CHECK);
    sortButton.setImage(SORT);
    sortButton.setToolTipText("Sort by Name");
    boolean sortChecker = getDialogSettings().getBoolean("sort");
    sortButton.setSelection(sortChecker);
    sortButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            lexicalSortingAction.setChecked(sortButton.getSelection());
            lexicalSortingAction.run();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {}
        });
    hideButton = new ToolItem(toolBar, SWT.CHECK);
    hideButton.setImage(PUBLIC);
    hideButton.setToolTipText("Hide Unshared Declarations");
    boolean hideChecked = getDialogSettings().getBoolean("hideNonShared");
    hideButton.setSelection(hideChecked);
    hideButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            hideNonSharedAction.setChecked(hideButton.getSelection());
            hideNonSharedAction.run();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {}
        });
  }
  /*
   * Creates a button with a help image. This is only used if there
   * is an image available.
   */
  private ToolBar createLocalizationImageButton(Composite parent, Image image) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
          }
        });

    final ToolItem item = new ToolItem(toolBar, SWT.NONE);
    item.setImage(image);

    languageSet.associate(
        "localizationToolTip", //$NON-NLS-1$
        new TranslatableTextInput(
            Activator.getLocalizableText(
                "LocalizableTrayDialog.localizationToolTip")) { //$NON-NLS-1$
          @Override
          public void updateControl(String text) {
            item.setToolTipText(text);
          }
        });

    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            localizationPressed();
          }
        });
    return toolBar;
  }
Exemple #6
0
 private org.eclipse.swt.widgets.ToolItem addToolItem(
     final org.eclipse.swt.widgets.ToolBar toolbar,
     final org.eclipse.swt.examples.paint.Tool tool) {
   final java.lang.String id = tool.group + '.' + tool.name;
   org.eclipse.swt.widgets.ToolItem item =
       new org.eclipse.swt.widgets.ToolItem(toolbar, tool.type);
   item.setText(getResourceString(id + ".label"));
   item.setToolTipText(getResourceString(id + ".tooltip"));
   item.setImage(tool.image);
   item.addSelectionListener(
       new org.eclipse.swt.events.SelectionAdapter() {
         public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
           tool.action.run();
         }
       });
   final int childID = toolbar.indexOf(item);
   toolbar
       .getAccessible()
       .addAccessibleListener(
           new org.eclipse.swt.accessibility.AccessibleAdapter() {
             public void getName(org.eclipse.swt.accessibility.AccessibleEvent e) {
               if (e.childID == childID) {
                 e.result = getResourceString(id + ".description");
               }
             }
           });
   return item;
 }
  private void addPlainAction(RuleAction menuAction) {
    final ToolItem button = new ToolItem(mLayoutToolBar, SWT.PUSH);

    URL iconUrl = menuAction.getIconUrl();
    String title = menuAction.getTitle();
    if (iconUrl != null) {
      button.setImage(IconFactory.getInstance().getIcon(iconUrl));
      button.setToolTipText(title);
    } else {
      button.setText(title);
    }
    button.setData(menuAction);

    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            RuleAction menuAction = (RuleAction) button.getData();
            menuAction
                .getCallback()
                .action(menuAction, getSelectedNodes(), menuAction.getId(), false);
            updateSelection();
          }
        });
  }
Exemple #8
0
  public ExpandButton(Composite parent) {
    expandImage = SATC_Activator.getImageDescriptor(EXPAND_ICON).createImage();
    collapseImage = SATC_Activator.getImageDescriptor(COLLAPSE_ICON).createImage();

    toolBar = new ToolBar(parent, SWT.FLAT);
    toolItem = new ToolItem(toolBar, SWT.PUSH);
    toolItem.setImage(expandImage);
    toolItem.addSelectionListener(
        new SelectionListener() {

          @Override
          public void widgetDefaultSelected(SelectionEvent arg0) {
            //
          }

          @Override
          public void widgetSelected(SelectionEvent event) {
            setSelection(!selected);
            if (listeners != null) {
              for (SelectionListener listener : listeners) {
                listener.widgetSelected(event);
              }
            }
          }
        });
  }
  private ToolBar createHelpImageButton(Composite parent, Image image) {
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(
        new DisposeListener() {

          @Override
          public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
          }
        });
    ToolItem item = new ToolItem(toolBar, SWT.NONE);
    item.setImage(image);
    item.setToolTipText(JFaceResources.getString("helpToolTip")); // $NON-NLS-1$
    item.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            helpPressed();
          }
        });
    return toolBar;
  }
 /** 添加帮助按钮,备注,这里的配置与其他的不一样 robert 2012-09-06 */
 protected Control createHelpToolItem(Composite parent) {
   // ROBERTHELP xml 转换器配置
   String language = CommonFunction.getSystemLanguage();
   final String helpUrl =
       MessageFormat.format(
           "/net.heartsome.cat.ts.ui.help/html/{0}/ch08.html#configure-xml-converter", language);
   Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
   ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
   toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
   final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
   toolBar.setCursor(cursor);
   toolBar.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           cursor.dispose();
         }
       });
   ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
   helpItem.setImage(helpImage);
   helpItem.setToolTipText(JFaceResources.getString("helpToolTip")); // $NON-NLS-1$
   helpItem.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
         }
       });
   return toolBar;
 }
  /*
   * Overridden so that clicking in the title menu area closes the dialog. Also creates a close box menu in the title
   * area.
   */
  protected Control createTitleMenuArea(Composite parent) {
    Composite titleComposite = (Composite) super.createTitleMenuArea(parent);
    titleComposite.addMouseListener(clickListener);

    ToolBar toolBar = new ToolBar(titleComposite, SWT.FLAT);
    ToolItem closeButton = new ToolItem(toolBar, SWT.PUSH, 0);

    GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(toolBar);
    closeButton.setImage(
        UIEplPlugin.getDefault().getImageRegistry().get((UIEplPlugin.IMG_TOOL_CLOSE)));
    closeButton.setHotImage(
        UIEplPlugin.getDefault().getImageRegistry().get((UIEplPlugin.IMG_TOOL_CLOSE_HOT)));
    closeButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            close();
          }
        });
    toolBar.addMouseListener(
        new MouseAdapter() {
          public void mouseDown(MouseEvent e) {
            close();
          }
        });
    return titleComposite;
  }
  @Override
  protected Control createControl(Composite parent) {
    super.createControl(parent);
    ToolBar buttons = new ToolBar(parent, SWT.FLAT | SWT.WRAP);

    ToolItem changeImage = new ToolItem(buttons, SWT.PUSH);
    changeImage.setImage(
        JaspersoftStudioPlugin.getInstance().getImage("icons/resources/equalizer--arrow.png"));
    changeImage.setToolTipText("Set exporter properties");
    changeImage.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            createPopupMenu();
            if (popupMenu.isVisible()) {
              popupMenu.setVisible(false);
            } else {
              locatePopupMenu(popupMenu);
              popupMenu.setVisible(true);
            }
          }
        });

    return buttons;
  }
  private static ToolItem createPublishToolItem(final ToolBar toolBar, final Shell shell) {
    ToolItem toolItem = createToolItem(toolBar, EMPTY, PUBLISH_TOOL_TIP_TEXT, PUBLISH_ICON);
    toolItem.addSelectionListener(
        new SelectionListener() {
          private static final long serialVersionUID = 3334607710375924130L;

          @Override
          public void widgetSelected(SelectionEvent e) {
            StatusLineManagerUtil.getDefaultStatusLineManager().removeAll();
            try {
              publish();
            } catch (Exception ex) {
              logger.error(ex.getMessage(), ex);
              StatusLineManagerUtil.setErrorMessage(ex.getMessage());
              MessageDialog.openError(shell, ACTIVATION_FAILED, ex.getMessage());
            }

            WebViewerView.refreshWebViewerViewIfVisible();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            //
          }
        });
    return toolItem;
  }
  private static ToolItem createNewToolItem(Composite parent, final ToolBar toolBar) {
    final Menu menu = NewMenuItemViewProvider.createMenu(parent);

    final ToolItem toolItem = createToolItem(toolBar, NEW, NEW, null, SWT.DROP_DOWN);
    toolItem.addSelectionListener(
        new SelectionListener() {
          private static final long serialVersionUID = -2281618627759204367L;

          @Override
          public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.ARROW) {
              Rectangle rect = toolItem.getBounds();
              Point pt = new Point(rect.x, rect.y + rect.height);
              pt = toolBar.toDisplay(pt);
              menu.setLocation(pt.x, pt.y);
              menu.setVisible(true);
            }
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            //

          }
        });

    return toolItem;
  }
  @SuppressWarnings("unused") // SWT constructors have side effects, they are not unused
  private ToolBar createLintControls() {
    ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT | SWT.HORIZONTAL);

    // Separate from adjacent toolbar
    new ToolItem(toolBar, SWT.SEPARATOR);

    ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
    mLintButton = new ToolItem(toolBar, SWT.PUSH);
    mLintButton.setToolTipText("Show Lint Warnings for this Layout");
    mLintButton.setImage(sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    mLintButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            CommonXmlEditor editor = mEditor.getEditorDelegate().getEditor();
            IFile file = editor.getInputFile();
            if (file != null) {
              EclipseLintClient.showErrors(getShell(), file, editor);
            }
          }
        });

    return toolBar;
  }
  private void addRadio(RuleAction.Choices choices) {
    List<URL> icons = choices.getIconUrls();
    List<String> titles = choices.getTitles();
    List<String> ids = choices.getIds();
    String current = choices.getCurrent() != null ? choices.getCurrent() : ""; // $NON-NLS-1$

    assert icons != null;
    assert icons.size() == titles.size();

    for (int i = 0; i < icons.size(); i++) {
      URL iconUrl = icons.get(i);
      String title = titles.get(i);
      final String id = ids.get(i);
      final ToolItem item = new ToolItem(mLayoutToolBar, SWT.RADIO);
      item.setToolTipText(title);
      item.setImage(IconFactory.getInstance().getIcon(iconUrl));
      item.setData(choices);
      item.setData(ATTR_ID, id);
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              if (item.getSelection()) {
                RuleAction.Choices choices = (Choices) item.getData();
                choices.getCallback().action(choices, getSelectedNodes(), id, null);
                updateSelection();
              }
            }
          });
      boolean selected = current.equals(id);
      if (selected) {
        item.setSelection(true);
      }
    }
  }
  private void addToggle(Toggle toggle) {
    final ToolItem button = new ToolItem(mLayoutToolBar, SWT.CHECK);

    URL iconUrl = toggle.getIconUrl();
    String title = toggle.getTitle();
    if (iconUrl != null) {
      button.setImage(IconFactory.getInstance().getIcon(iconUrl));
      button.setToolTipText(title);
    } else {
      button.setText(title);
    }
    button.setData(toggle);

    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Toggle toggle = (Toggle) button.getData();
            toggle
                .getCallback()
                .action(toggle, getSelectedNodes(), toggle.getId(), button.getSelection());
            updateSelection();
          }
        });
    if (toggle.isChecked()) {
      button.setSelection(true);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void createPartControl(final Composite parent) {
    toolBar = new ToolBar(parent, SWT.NONE);

    objectSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    objectSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeObject.png"));
    objectSelection.setSelection(true);
    objectSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.OBJECT);
          }
        });
    faceSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    faceSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeFace.png"));
    faceSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.FACE);
          }
        });
    faceSelection.setEnabled(false);
    edgeSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    edgeSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeEdge.png"));
    edgeSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.EDGE);
          }
        });
    edgeSelection.setEnabled(false);
    vertexSelection = new ToolItem(toolBar, SWT.RADIO | SWT.NONE);
    vertexSelection.setImage(MoreDreadUI.getDefault().getImage("/icons/SelectionModeVertex.png"));
    vertexSelection.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            MoreDreadUI.getDefault().getSceneHolder().setSelectionMode(SelectionMode.VERTEX);
          }
        });
    vertexSelection.setEnabled(false);
    MoreDreadUI.getDefault().getSceneHolder().addSceneSelectionModeListener(this);
    MoreDreadUI.getDefault().getSceneHolder().addSceneSelectionChangeListener(this);
  }
  /** This method initializes barCommands */
  private void createBarCommands() {
    ToolBar barCommands = new ToolBar(shell, SWT.HORIZONTAL);
    barCommands.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));

    ToolItem btnReplace = new ToolItem(barCommands, SWT.PUSH | SWT.BORDER);
    btnReplace.setText("Replace");
    btnReplace.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            String runningUser = replaceRunningUserTableComposite.getTxtReplaceRunningUserString();
            if (deployDashboardProcess.replaceRunningUserWith(runningUser)) {
              shell.close();
            } else {
              replaceRunningUserTableComposite.enableErrorMessage();
            }
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
          }
        });

    ToolItem btnClose = new ToolItem(barCommands, SWT.PUSH | SWT.BORDER);
    btnClose.setText("Cancel");
    btnClose.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            shell.close();
          }

          @Override
          public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
          }
        });
  }
  /**
   * Creates toolbar
   *
   * @param ancestor the parent composite
   */
  private void createToolBar(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    parent.setLayout(layout);

    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    parent.setLayoutData(gridData);

    // to simulate a vertical toolbar (not possible), create a separate toolbar for each button
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT);
    Image imageUp = DiagramUIPluginImages.DESC_UP_PATH.createImage();
    moveUpToolItem = new ToolItem(toolBar, SWT.PUSH);
    moveUpToolItem.setEnabled(false);
    moveUpToolItem.setToolTipText(MOVE_UP_TOOL_TIP);
    moveUpToolItem.setImage(imageUp);
    moveUpToolItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            moveUpElements();
          }
        });
    ToolBar toolBarDown = new ToolBar(parent, SWT.FLAT);
    Image imageDown = DiagramUIPluginImages.DESC_DOWN_PATH.createImage();
    moveDownToolItem = new ToolItem(toolBarDown, SWT.PUSH);
    moveDownToolItem.setEnabled(false);
    moveDownToolItem.setToolTipText(MOVE_DOWN_TOOL_TIP);
    moveDownToolItem.setImage(imageDown);
    moveDownToolItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            moveDownElements();
          }
        });
  }
 /**
  * Creates a top-level menu and adds it to the Riena menu bar.
  *
  * @param menuManager
  * @param listener
  */
 private ToolItem createAndAddMenu(
     final MenuManager menuManager, final ToolBarMenuListener listener) {
   if (menuManager.isVisible()) {
     final ToolItem toolItem = new ToolItem(menuToolBar, SWT.CHECK);
     toolItem.setText(menuManager.getMenuText());
     final MenuManagerHelper helper = new MenuManagerHelper();
     final Menu menu = helper.createMenu(menuToolBar, toolItem, menuManager);
     toolItem.setData(MENU_DATA_KEY, menu);
     calcSize(menuCoolItem);
     toolItem.addSelectionListener(listener);
     return toolItem;
   }
   return null;
 }
  public Control createControl(Composite parent, int style) {
    toolbar = new ToolBar(parent, style);

    btnAdd = new ToolItem(toolbar, SWT.PUSH);
    btnAdd.setImage(
        PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    btnAdd.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            for (AddRemoveListener l : listeners) {
              l.addSelected();
            }
          }
        });

    btnRemove = new ToolItem(toolbar, SWT.PUSH);
    btnRemove.setImage(
        PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    btnRemove.setDisabledImage(
        PlatformUI.getWorkbench()
            .getSharedImages()
            .getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    btnRemove.setToolTipText("Remove");
    btnRemove.setEnabled(false);
    btnRemove.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            for (AddRemoveListener l : listeners) {
              l.removeSelected();
            }
          }
        });

    return toolbar;
  }
 private ToolBar createLayoutToolBar(Composite parent) {
   ToolBar tb = new ToolBar(parent, SWT.NONE);
   ToolItem tabbed = new ToolItem(tb, SWT.RADIO);
   tabbed.setImage(imageCache.get(TABBED_ICON));
   tabbed.setToolTipText("Tabbed Request/Response layout");
   tabbed.setSelection(true);
   tabbed.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           setTabbedMode();
         }
       });
   ToolItem horiz = new ToolItem(tb, SWT.RADIO);
   horiz.setImage(imageCache.get(HORIZONTAL_ICON));
   horiz.setToolTipText("Horizontal Request/Response layout");
   horiz.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           setHorizontalSashMode();
         }
       });
   ToolItem vert = new ToolItem(tb, SWT.RADIO);
   vert.setImage(imageCache.get(VERTICAL_ICON));
   vert.setToolTipText("Vertical Request/Response layout");
   vert.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           setVerticalSashMode();
         }
       });
   tb.pack();
   return tb;
 }
  protected ToolItem createAddItemTool(ToolBar toolbar) {
    ToolItem tool = new ToolItem(toolbar, SWT.PUSH);

    tool.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    tool.setToolTipText("Add Bundle");
    tool.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            doAdd();
          }
        });

    return tool;
  }
Exemple #25
0
 public static ToolItem createToolItem(
     ToolBar toolBar, String text, Image icon, final IAction action) {
   ToolItem item = new ToolItem(toolBar, SWT.PUSH);
   item.setToolTipText(text);
   if (icon != null) {
     item.setImage(icon);
   }
   item.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           action.run();
         }
       });
   return item;
 }
Exemple #26
0
  public DropDownItem(Composite parent) {
    super(parent, SWT.NONE);

    setLayout(new FillLayout());

    bar = new ToolBar(this, SWT.HORIZONTAL);

    item = new ToolItem(bar, SWT.DROP_DOWN);
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if ((e.detail & SWT.ARROW) != 0) doDropDown();
            else itemSelected();
          }
        });
  }
  protected void createComponent(Composite parent) {
    toolBar = new ToolBar(parent, SWT.FLAT | SWT.WRAP | SWT.LEFT);
    toolBar.setBackground(parent.getBackground());

    // The listener can not be disposed by its own, so we can dispose it manually
    // when the component that used it don't need it anymore
    toolBar.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            colorLabelProvider.dispose();
          }
        });
    foreButton = new ToolItem(toolBar, SWT.PUSH);
    if (section.getElement().isEditable()) {
      foreButton.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              ColorDialog cd = new ColorDialog(toolBar.getShell());
              cd.setText(pDescriptor.getDisplayName());
              AlfaRGB rgb =
                  (AlfaRGB) section.getElement().getPropertyActualValue(pDescriptor.getId());
              cd.setRGB(rgb == null ? null : rgb);
              boolean useTransparency = true;
              if (pDescriptor instanceof ColorPropertyDescriptor) {
                useTransparency = ((ColorPropertyDescriptor) pDescriptor).supportsTransparency();
              }
              if (useTransparency) {
                AlfaRGB newColor = cd.openAlfaRGB();
                if (newColor != null) {
                  changeProperty(section, pDescriptor.getId(), newColor);
                }
              } else {
                RGB newColor = cd.openRGB();
                if (newColor != null) {
                  changeProperty(section, pDescriptor.getId(), AlfaRGB.getFullyOpaque(newColor));
                }
              }
            }
          });
    }
    foreButton.setToolTipText(pDescriptor.getDescription());
    toolBar.pack();
  }
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, false));

    final Text text = new Text(shell, SWT.SEARCH | SWT.ICON_CANCEL);
    Image image = null;
    if ((text.getStyle() & SWT.ICON_CANCEL) == 0) {
      image = display.getSystemImage(SWT.ICON_ERROR);
      ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
      ToolItem item = new ToolItem(toolBar, SWT.PUSH);
      item.setImage(image);
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              text.setText("");
              System.out.println("Search cancelled");
            }
          });
    }
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    text.setText("Search text");
    text.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            if (e.detail == SWT.CANCEL) {
              System.out.println("Search cancelled");
            } else {
              System.out.println("Searching for: " + text.getText() + "...");
            }
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    if (image != null) image.dispose();
    display.dispose();
  }
  private static ToolItem createSaveAllToolItem(final ToolBar toolBar) {
    ToolItem toolItem = createToolItem(toolBar, EMPTY, SAVE_ALL, SAVE_ALL_ICON);
    toolItem.addSelectionListener(
        new SelectionListener() {
          private static final long serialVersionUID = 6845514748708051108L;

          @Override
          public void widgetSelected(SelectionEvent e) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            ActionFactory.SAVE_ALL.create(window).run();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            //
          }
        });
    return toolItem;
  }
  protected ToolItem createRemoveItemTool(ToolBar toolbar) {
    ToolItem tool = new ToolItem(toolbar, SWT.PUSH);

    tool.setImage(
        PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    tool.setDisabledImage(
        PlatformUI.getWorkbench()
            .getSharedImages()
            .getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    tool.setToolTipText("Remove");
    tool.setEnabled(false);
    tool.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            doRemove();
          }
        });

    return tool;
  }