Massive refactoring of the methodology in former class UiUtils
[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.IWorkbenchWindow;
21 import org.eclipse.ui.actions.ActionFactory;
22 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
23 import org.eclipse.ui.application.ActionBarAdvisor;
24 import org.eclipse.ui.application.IActionBarConfigurer;
25 import org.eclipse.ui.operations.UndoActionHandler;
26
27 import eu.etaxonomy.cdm.io.common.ImportWrapper;
28 import eu.etaxonomy.taxeditor.actions.io.ExportAction;
29 import eu.etaxonomy.taxeditor.actions.io.ImportAction;
30 import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction;
31 import eu.etaxonomy.taxeditor.controller.GlobalController;
32
33 /**
34 * An action bar advisor is responsible for creating, adding, and disposing of
35 * the actions added to a workbench window. Each window will be populated with
36 * new actions.
37 *
38 * @author p.ciardelli
39 * @created 02.06.2008
40 * @version 1.0
41 */
42 public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
43 private static final Logger logger = Logger
44 .getLogger(ApplicationActionBarAdvisor.class);
45
46 // Actions - important to allocate these only in makeActions, and then use
47 // them in the fill methods. This ensures that the actions aren't recreated
48 // when fillActionBars is called with FILL_PROXY.
49 private IWorkbenchAction exitAction;
50 private IWorkbenchAction saveAction;
51 private IWorkbenchAction preferencesAction;
52 private IWorkbenchAction undoAction;
53 private IWorkbenchAction redoAction;
54
55 private IAction newNameAction;
56
57 private List<IAction> importActionList;
58
59 private IAction exportJaxbAction;
60
61
62 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
63 super(configurer);
64 }
65
66 protected void makeActions(final IWorkbenchWindow window) {
67 // Creates the actions and registers them.
68 // Registering is needed to ensure that key bindings work.
69 // The corresponding commands keybindings are defined in the plugin.xml
70 // file.
71 // Registering also provides automatic disposal of the actions when
72 // the window is closed.
73
74 GlobalController.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
75
76 saveAction = ActionFactory.SAVE.create(window);
77 register(saveAction);
78
79 undoAction = ActionFactory.UNDO.create(window);
80 register(undoAction);
81
82 redoAction = ActionFactory.REDO.create(window);
83 register(redoAction);
84
85 exitAction = ActionFactory.QUIT.create(window);
86 register(exitAction);
87
88 newNameAction = new OpenTaxonEditorAction();
89 register(newNameAction);
90
91 preferencesAction = ActionFactory.PREFERENCES.create(window);
92
93 makeImportActions();
94
95 exportJaxbAction = new ExportAction(ExportAction.JAXB);
96 register(exportJaxbAction);
97 }
98
99 private void makeImportActions() {
100
101 importActionList = new ArrayList<IAction>();
102
103 for (ImportWrapper wrapper : ImportWrapper.list()) {
104 IAction importAction = new ImportAction(wrapper);
105 register(importAction);
106 importActionList.add(importAction);
107 }
108 }
109
110 protected void fillMenuBar(IMenuManager menuBar) {
111
112 // Note: to hook into Eclipse File Menu, to use open File for instance,
113 // replace NULL with IWorkbenchActionConstants.M_FILE);
114 MenuManager fileMenu = new MenuManager("&File",
115 null);
116
117 MenuManager editMenu = new MenuManager("&Edit", null);
118
119 // Create submenu for imports
120 MenuManager importMenu = new MenuManager("Import ...", null);
121
122 // Create submenu for exports
123 MenuManager exportMenu = new MenuManager("Export as ...", null);
124
125 // Populate file menu
126 menuBar.add(fileMenu);
127 fileMenu.add(newNameAction);
128 fileMenu.add(saveAction);
129 fileMenu.add(new Separator());
130 fileMenu.add(importMenu);
131 fileMenu.add(exportMenu);
132 fileMenu.add(new Separator());
133 fileMenu.add(exitAction);
134
135 menuBar.add(editMenu);
136 editMenu.add(undoAction);
137 editMenu.add(redoAction);
138
139 // Populate submenu for imports
140 for (IAction importAction : importActionList) {
141 importMenu.add(importAction);
142 }
143
144 // Populate submenu for exports
145 exportMenu.add(exportJaxbAction);
146
147 // Populate preferences
148 MenuManager preferencesMenu = new MenuManager("&Preferences",
149 null);
150 menuBar.add(preferencesMenu);
151 preferencesMenu.add(preferencesAction);
152 }
153 }