/**
   * The menu to show in the workbench menu
   *
   * @param menu the menu to fill entries into it
   */
  protected void fillMenu(Menu menu) {

    IWorkbenchPart activePart = JavaPlugin.getActivePage().getActivePart();
    if (!(activePart instanceof CompilationUnitEditor)) {
      ActionContributionItem item = new ActionContributionItem(NONE_APPLICABLE_ACTION);
      item.fill(menu, -1);
      return;
    }

    CompilationUnitEditor editor = (CompilationUnitEditor) activePart;
    if (editor.isBreadcrumbActive()) {
      ActionContributionItem item = new ActionContributionItem(NONE_APPLICABLE_ACTION);
      item.fill(menu, -1);
      return;
    }

    IAction[] actions = getTemplateActions(editor);

    boolean addSurroundWith = !isInJavadoc(editor);
    if (addSurroundWith) {
      SurroundWithTryCatchAction surroundAction = createSurroundWithTryCatchAction(editor);
      ActionContributionItem surroundItem = new ActionContributionItem(surroundAction);
      surroundItem.fill(menu, -1);
    }

    boolean hasTemplateActions = actions != null && actions.length > 0;
    if (!hasTemplateActions && !addSurroundWith) {
      ActionContributionItem item = new ActionContributionItem(NONE_APPLICABLE_ACTION);
      item.fill(menu, -1);
    } else if (hasTemplateActions) {
      if (addSurroundWith) {
        Separator templateGroup = new Separator(TEMPLATE_GROUP);
        templateGroup.fill(menu, -1);
      }

      for (int i = 0; i < actions.length; i++) {
        ActionContributionItem item = new ActionContributionItem(actions[i]);
        item.fill(menu, -1);
      }
    }

    Separator configGroup = new Separator(CONFIG_GROUP);
    configGroup.fill(menu, -1);

    ActionContributionItem configAction =
        new ActionContributionItem(new ConfigureTemplatesAction());
    configAction.fill(menu, -1);
  }
 private static SurroundWithTryCatchAction createSurroundWithTryCatchAction(
     CompilationUnitEditor editor) {
   SurroundWithTryCatchAction result = new SurroundWithTryCatchAction(editor);
   result.setText(ActionMessages.SurroundWithTemplateMenuAction_SurroundWithTryCatchActionName);
   result.setActionDefinitionId(IJavaEditorActionDefinitionIds.SURROUND_WITH_TRY_CATCH);
   editor.setAction("SurroundWithTryCatch", result); // $NON-NLS-1$
   return result;
 }
  public static void fillMenu(
      IMenuManager menu,
      CompilationUnitEditor editor,
      SurroundWithTryCatchAction surroundWithTryCatchAction) {
    IAction[] actions = getTemplateActions(editor);

    surroundWithTryCatchAction.update(editor.getSelectionProvider().getSelection());
    boolean addSurroundWithAction = surroundWithTryCatchAction.isEnabled() && !isInJavadoc(editor);

    if ((actions == null || actions.length == 0) && !addSurroundWithAction) {
      menu.add(NONE_APPLICABLE_ACTION);
    } else {
      if (addSurroundWithAction) menu.add(surroundWithTryCatchAction);

      menu.add(new Separator(TEMPLATE_GROUP));
      for (int i = 0; actions != null && i < actions.length; i++) menu.add(actions[i]);
    }

    menu.add(new Separator(CONFIG_GROUP));
    menu.add(new ConfigureTemplatesAction());
  }
 /**
  * Note: This constructor is for internal use only. Clients should not call this constructor.
  *
  * @param editor the compilation unit editor
  * @noreference This constructor is not intended to be referenced by clients.
  */
 public OverrideMethodsAction(final CompilationUnitEditor editor) {
   this(editor.getEditorSite());
   fEditor = editor;
   setEnabled(checkEnabledEditor());
 }
Esempio n. 5
0
 @Override
 protected void doSetInput(IEditorInput input) throws CoreException {
   super.doSetInput(input);
   IFile file = (IFile) input.getAdapter(IFile.class);
   if (file != null) new ToggleNatureAction().addToBuildSpec((IProject) file.getProject());
 }