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
;
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
;
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
40 public class ApplicationActionBarAdvisor
extends ActionBarAdvisor
{
41 private static final Logger logger
= Logger
42 .getLogger(ApplicationActionBarAdvisor
.class);
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
;
52 private IAction newNameAction
;
54 private List
<IAction
> importActionList
;
56 private IAction exportJaxbAction
;
58 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer
) {
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
67 // Registering also provides automatic disposal of the actions when
68 // the window is closed.
70 saveAction
= ActionFactory
.SAVE
.create(window
);
73 undoAction
= ActionFactory
.UNDO
.create(window
);
76 exitAction
= ActionFactory
.QUIT
.create(window
);
79 newNameAction
= new OpenTaxonEditorAction();
80 register(newNameAction
);
82 preferencesAction
= ActionFactory
.PREFERENCES
.create(window
);
86 exportJaxbAction
= new ExportAction(ExportAction
.JAXB
);
87 register(exportJaxbAction
);
90 private void makeImportActions() {
92 importActionList
= new ArrayList
<IAction
>();
94 for (ImportWrapper wrapper
: ImportWrapper
.list()) {
95 IAction importAction
= new ImportAction(wrapper
);
96 register(importAction
);
97 importActionList
.add(importAction
);
101 protected void fillMenuBar(IMenuManager menuBar
) {
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",
108 // Create submenu for imports
109 MenuManager importMenu
= new MenuManager("Import ...", null);
111 // Create submenu for exports
112 MenuManager exportMenu
= new MenuManager("Export as ...", null);
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
);
125 // Populate submenu for imports
126 for (IAction importAction
: importActionList
) {
127 importMenu
.add(importAction
);
130 // Populate submenu for exports
131 exportMenu
.add(exportJaxbAction
);
133 // Populate preferences
134 MenuManager preferencesMenu
= new MenuManager("&Preferences",
136 menuBar
.add(preferencesMenu
);
137 preferencesMenu
.add(preferencesAction
);