004c8c4699b4874692e0c120d773c98ab45141dc
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / ApplicationActionBarAdvisor.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor;
11
12 import java.util.List;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.MenuManager;
18 import org.eclipse.jface.action.Separator;
19 import org.eclipse.ui.IWorkbenchActionConstants;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.application.ActionBarAdvisor;
22 import org.eclipse.ui.application.IActionBarConfigurer;
23
24 import eu.etaxonomy.taxeditor.actions.TaxEditorActionFactory;
25 import eu.etaxonomy.taxeditor.actions.io.ExportAction;
26 import eu.etaxonomy.taxeditor.controller.GlobalController;
27
28 /**
29 * An action bar advisor is responsible for creating, adding, and disposing of
30 * the actions added to a workbench window. Each window will be populated with
31 * new actions.
32 *
33 * @author p.ciardelli
34 * @created 02.06.2008
35 * @version 1.0
36 */
37 public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
38 private static final Logger logger = Logger
39 .getLogger(ApplicationActionBarAdvisor.class);
40
41 protected void makeActions(final IWorkbenchWindow window) {
42 GlobalController.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
43 }
44
45 protected void fillMenuBar(IMenuManager menuBar) {
46 }
47
48 // Actions - important to allocate these only in makeActions, and then use
49 // them in the fill methods. This ensures that the actions aren't recreated
50 // when fillActionBars is called with FILL_PROXY.
51 // private IWorkbenchAction exitAction;
52 // private IWorkbenchAction saveAction;
53 // private IWorkbenchAction preferencesAction;
54 // private IWorkbenchAction undoAction;
55 // private IWorkbenchAction redoAction;
56 //
57 // private IAction newNameAction;
58
59 private List<IAction> importActionList;
60
61 private IAction exportJaxbAction;
62
63
64 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
65 super(configurer);
66 }
67
68 protected void _makeActions(final IWorkbenchWindow window) {
69 // Creates the actions and registers them.
70 // Registering is needed to ensure that key bindings work.
71 // The corresponding commands keybindings are defined in the plugin.xml
72 // file.
73 // Registering also provides automatic disposal of the actions when
74 // the window is closed.
75
76 GlobalController.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
77
78 // File menu actions
79 register(TaxEditorActionFactory.NEW.create(window));
80 register(TaxEditorActionFactory.SAVE.create(window));
81 register(TaxEditorActionFactory.QUIT.create(window));
82
83 // Edit menu actions
84 register(TaxEditorActionFactory.UNDO.create(window));
85 register(TaxEditorActionFactory.REDO.create(window));
86 register(TaxEditorActionFactory.CUT.create(window));
87 register(TaxEditorActionFactory.COPY.create(window));
88 register(TaxEditorActionFactory.PASTE.create(window));
89 register(TaxEditorActionFactory.DELETE.create(window));
90
91 // Window menu actions
92 register(TaxEditorActionFactory.PREFERENCES.create(window));
93
94 // Help menu actions
95 register(TaxEditorActionFactory.ABOUT.create(window));
96
97
98
99 makeImportActions();
100
101 exportJaxbAction = new ExportAction(ExportAction.JAXB);
102 register(exportJaxbAction);
103 }
104
105
106 private void makeImportActions() {
107
108 // importActionList = new ArrayList<IAction>();
109 //
110 // for (ImportWrapper wrapper : ImportWrapper.list()) {
111 // IAction importAction = new ImportAction(wrapper);
112 // register(importAction);
113 // importActionList.add(importAction);
114 // }
115 }
116
117 private MenuManager FILE_MENU(){
118 MenuManager fileMenu = new MenuManager("&File",
119 IWorkbenchActionConstants.M_FILE);
120
121 // Create submenu for imports
122 MenuManager importMenu = new MenuManager("Import ...", null);
123
124 // Create submenu for exports
125 MenuManager exportMenu = new MenuManager("Export as ...", null);
126
127 // Populate file menu
128 fileMenu.add(getAction(TaxEditorActionFactory.NEW.getId()));
129 fileMenu.add(getAction(TaxEditorActionFactory.SAVE.getId()));
130 fileMenu.add(new Separator());
131 fileMenu.add(importMenu);
132 fileMenu.add(exportMenu);
133 fileMenu.add(new Separator());
134 fileMenu.add(getAction(TaxEditorActionFactory.QUIT.getId()));
135
136 // Populate submenu for imports
137 for (IAction importAction : importActionList) {
138 importMenu.add(importAction);
139 }
140
141 // Populate submenu for exports
142 exportMenu.add(exportJaxbAction);
143
144 return fileMenu;
145 }
146
147
148 private MenuManager EDIT_MENU() {
149
150 MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
151
152 editMenu.add(getAction(TaxEditorActionFactory.UNDO.getId()));
153 editMenu.add(getAction(TaxEditorActionFactory.REDO.getId()));
154 editMenu.add(new Separator());
155 editMenu.add(getAction(TaxEditorActionFactory.CUT.getId()));
156 editMenu.add(getAction(TaxEditorActionFactory.COPY.getId()));
157 editMenu.add(getAction(TaxEditorActionFactory.PASTE.getId()));
158 editMenu.add(new Separator());
159 editMenu.add(getAction(TaxEditorActionFactory.DELETE.getId()));
160
161 return editMenu;
162 }
163
164 private MenuManager WINDOW_MENU() {
165 MenuManager windowMenu = new MenuManager("&Window",
166 IWorkbenchActionConstants.M_WINDOW);
167
168 windowMenu.add(getAction(TaxEditorActionFactory.PREFERENCES.getId()));
169
170 return windowMenu;
171 }
172
173 private MenuManager HELP_MENU(){
174 MenuManager helpMenu = new MenuManager("&Help",
175 IWorkbenchActionConstants.M_HELP);
176
177 helpMenu.add(getAction(TaxEditorActionFactory.ABOUT.getId()));
178
179 return helpMenu;
180 }
181
182 protected void _fillMenuBar(IMenuManager menuBar) {
183
184 menuBar.add(FILE_MENU());
185
186 menuBar.add(EDIT_MENU());
187
188 menuBar.add(WINDOW_MENU());
189
190 menuBar.add(HELP_MENU());
191 }
192 }