2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
;
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
;
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
41 public class ApplicationActionBarAdvisor
extends ActionBarAdvisor
{
42 private static final Logger logger
= Logger
43 .getLogger(ApplicationActionBarAdvisor
.class);
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
;
54 private IAction newNameAction
;
56 private List
<IAction
> importActionList
;
58 private IAction exportJaxbAction
;
61 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer
) {
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
70 // Registering also provides automatic disposal of the actions when
71 // the window is closed.
73 UiUtil
.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
75 saveAction
= ActionFactory
.SAVE
.create(window
);
78 undoAction
= ActionFactory
.UNDO
.create(window
);
81 redoAction
= ActionFactory
.REDO
.create(window
);
84 exitAction
= ActionFactory
.QUIT
.create(window
);
87 newNameAction
= new OpenTaxonEditorAction();
88 register(newNameAction
);
90 preferencesAction
= ActionFactory
.PREFERENCES
.create(window
);
94 exportJaxbAction
= new ExportAction(ExportAction
.JAXB
);
95 register(exportJaxbAction
);
98 private void makeImportActions() {
100 importActionList
= new ArrayList
<IAction
>();
102 for (ImportWrapper wrapper
: ImportWrapper
.list()) {
103 IAction importAction
= new ImportAction(wrapper
);
104 register(importAction
);
105 importActionList
.add(importAction
);
109 protected void fillMenuBar(IMenuManager menuBar
) {
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",
116 MenuManager editMenu
= new MenuManager("&Edit", null);
118 // Create submenu for imports
119 MenuManager importMenu
= new MenuManager("Import ...", null);
121 // Create submenu for exports
122 MenuManager exportMenu
= new MenuManager("Export as ...", null);
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
);
134 menuBar
.add(editMenu
);
135 editMenu
.add(undoAction
);
136 editMenu
.add(redoAction
);
138 // Populate submenu for imports
139 for (IAction importAction
: importActionList
) {
140 importMenu
.add(importAction
);
143 // Populate submenu for exports
144 exportMenu
.add(exportJaxbAction
);
146 // Populate preferences
147 MenuManager preferencesMenu
= new MenuManager("&Preferences",
149 menuBar
.add(preferencesMenu
);
150 preferencesMenu
.add(preferencesAction
);