1) Created CdmSessionDataRepository to keep track of all session data - all taxon...
[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 UiUtil.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
71
72 saveAction = ActionFactory.SAVE.create(window);
73 register(saveAction);
74
75 undoAction = ActionFactory.UNDO.create(window);
76 register(undoAction);
77
78 exitAction = ActionFactory.QUIT.create(window);
79 register(exitAction);
80
81 newNameAction = new OpenTaxonEditorAction();
82 register(newNameAction);
83
84 preferencesAction = ActionFactory.PREFERENCES.create(window);
85
86 makeImportActions();
87
88 exportJaxbAction = new ExportAction(ExportAction.JAXB);
89 register(exportJaxbAction);
90 }
91
92 private void makeImportActions() {
93
94 importActionList = new ArrayList<IAction>();
95
96 for (ImportWrapper wrapper : ImportWrapper.list()) {
97 IAction importAction = new ImportAction(wrapper);
98 register(importAction);
99 importActionList.add(importAction);
100 }
101 }
102
103 protected void fillMenuBar(IMenuManager menuBar) {
104
105 // Note: to hook into Eclipse File Menu, to use open File for instance,
106 // replace NULL with IWorkbenchActionConstants.M_FILE);
107 MenuManager fileMenu = new MenuManager("&File",
108 null);
109
110 // Create submenu for imports
111 MenuManager importMenu = new MenuManager("Import ...", null);
112
113 // Create submenu for exports
114 MenuManager exportMenu = new MenuManager("Export as ...", null);
115
116 // Populate file menu
117 menuBar.add(fileMenu);
118 fileMenu.add(newNameAction);
119 fileMenu.add(saveAction);
120 fileMenu.add(undoAction);
121 fileMenu.add(new Separator());
122 fileMenu.add(importMenu);
123 fileMenu.add(exportMenu);
124 fileMenu.add(new Separator());
125 fileMenu.add(exitAction);
126
127 // Populate submenu for imports
128 for (IAction importAction : importActionList) {
129 importMenu.add(importAction);
130 }
131
132 // Populate submenu for exports
133 exportMenu.add(exportJaxbAction);
134
135 // Populate preferences
136 MenuManager preferencesMenu = new MenuManager("&Preferences",
137 null);
138 menuBar.add(preferencesMenu);
139 preferencesMenu.add(preferencesAction);
140 }
141 }