Version 1.01
[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
26 import eu.etaxonomy.cdm.io.common.ImportWrapper;
27 import eu.etaxonomy.taxeditor.actions.io.ExportAction;
28 import eu.etaxonomy.taxeditor.actions.io.ImportAction;
29 import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction;
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
52 private IAction newNameAction;
53
54 private List<IAction> importActionList;
55
56 private IAction exportJaxbAction;
57
58 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
59 super(configurer);
60 }
61
62 protected void makeActions(final IWorkbenchWindow window) {
63 // Creates the actions and registers them.
64 // Registering is needed to ensure that key bindings work.
65 // The corresponding commands keybindings are defined in the plugin.xml
66 // file.
67 // Registering also provides automatic disposal of the actions when
68 // the window is closed.
69
70 saveAction = ActionFactory.SAVE.create(window);
71 register(saveAction);
72
73 undoAction = ActionFactory.UNDO.create(window);
74 register(undoAction);
75
76 exitAction = ActionFactory.QUIT.create(window);
77 register(exitAction);
78
79 newNameAction = new OpenTaxonEditorAction();
80 register(newNameAction);
81
82 preferencesAction = ActionFactory.PREFERENCES.create(window);
83
84 makeImportActions();
85
86 exportJaxbAction = new ExportAction(ExportAction.JAXB);
87 register(exportJaxbAction);
88 }
89
90 private void makeImportActions() {
91
92 importActionList = new ArrayList<IAction>();
93
94 for (ImportWrapper wrapper : ImportWrapper.list()) {
95 IAction importAction = new ImportAction(wrapper);
96 register(importAction);
97 importActionList.add(importAction);
98 }
99 }
100
101 protected void fillMenuBar(IMenuManager menuBar) {
102
103 // Note: to hook into Eclipse File Menu, to use open File for instance,
104 // replace NULL with IWorkbenchActionConstants.M_FILE);
105 MenuManager fileMenu = new MenuManager("&File",
106 null);
107
108 // Create submenu for imports
109 MenuManager importMenu = new MenuManager("Import ...", null);
110
111 // Create submenu for exports
112 MenuManager exportMenu = new MenuManager("Export as ...", null);
113
114 // Populate file menu
115 menuBar.add(fileMenu);
116 fileMenu.add(newNameAction);
117 fileMenu.add(saveAction);
118 fileMenu.add(undoAction);
119 fileMenu.add(new Separator());
120 // fileMenu.add(importMenu);
121 // fileMenu.add(exportMenu);
122 // fileMenu.add(new Separator());
123 fileMenu.add(exitAction);
124
125 // Populate submenu for imports
126 for (IAction importAction : importActionList) {
127 importMenu.add(importAction);
128 }
129
130 // Populate submenu for exports
131 exportMenu.add(exportJaxbAction);
132
133 // Populate preferences
134 MenuManager preferencesMenu = new MenuManager("&Preferences",
135 null);
136 menuBar.add(preferencesMenu);
137 preferencesMenu.add(preferencesAction);
138 }
139 }