/*
   * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
   */
  @Override
  public void contributeToMenu(IMenuManager menu) {

    super.contributeToMenu(menu);

    IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
    if (editMenu != null) {

      MenuManager structureSelection =
          new MenuManager(
              JavaEditorMessages.ExpandSelectionMenu_label, "expandSelection"); // $NON-NLS-1$
      editMenu.insertAfter(ITextEditorActionConstants.SELECT_ALL, structureSelection);
      structureSelection.add(fStructureSelectEnclosingAction);
      structureSelection.add(fStructureSelectNextAction);
      structureSelection.add(fStructureSelectPreviousAction);
      structureSelection.add(fStructureSelectHistoryAction);

      editMenu.appendToGroup(
          ITextEditorActionConstants.GROUP_INFORMATION, fRetargetShowInformationAction);
    }

    IMenuManager navigateMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
    if (navigateMenu != null) {
      navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fShowOutline);
      navigateMenu.appendToGroup(IWorkbenchActionConstants.SHOW_EXT, fOpenHierarchy);
    }

    IMenuManager gotoMenu = menu.findMenuUsingPath("navigate/goTo"); // $NON-NLS-1$
    if (gotoMenu != null) {
      gotoMenu.add(new Separator("additions2")); // $NON-NLS-1$
      gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); // $NON-NLS-1$
      gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); // $NON-NLS-1$
      gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); // $NON-NLS-1$
    }
  }
  @Override
  public void init(IActionBars bars, IWorkbenchPage page) {
    super.init(bars, page);

    bars.setGlobalActionHandler(
        IPythonEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, toggleMarkOccurrencesAction);
  }
  @Override
  public void setActiveEditor(IEditorPart part) {
    super.setActiveEditor(part);

    if (part instanceof TextEditor) {
      this.commentAction.setTextEditor((TextEditor) part);
      this.uncommentAction.setTextEditor((TextEditor) part);
      this.toggleCommentsAction.setTextEditor((TextEditor) part);
    }
  }
  @Override
  public void contributeToMenu(IMenuManager menuManager) {
    super.contributeToMenu(menuManager);

    MenuManager sourceMenu = new MenuManager("Source");
    menuManager.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, sourceMenu);
    sourceMenu.add(this.commentAction);
    sourceMenu.add(this.uncommentAction);
    sourceMenu.add(this.toggleCommentsAction);
  }
 /** Adds the three items to the edit-menu */
 @Override
 public void contributeToMenu(IMenuManager mm) {
   super.contributeToMenu(mm);
   IMenuManager editMenu = mm.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
   if (editMenu != null) {
     editMenu.add(new Separator());
     editMenu.add(contentAssistProposal);
     editMenu.add(formatProposal);
     editMenu.add(contentAssistContextInformation);
   }
 }
  /*
   * @see IEditorActionBarContributor#dispose()
   */
  @Override
  public void dispose() {

    Iterator<RetargetAction> e = fPartListeners.iterator();
    while (e.hasNext()) getPage().removePartListener(e.next());
    fPartListeners.clear();

    setActiveEditor(null);
    fToggleBreadcrumbAction.dispose();
    super.dispose();
  }
  @Override
  public void setActiveEditor(IEditorPart part) {
    super.setActiveEditor(part);

    ITextEditor textEditor = null;

    if (part instanceof ITextEditor) {
      textEditor = (ITextEditor) part;
    }

    toggleMarkOccurrencesAction.setEditor(textEditor);
  }
  /**
   * Sets the active editor to this contributor. This updates the actions to reflect the editor.
   *
   * @see EditorActionBarContributor#editorChanged
   */
  @Override
  public void setActiveEditor(IEditorPart part) {

    super.setActiveEditor(part);

    ITextEditor editor = null;
    if (part instanceof ITextEditor) editor = (ITextEditor) part;

    contentAssistProposal.setAction(
        getAction(editor, IChameleonEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS));
    formatProposal.setAction(getAction(editor, IChameleonEditorActionDefinitionIds.FORMAT));
    contentAssistContextInformation.setAction(
        getAction(editor, IChameleonEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION));
  }
  /*
   * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
   */
  @Override
  public void init(IActionBars bars, IWorkbenchPage page) {
    fToggleBreadcrumbAction = new ToggleBreadcrumbAction(page);
    Iterator<RetargetAction> e = fPartListeners.iterator();
    while (e.hasNext()) page.addPartListener(e.next());

    super.init(bars, page);

    bars.setGlobalActionHandler(
        ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
    bars.setGlobalActionHandler(
        IJavaEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
    bars.setGlobalActionHandler(
        IJavaEditorActionDefinitionIds.TOGGLE_BREADCRUMB, fToggleBreadcrumbAction);
  }
  /*
   * @see EditorActionBarContributor#setActiveEditor(IEditorPart)
   */
  @Override
  public void setActiveEditor(IEditorPart part) {

    super.setActiveEditor(part);

    ITextEditor textEditor = null;
    if (part instanceof ITextEditor) textEditor = (ITextEditor) part;

    fTogglePresentation.setEditor(textEditor);
    fToggleMarkOccurrencesAction.setEditor(textEditor);

    fGotoMatchingBracket.setAction(
        getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
    fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
    fOpenHierarchy.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_HIERARCHY));
    fOpenStructure.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_STRUCTURE));

    fStructureSelectEnclosingAction.setAction(
        getAction(textEditor, StructureSelectionAction.ENCLOSING));
    fStructureSelectNextAction.setAction(getAction(textEditor, StructureSelectionAction.NEXT));
    fStructureSelectPreviousAction.setAction(
        getAction(textEditor, StructureSelectionAction.PREVIOUS));
    fStructureSelectHistoryAction.setAction(
        getAction(textEditor, StructureSelectionAction.HISTORY));

    fGotoNextMemberAction.setAction(
        getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER));
    fGotoPreviousMemberAction.setAction(
        getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER));

    fRemoveOccurrenceAnnotationsAction.setAction(
        getAction(textEditor, "RemoveOccurrenceAnnotations")); // $NON-NLS-1$
    fRetargetShowInformationAction.setAction(
        getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION));

    if (part instanceof JavaEditor) {
      JavaEditor javaEditor = (JavaEditor) part;
      javaEditor.getActionGroup().fillActionBars(getActionBars());
      FoldingActionGroup foldingActions = javaEditor.getFoldingActionGroup();
      if (foldingActions != null) foldingActions.updateActionBars();
    }

    IActionBars actionBars = getActionBars();
    IStatusLineManager manager = actionBars.getStatusLineManager();
    manager.setMessage(null);
    manager.setErrorMessage(null);

    /** The global actions to be connected with editor actions */
    IAction action = getAction(textEditor, ITextEditorActionConstants.NEXT);
    actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action);
    action = getAction(textEditor, ITextEditorActionConstants.PREVIOUS);
    actionBars.setGlobalActionHandler(
        ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action);
    action = getAction(textEditor, IJavaEditorActionConstants.COPY_QUALIFIED_NAME);
    actionBars.setGlobalActionHandler(CopyQualifiedNameAction.ACTION_HANDLER_ID, action);

    actionBars.setGlobalActionHandler(
        IJavaEditorActionDefinitionIds.SHOW_IN_BREADCRUMB,
        getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_IN_BREADCRUMB));
    actionBars.setGlobalActionHandler(
        "org.eclipse.jdt.internal.ui.actions.OpenHyperlink",
        getAction(textEditor, ITextEditorActionConstants.OPEN_HYPERLINK)); // $NON-NLS-1$
  }