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