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
;
31 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
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
42 public class ApplicationActionBarAdvisor
extends ActionBarAdvisor
{
43 private static final Logger logger
= Logger
44 .getLogger(ApplicationActionBarAdvisor
.class);
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
;
55 private IAction newNameAction
;
57 private List
<IAction
> importActionList
;
59 private IAction exportJaxbAction
;
62 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer
) {
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
71 // Registering also provides automatic disposal of the actions when
72 // the window is closed.
74 GlobalController
.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
76 saveAction
= ActionFactory
.SAVE
.create(window
);
79 undoAction
= ActionFactory
.UNDO
.create(window
);
82 redoAction
= ActionFactory
.REDO
.create(window
);
85 exitAction
= ActionFactory
.QUIT
.create(window
);
88 newNameAction
= new OpenTaxonEditorAction();
89 register(newNameAction
);
91 preferencesAction
= ActionFactory
.PREFERENCES
.create(window
);
95 exportJaxbAction
= new ExportAction(ExportAction
.JAXB
);
96 register(exportJaxbAction
);
99 private void makeImportActions() {
101 importActionList
= new ArrayList
<IAction
>();
103 for (ImportWrapper wrapper
: ImportWrapper
.list()) {
104 IAction importAction
= new ImportAction(wrapper
);
105 register(importAction
);
106 importActionList
.add(importAction
);
110 protected void fillMenuBar(IMenuManager menuBar
) {
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",
117 MenuManager editMenu
= new MenuManager("&Edit", null);
119 // Create submenu for imports
120 MenuManager importMenu
= new MenuManager("Import ...", null);
122 // Create submenu for exports
123 MenuManager exportMenu
= new MenuManager("Export as ...", null);
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
);
135 menuBar
.add(editMenu
);
136 editMenu
.add(undoAction
);
137 editMenu
.add(redoAction
);
139 // Populate submenu for imports
140 for (IAction importAction
: importActionList
) {
141 importMenu
.add(importAction
);
144 // Populate submenu for exports
145 exportMenu
.add(exportJaxbAction
);
147 // Populate preferences
148 MenuManager preferencesMenu
= new MenuManager("&Preferences",
150 menuBar
.add(preferencesMenu
);
151 preferencesMenu
.add(preferencesAction
);