KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dolphin > rcp > DolphinActionBarAdvisor


1 /*
2 * Copyright (C) 2005 Bourgeon Jérôme, Macherel Bruno
3 *
4 * This file is part of Dolphin
5 *
6 * Dolphin : An open source J2EE Deployment Tool JSR-88 compliant
7 * Contact: ishmael-dev@objectweb.org
8 *
9 * Dolphin is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or any later version.
13 *
14 * Dolphin is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with Dolphin; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */

24 package org.objectweb.dolphin.rcp;
25
26 import org.eclipse.jface.action.GroupMarker;
27 import org.eclipse.jface.action.IContributionItem;
28 import org.eclipse.jface.action.ICoolBarManager;
29 import org.eclipse.jface.action.IMenuManager;
30 import org.eclipse.jface.action.IToolBarManager;
31 import org.eclipse.jface.action.MenuManager;
32 import org.eclipse.jface.action.Separator;
33 import org.eclipse.jface.action.ToolBarContributionItem;
34 import org.eclipse.jface.action.ToolBarManager;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.ui.IWorkbenchActionConstants;
37 import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.actions.ActionFactory;
39 import org.eclipse.ui.actions.ContributionItemFactory;
40 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
41 import org.eclipse.ui.application.ActionBarAdvisor;
42 import org.eclipse.ui.application.IActionBarConfigurer;
43 import org.objectweb.dolphin.actions.ChangeWorkspaceAction;
44
45
46 /**
47  * This is the actionBarAdvisor for Dolphin
48  * @author Bourgeon Jérôme, Macherel Bruno
49  *
50  */

51 public class DolphinActionBarAdvisor extends ActionBarAdvisor {
52     //File menu
53
private IWorkbenchAction exitAction;
54     //Edit menu
55
private IWorkbenchAction undoAction;
56     private IWorkbenchAction redoAction;
57     private IWorkbenchAction cutAction;
58     private IWorkbenchAction copyAction;
59     private IWorkbenchAction pasteAction;
60     private IWorkbenchAction deleteAction;
61     private IWorkbenchAction selectAllAction;
62     //Window menu
63
private IContributionItem perspectiveList;
64     private IContributionItem viewList;
65     private IWorkbenchAction preferenceAction;
66     private IWorkbenchAction openWindowAction;
67     //Help menu
68
private IWorkbenchAction helpAction;
69     private IWorkbenchAction aboutAction;
70
71     private ChangeWorkspaceAction changeWorkspace;
72
73     /**
74      * @param configurer
75      */

76     public DolphinActionBarAdvisor(IActionBarConfigurer configurer) {
77         super(configurer);
78     }
79
80     // public void fillActionBars(IWorkbenchWindow window,
81
// IActionBarConfigurer configurer, int flags) {
82
// // super.fillActionBars(window, configurer, flags);
83
// if ((flags & ActionBarAdvisor.FILL_MENU_BAR) != 0) {
84
// fillMenuBar(window, configurer);
85
// }
86
// }
87

88     /**
89      * @see org.eclipse.ui.application.ActionBarAdvisor#makeActions(org.eclipse.ui.IWorkbenchWindow)
90      */

91     protected void makeActions(final IWorkbenchWindow window) {
92
93         //File menu
94
exitAction=ActionFactory.QUIT.create(window);
95         register(exitAction);
96
97         //Edit menu
98
undoAction=ActionFactory.UNDO.create(window);
99         register(undoAction);
100         redoAction=ActionFactory.REDO.create(window);
101         register(redoAction);
102         copyAction=ActionFactory.COPY.create(window);
103         register(copyAction);
104         cutAction=ActionFactory.CUT.create(window);
105         register(cutAction);
106         pasteAction=ActionFactory.PASTE.create(window);
107         register(pasteAction);
108         deleteAction=ActionFactory.DELETE.create(window);
109         register(deleteAction);
110         selectAllAction=ActionFactory.SELECT_ALL.create(window);
111         register(selectAllAction);
112
113         //Window
114
perspectiveList = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
115         viewList = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
116         preferenceAction=ActionFactory.PREFERENCES.create(window);
117         register(preferenceAction);
118         openWindowAction=ActionFactory.OPEN_NEW_WINDOW.create(window);
119         register(openWindowAction);
120
121         //Help
122
helpAction=ActionFactory.HELP_CONTENTS.create(window);
123         register(helpAction);
124         aboutAction=ActionFactory.ABOUT.create(window);
125         register(aboutAction);
126
127         changeWorkspace = new ChangeWorkspaceAction(window);
128         register(changeWorkspace);
129
130
131     }
132
133     /**
134      * @see org.eclipse.ui.application.ActionBarAdvisor#fillMenuBar(org.eclipse.jface.action.IMenuManager)
135      */

136     protected void fillMenuBar(IMenuManager menubar) {
137         createFileMenu(menubar);
138         createEditMenu(menubar);
139         createWindowMenu(menubar);
140         createHelpMenu(menubar);
141     }
142
143     /**
144      * createFileMenu
145      * @param menubar
146      */

147     private void createFileMenu(IMenuManager menubar) {
148         MenuManager fileMenu = new MenuManager(Messages.getString("FileMenu"), IWorkbenchActionConstants.M_FILE);
149         menubar.add(fileMenu);
150         menubar.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
151         menubar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
152         fileMenu.add(changeWorkspace);
153         fileMenu.add(exitAction);
154         menubar.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
155     }
156
157     /**
158      * createEditMenu
159      * @param menubar
160      */

161     private void createEditMenu(IMenuManager menubar) {
162         MenuManager editmenu = new MenuManager(Messages.getString("EditMenu"),IWorkbenchActionConstants.M_EDIT); //$NON-NLS-1$
163
menubar.add(editmenu);
164         menubar.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
165         editmenu.add(undoAction);
166         editmenu.add(redoAction);
167         editmenu.add(new Separator());
168         editmenu.add(copyAction);
169         editmenu.add(cutAction);
170         editmenu.add(pasteAction);
171         editmenu.add(deleteAction);
172         editmenu.add(new Separator());
173         editmenu.add(selectAllAction);
174         menubar.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
175         menubar.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
176     }
177
178     /**
179      * createWindowMenu
180      * @param menubar
181      */

182     private void createWindowMenu(IMenuManager menubar) {
183         MenuManager menuWindow = new MenuManager(Messages.getString("WindowMenu"), IWorkbenchActionConstants.M_WINDOW);//$NON-NLS-1$
184
MenuManager perspectiveMenu = new MenuManager(Messages.getString("WindowMenu_OpenPerspective"), "openPerspective"); //$NON-NLS-1$ //$NON-NLS-2$
185
perspectiveMenu.add(perspectiveList);
186         menuWindow.add(perspectiveMenu);
187         MenuManager viewMenu = new MenuManager(Messages.getString("WindowMenu_ShowView")); //$NON-NLS-1$
188
viewMenu.add(viewList);
189         menuWindow.add(viewMenu);
190         menuWindow.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
191         menuWindow.add(preferenceAction);
192         menuWindow.add(openWindowAction);
193         menubar.add(menuWindow);
194
195     }
196
197     /**
198      * createHelpMenu
199      * @param menubar
200      */

201     private void createHelpMenu(IMenuManager menubar) {
202         MenuManager menuHelp = new MenuManager(Messages.getString("HelpMenu"), IWorkbenchActionConstants.M_HELP); //$NON-NLS-1$
203
// Welcome or intro page would go here
204
menuHelp.add(helpAction);
205         // Tips and tricks page would go here
206
menuHelp.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
207         menuHelp.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
208         menuHelp.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
209         // About should always be at the bottom
210
// To use the real RCP About dialog uncomment these lines
211
menuHelp.add(new Separator());
212         menuHelp.add(aboutAction);
213         menubar.add(menuHelp);
214
215     }
216
217     /**
218      * @see org.eclipse.ui.application.ActionBarAdvisor#fillCoolBar(org.eclipse.jface.action.ICoolBarManager)
219      */

220     protected void fillCoolBar(ICoolBarManager coolbar){
221         IToolBarManager toolbar = new ToolBarManager(SWT.FLAT|SWT.RIGHT);
222         coolbar.add(new ToolBarContributionItem(toolbar,"main"));
223         toolbar.add(helpAction);
224         toolbar.add(aboutAction);
225
226     }
227
228 }
229
Popular Tags