示例#1
0
  @Override
  public void addItem(int id, ToolItem item) {
    if (item.getParent() != myToolBar) {
      LogUtils.error(this, "Item does nopt have the correct toolbar as parent. Disposed.");
      item.dispose();
      return;
    }
    if (myItems.containsKey(id)) {
      LogUtils.error(this, "item ID " + id + " already used. Item Disposed.");
      item.dispose();
      return;
    }

    myItems.put(id, item);
  }
  private void removePerspectiveItem(MPerspective toRemove) {
    ToolItem psItem = getItemFor(toRemove);
    if (psItem != null) {
      psItem.dispose();
    }

    // update the size
    fixSize();
  }
 /** Update the toolbar widgets */
 private void updateToolbar(
     final List<RuleAction> actions, final int labelIndex, final String label) {
   if (mLayoutToolBar == null || mLayoutToolBar.isDisposed()) {
     return;
   }
   for (ToolItem c : mLayoutToolBar.getItems()) {
     c.dispose();
   }
   mLayoutToolBar.pack();
   addActions(actions, labelIndex, label);
   mLayoutToolBar.pack();
   mLayoutToolBar.layout();
 }
  public void setActions(IAction[] actions) {
    if (actions != null) {
      if (toolbar != null) {
        while (toolbar.getItemCount() > 0) {
          ToolItem item = toolbar.getItem(0);
          IAction action = (IAction) actionMap.get(item);
          if (action != null) action.removePropertyChangeListener(this);
          item.dispose();
        }
        actionMap.clear();
        toolbar.dispose();
      }

      toolbar = new ToolBar(label, SWT.FLAT);
      toolbar.setBackground(gbg);
      GridData gd = new GridData();
      gd.grabExcessHorizontalSpace = true;
      gd.horizontalAlignment = SWT.END;
      gd.grabExcessVerticalSpace = true;
      gd.verticalAlignment = SWT.CENTER;
      toolbar.setLayoutData(gd);

      for (int i = 0; i < actions.length; i++) {
        IAction action = actions[i];
        int flags = SWT.PUSH;
        if (action != null) {
          int style = action.getStyle();
          if (style == IAction.AS_CHECK_BOX) {
            flags = SWT.CHECK;
          } else if (style == IAction.AS_RADIO_BUTTON) {
            flags = SWT.RADIO;
          } else if (style == IAction.AS_DROP_DOWN_MENU) {
            flags = SWT.DROP_DOWN;
          }
        }
        ToolItem item = new ToolItem(toolbar, flags);
        item.addListener(SWT.Selection, getToolItemListener());
        action.addPropertyChangeListener(this);
        actionMap.put(item, action);
      }
      updateToolBar();
      label.layout();
    } else {
      if (toolbar != null) {
        toolbar.dispose();
        toolbar = null;
      }
    }
  }
 private void disposeToolItems() {
   for (int i = 0; i < toolItemList.size(); i++) {
     ToolItem item = (ToolItem) toolItemList.get(i);
     if (!item.isDisposed()) {
       Object data = item.getData();
       if (data != null && data instanceof Menu) {
         Menu menu = (Menu) data;
         if (!menu.isDisposed()) {
           menu.dispose();
         }
       }
       item.dispose();
     }
   }
 }