01: package com.xoetrope.editor.eclipse.langed;
02:
03: import org.eclipse.jface.action.*;
04: import org.eclipse.jface.dialogs.MessageDialog;
05: import org.eclipse.ui.IActionBars;
06: import org.eclipse.ui.IEditorPart;
07: import org.eclipse.ui.IWorkbenchActionConstants;
08: import org.eclipse.ui.PlatformUI;
09: import org.eclipse.ui.actions.ActionFactory;
10: import org.eclipse.ui.ide.IDE;
11: import org.eclipse.ui.ide.IDEActionFactory;
12: import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
13: import org.eclipse.ui.texteditor.ITextEditor;
14: import org.eclipse.ui.texteditor.ITextEditorActionConstants;
15:
16: /**
17: * Manages the installation/deinstallation of global actions for multi-page
18: * editors. Responsible for the redirection of global actions to the active
19: * editor. Multi-page contributor replaces the contributors for the individual
20: * editors in the multi-page editor.
21: */
22: public class LanguageEditorContributor extends
23: MultiPageEditorActionBarContributor {
24: private IEditorPart activeEditorPart;
25:
26: private Action sampleAction;
27:
28: /**
29: * Creates a multi-page contributor.
30: */
31: public LanguageEditorContributor() {
32: super ();
33: createActions();
34: }
35:
36: /**
37: * Returns the action registered with the given text editor.
38: *
39: * @return IAction or null if editor is null.
40: */
41: protected IAction getAction(ITextEditor editor, String actionID) {
42: return (editor == null ? null : editor.getAction(actionID));
43: }
44:
45: /*
46: * (non-JavaDoc) Method declared in
47: * AbstractMultiPageEditorActionBarContributor.
48: */
49:
50: public void setActivePage(IEditorPart part) {
51: if (activeEditorPart == part)
52: return;
53:
54: activeEditorPart = part;
55:
56: IActionBars actionBars = getActionBars();
57: if (actionBars != null) {
58: //
59: // ITextEditor editor = ( part instanceof ITextEditor ) ? (ITextEditor)part : null;
60: //
61: // actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), getAction( editor, ITextEditorActionConstants.DELETE ) );
62: // actionBars.setGlobalActionHandler( ActionFactory.UNDO.getId(), getAction( editor, ITextEditorActionConstants.UNDO ) );
63: // actionBars.setGlobalActionHandler( ActionFactory.REDO.getId(), getAction( editor, ITextEditorActionConstants.REDO ) );
64: // actionBars.setGlobalActionHandler( ActionFactory.CUT.getId(), getAction( editor, ITextEditorActionConstants.CUT ) );
65: // actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), getAction( editor, ITextEditorActionConstants.COPY ) );
66: // actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), getAction( editor, ITextEditorActionConstants.PASTE ) );
67: // actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), getAction( editor, ITextEditorActionConstants.SELECT_ALL ) );
68: // actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), getAction( editor, ITextEditorActionConstants.FIND ) );
69: // actionBars.setGlobalActionHandler( IDEActionFactory.BOOKMARK.getId(), getAction( editor, IDEActionFactory.BOOKMARK.getId() ) );
70: //
71: // actionBars.setGlobalActionHandler( ActionFactory.MAXIMIZE.getId(), getAction( editor, ITextEditorActionConstants.FIND ) );
72: // actionBars.updateActionBars();
73: }
74: }
75:
76: private void createActions() {
77: // sampleAction = new Action() {
78: // public void run() {
79: // MessageDialog.openInformation(null, "Kalideoscope Plug-in", "Sample
80: // Action Executed");
81: // }
82: // };
83: // sampleAction.setText("Sample Action");
84: // sampleAction.setToolTipText("Sample Action tool tip");
85: // sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
86: // getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
87: }
88:
89: public void contributeToMenu(IMenuManager manager) {
90: // IMenuManager menu = new MenuManager("Editor &Menu");
91: // manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
92: // menu.add(sampleAction);
93: }
94:
95: public void contributeToToolBar(IToolBarManager manager) {
96: // manager.add(new Separator());
97: // manager.add(sampleAction);
98: }
99: }
|