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