KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > editors > ConfigurationEditorContributor


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.editors;
5
6 import org.eclipse.jface.action.Action;
7 import org.eclipse.jface.action.IAction;
8 import org.eclipse.jface.action.IMenuManager;
9 import org.eclipse.jface.action.IToolBarManager;
10 import org.eclipse.jface.action.MenuManager;
11 import org.eclipse.jface.action.Separator;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.ui.IActionBars;
14 import org.eclipse.ui.IEditorPart;
15 import org.eclipse.ui.IWorkbenchActionConstants;
16 import org.eclipse.ui.PlatformUI;
17 import org.eclipse.ui.actions.ActionFactory;
18 import org.eclipse.ui.ide.IDE;
19 import org.eclipse.ui.ide.IDEActionFactory;
20 import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
21 import org.eclipse.ui.texteditor.ITextEditor;
22 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
23
24 public class ConfigurationEditorContributor
25   extends MultiPageEditorActionBarContributor
26 {
27   private IEditorPart activeEditorPart;
28   private Action sampleAction;
29   
30   public ConfigurationEditorContributor() {
31     super();
32     createActions();
33   }
34
35   protected IAction getAction(ITextEditor editor, String JavaDoc actionID) {
36     return (editor == null ? null : editor.getAction(actionID));
37   }
38
39   public void setActivePage(IEditorPart part) {
40     if(activeEditorPart == part) {
41       return;
42     }
43
44     activeEditorPart = part;
45
46     IActionBars actionBars = getActionBars();
47
48     if(actionBars != null) {
49       ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor)part : null;
50
51       actionBars.setGlobalActionHandler(
52         ActionFactory.DELETE.getId(),
53         getAction(editor, ITextEditorActionConstants.DELETE));
54       actionBars.setGlobalActionHandler(
55         ActionFactory.UNDO.getId(),
56         getAction(editor, ITextEditorActionConstants.UNDO));
57       actionBars.setGlobalActionHandler(
58         ActionFactory.REDO.getId(),
59         getAction(editor, ITextEditorActionConstants.REDO));
60       actionBars.setGlobalActionHandler(
61         ActionFactory.CUT.getId(),
62         getAction(editor, ITextEditorActionConstants.CUT));
63       actionBars.setGlobalActionHandler(
64         ActionFactory.COPY.getId(),
65         getAction(editor, ITextEditorActionConstants.COPY));
66       actionBars.setGlobalActionHandler(
67         ActionFactory.PASTE.getId(),
68         getAction(editor, ITextEditorActionConstants.PASTE));
69       actionBars.setGlobalActionHandler(
70         ActionFactory.SELECT_ALL.getId(),
71         getAction(editor, ITextEditorActionConstants.SELECT_ALL));
72       actionBars.setGlobalActionHandler(
73         ActionFactory.FIND.getId(),
74         getAction(editor, ITextEditorActionConstants.FIND));
75       actionBars.setGlobalActionHandler(
76         IDEActionFactory.BOOKMARK.getId(),
77         getAction(editor, IDEActionFactory.BOOKMARK.getId()));
78       actionBars.updateActionBars();
79     }
80   }
81
82   private void createActions() {
83     sampleAction = new Action() {
84       public void run() {
85         MessageDialog.openInformation(null,
86           "Tc Plug-in",
87           "Sample Action Executed");
88       }
89     };
90     sampleAction.setText("Sample Action");
91     sampleAction.setToolTipText("Sample Action tool tip");
92     sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
93       getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
94   }
95
96   public void contributeToMenu(IMenuManager manager) {
97     IMenuManager menu = new MenuManager("Editor &Menu");
98
99     manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
100     menu.add(sampleAction);
101   }
102
103   public void contributeToToolBar(IToolBarManager manager) {
104     manager.add(new Separator());
105     manager.add(sampleAction);
106   }
107 }
108
Popular Tags