Source code: com/port80/eclipse/jdt/graph/views/GraphViewerContributor.java
1 package com.port80.eclipse.jdt.graph.views;
2
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.action.IAction;
5 import org.eclipse.ui.IActionBars;
6 import org.eclipse.ui.IEditorPart;
7 import org.eclipse.ui.IWorkbenchActionConstants;
8 import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
9 import org.eclipse.ui.texteditor.ITextEditor;
10 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
11
12 /**
13 * Manages the installation/deinstallation of global actions for multi-page editors.
14 * Responsible for the redirection of global actions to the active editor.
15 * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
16 */
17 public class GraphViewerContributor extends MultiPageEditorActionBarContributor {
18 private IEditorPart activeEditorPart;
19 private Action sampleAction;
20 /**
21 * Creates a multi-page contributor.
22 */
23 public GraphViewerContributor() {
24 super();
25 }
26 /**
27 * Returns the action registed with the given text editor.
28 * @return IAction or null if editor is null.
29 */
30 protected IAction getAction(ITextEditor editor, String actionID) {
31 return (editor == null ? null : editor.getAction(actionID));
32 }
33 /* (non-JavaDoc)
34 * Method declared in AbstractMultiPageEditorActionBarContributor.
35 */
36
37 public void setActivePage(IEditorPart part) {
38 if (activeEditorPart == part)
39 return;
40
41 activeEditorPart = part;
42
43 IActionBars actionBars = getActionBars();
44 if (actionBars != null) {
45
46 ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
47
48 actionBars.setGlobalActionHandler(
49 IWorkbenchActionConstants.DELETE,
50 getAction(editor, ITextEditorActionConstants.DELETE));
51 actionBars.setGlobalActionHandler(
52 IWorkbenchActionConstants.UNDO,
53 getAction(editor, ITextEditorActionConstants.UNDO));
54 actionBars.setGlobalActionHandler(
55 IWorkbenchActionConstants.REDO,
56 getAction(editor, ITextEditorActionConstants.REDO));
57 actionBars.setGlobalActionHandler(
58 IWorkbenchActionConstants.CUT,
59 getAction(editor, ITextEditorActionConstants.CUT));
60 actionBars.setGlobalActionHandler(
61 IWorkbenchActionConstants.COPY,
62 getAction(editor, ITextEditorActionConstants.COPY));
63 actionBars.setGlobalActionHandler(
64 IWorkbenchActionConstants.PASTE,
65 getAction(editor, ITextEditorActionConstants.PASTE));
66 actionBars.setGlobalActionHandler(
67 IWorkbenchActionConstants.SELECT_ALL,
68 getAction(editor, ITextEditorActionConstants.SELECT_ALL));
69 actionBars.setGlobalActionHandler(
70 IWorkbenchActionConstants.FIND,
71 getAction(editor, ITextEditorActionConstants.FIND));
72 actionBars.setGlobalActionHandler(
73 IWorkbenchActionConstants.BOOKMARK,
74 getAction(editor, ITextEditorActionConstants.BOOKMARK));
75 actionBars.updateActionBars();
76 }
77 }
78 }