Ejemplo n.º 1
0
  void setDefaultTitle() {
    String description = getContentDescription();
    String name = getPartName();
    String newTitle = name;

    if (!Util.equals(description, "")) { // $NON-NLS-1$
      newTitle =
          MessageFormat.format(
              WorkbenchMessages.get().WorkbenchPart_AutoTitleFormat,
              new String[] {name, description});
    }

    setTitle(newTitle);
  }
  /**
   * 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;
  }
Ejemplo n.º 3
0
 public String getDisplayName() {
   return WorkbenchMessages.get().TrimCommon_Progress_TrimName;
 }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.wizard.IWizardNode#getWizard()
   */
  public IWizard getWizard() {
    if (wizard != null) {
      return wizard; // we've already created it
    }

    final IWorkbenchWizard[] workbenchWizard = new IWorkbenchWizard[1];
    final IStatus statuses[] = new IStatus[1];
    // Start busy indicator.
    BusyIndicator.showWhile(
        parentWizardPage.getShell().getDisplay(),
        new Runnable() {
          public void run() {
            SafeRunner.run(
                new SafeRunnable() {
                  /** Add the exception details to status is one happens. */
                  public void handleException(Throwable e) {
                    IPluginContribution contribution =
                        (IPluginContribution)
                            Util.getAdapter(wizardElement, IPluginContribution.class);
                    statuses[0] =
                        new Status(
                            IStatus.ERROR,
                            contribution != null
                                ? contribution.getPluginId()
                                : WorkbenchPlugin.PI_WORKBENCH,
                            IStatus.OK,
                            WorkbenchMessages.get().WorkbenchWizard_errorMessage,
                            e);
                  }

                  public void run() {
                    try {
                      workbenchWizard[0] = createWizard();
                      // create instance of target wizard
                    } catch (CoreException e) {
                      IPluginContribution contribution =
                          (IPluginContribution)
                              Util.getAdapter(wizardElement, IPluginContribution.class);
                      statuses[0] =
                          new Status(
                              IStatus.ERROR,
                              contribution != null
                                  ? contribution.getPluginId()
                                  : WorkbenchPlugin.PI_WORKBENCH,
                              IStatus.OK,
                              WorkbenchMessages.get().WorkbenchWizard_errorMessage,
                              e);
                    }
                  }
                });
          }
        });

    if (statuses[0] != null) {
      parentWizardPage.setErrorMessage(WorkbenchMessages.get().WorkbenchWizard_errorMessage);
      StatusAdapter statusAdapter = new StatusAdapter(statuses[0]);
      statusAdapter.addAdapter(Shell.class, parentWizardPage.getShell());
      statusAdapter.setProperty(
          StatusAdapter.TITLE_PROPERTY, WorkbenchMessages.get().WorkbenchWizard_errorTitle);
      StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW);
      return null;
    }

    IStructuredSelection currentSelection = getCurrentResourceSelection();

    // Get the adapted version of the selection that works for the
    // wizard node
    currentSelection = wizardElement.adaptedSelection(currentSelection);

    workbenchWizard[0].init(getWorkbench(), currentSelection);

    wizard = workbenchWizard[0];
    return wizard;
  }