/** Updates the history controls. */
 private void updateHistoryControls() {
   historyToolbar.update(false);
   IContributionItem[] items = historyToolbar.getItems();
   for (int i = 0; i < items.length; i++) {
     items[i].update(IAction.ENABLED);
     items[i].update(IAction.TOOL_TIP_TEXT);
   }
 }
  private void createSectionToolbar(Section section, FormToolkit toolkit) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
    toolbar.setCursor(handCursor);
    // Cursor needs to be explicitly disposed
    toolbar.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            if (handCursor.isDisposed() == false) {
              handCursor.dispose();
            }
          }
        });
    fNewPluginAction = new NewPluginAction();
    fNewFragmentAction = new NewFragmentAction();
    toolBarManager.add(fNewPluginAction);
    toolBarManager.add(fNewFragmentAction);

    toolBarManager.update(true);
    section.setTextClient(toolbar);
  }
  /**
   * Creates the history toolbar and initializes <code>historyToolbar</code>.
   *
   * @param historyBar
   * @param manager
   * @return the control of the history toolbar
   */
  public ToolBar createHistoryControls(ToolBar historyBar, ToolBarManager manager) {

    historyToolbar = manager;
    /** Superclass of the two for-/backward actions for the history. */
    abstract class HistoryNavigationAction extends Action implements IMenuCreator {
      private Menu lastMenu;

      protected static final int MAX_ENTRIES = 5;

      HistoryNavigationAction() {
        super("", IAction.AS_DROP_DOWN_MENU); // $NON-NLS-1$
      }

      public IMenuCreator getMenuCreator() {
        return this;
      }

      public void dispose() {
        if (lastMenu != null) {
          lastMenu.dispose();
          lastMenu = null;
        }
      }

      public Menu getMenu(Control parent) {
        if (lastMenu != null) {
          lastMenu.dispose();
        }
        lastMenu = new Menu(parent);
        createEntries(lastMenu);
        return lastMenu;
      }

      public Menu getMenu(Menu parent) {
        return null;
      }

      protected void addActionToMenu(Menu parent, IAction action) {
        ActionContributionItem item = new ActionContributionItem(action);
        item.fill(parent, -1);
      }

      protected abstract void createEntries(Menu menu);
    }

    /**
     * Menu entry for the toolbar dropdowns. Instances are direct-jump entries in the navigation
     * history.
     */
    class HistoryItemAction extends Action {

      private final int index;

      HistoryItemAction(int index, String label) {
        super(label, IAction.AS_PUSH_BUTTON);
        this.index = index;
      }

      public void run() {
        jumpToHistory(index);
      }
    }

    HistoryNavigationAction backward =
        new HistoryNavigationAction() {
          public void run() {
            jumpToHistory(historyIndex - 1);
          }

          public boolean isEnabled() {
            boolean enabled = historyIndex > 0;
            if (enabled) {
              setToolTipText(
                  NLS.bind(
                      WorkbenchMessages.get().NavigationHistoryAction_backward_toolTipName,
                      getHistoryEntry(historyIndex - 1).getLabel()));
            }
            return enabled;
          }

          protected void createEntries(Menu menu) {
            int limit = Math.max(0, historyIndex - MAX_ENTRIES);
            for (int i = historyIndex - 1; i >= limit; i--) {
              IAction action = new HistoryItemAction(i, getHistoryEntry(i).getLabel());
              addActionToMenu(menu, action);
            }
          }
        };
    backward.setText(WorkbenchMessages.get().NavigationHistoryAction_backward_text);
    backward.setActionDefinitionId("org.eclipse.ui.navigate.backwardHistory"); // $NON-NLS-1$
    backward.setImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
    backward.setDisabledImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
    registerKeybindings(backward);
    historyToolbar.add(backward);

    HistoryNavigationAction forward =
        new HistoryNavigationAction() {
          public void run() {
            jumpToHistory(historyIndex + 1);
          }

          public boolean isEnabled() {
            boolean enabled = historyIndex < history.size() - 1;
            if (enabled) {
              setToolTipText(
                  NLS.bind(
                      WorkbenchMessages.get().NavigationHistoryAction_forward_toolTipName,
                      getHistoryEntry(historyIndex + 1).getLabel()));
            }
            return enabled;
          }

          protected void createEntries(Menu menu) {
            int limit = Math.min(history.size(), historyIndex + MAX_ENTRIES + 1);
            for (int i = historyIndex + 1; i < limit; i++) {
              IAction action = new HistoryItemAction(i, getHistoryEntry(i).getLabel());
              addActionToMenu(menu, action);
            }
          }
        };
    forward.setText(WorkbenchMessages.get().NavigationHistoryAction_forward_text);
    forward.setActionDefinitionId("org.eclipse.ui.navigate.forwardHistory"); // $NON-NLS-1$
    forward.setImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
    forward.setDisabledImageDescriptor(
        WorkbenchPlugin.getDefault()
            .getSharedImages()
            .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
    registerKeybindings(forward);
    historyToolbar.add(forward);

    return historyBar;
  }