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
.IWorkbenchActionConstants
;
21 import org
.eclipse
.ui
.IWorkbenchWindow
;
22 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
23 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
25 import eu
.etaxonomy
.cdm
.io
.common
.ImportWrapper
;
26 import eu
.etaxonomy
.taxeditor
.actions
.TaxEditorActionFactory
;
27 import eu
.etaxonomy
.taxeditor
.actions
.io
.ExportAction
;
28 import eu
.etaxonomy
.taxeditor
.actions
.io
.ImportAction
;
29 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
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;
51 // private IWorkbenchAction redoAction;
53 // private IAction newNameAction;
55 private List
<IAction
> importActionList
;
57 private IAction exportJaxbAction
;
60 public ApplicationActionBarAdvisor(IActionBarConfigurer configurer
) {
64 protected void makeActions(final IWorkbenchWindow window
) {
65 // Creates the actions and registers them.
66 // Registering is needed to ensure that key bindings work.
67 // The corresponding commands keybindings are defined in the plugin.xml
69 // Registering also provides automatic disposal of the actions when
70 // the window is closed.
72 GlobalController
.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
75 register(TaxEditorActionFactory
.NEW
.create(window
));
76 register(TaxEditorActionFactory
.SAVE
.create(window
));
77 register(TaxEditorActionFactory
.QUIT
.create(window
));
80 register(TaxEditorActionFactory
.UNDO
.create(window
));
81 register(TaxEditorActionFactory
.REDO
.create(window
));
82 register(TaxEditorActionFactory
.CUT
.create(window
));
83 register(TaxEditorActionFactory
.COPY
.create(window
));
84 register(TaxEditorActionFactory
.PASTE
.create(window
));
85 register(TaxEditorActionFactory
.DELETE
.create(window
));
87 // Window menu actions
88 register(TaxEditorActionFactory
.PREFERENCES
.create(window
));
91 register(TaxEditorActionFactory
.ABOUT
.create(window
));
97 exportJaxbAction
= new ExportAction(ExportAction
.JAXB
);
98 register(exportJaxbAction
);
102 private void makeImportActions() {
104 importActionList
= new ArrayList
<IAction
>();
106 for (ImportWrapper wrapper
: ImportWrapper
.list()) {
107 IAction importAction
= new ImportAction(wrapper
);
108 register(importAction
);
109 importActionList
.add(importAction
);
113 private MenuManager
FILE_MENU(){
114 MenuManager fileMenu
= new MenuManager("&File",
115 IWorkbenchActionConstants
.M_FILE
);
117 // Create submenu for imports
118 MenuManager importMenu
= new MenuManager("Import ...", null);
120 // Create submenu for exports
121 MenuManager exportMenu
= new MenuManager("Export as ...", null);
123 // Populate file menu
124 fileMenu
.add(getAction(TaxEditorActionFactory
.NEW
.getId()));
125 fileMenu
.add(getAction(TaxEditorActionFactory
.SAVE
.getId()));
126 fileMenu
.add(new Separator());
127 fileMenu
.add(importMenu
);
128 fileMenu
.add(exportMenu
);
129 fileMenu
.add(new Separator());
130 fileMenu
.add(getAction(TaxEditorActionFactory
.QUIT
.getId()));
132 // Populate submenu for imports
133 for (IAction importAction
: importActionList
) {
134 importMenu
.add(importAction
);
137 // Populate submenu for exports
138 exportMenu
.add(exportJaxbAction
);
144 private MenuManager
EDIT_MENU() {
146 MenuManager editMenu
= new MenuManager("&Edit", IWorkbenchActionConstants
.M_EDIT
);
148 editMenu
.add(getAction(TaxEditorActionFactory
.UNDO
.getId()));
149 editMenu
.add(getAction(TaxEditorActionFactory
.REDO
.getId()));
150 editMenu
.add(new Separator());
151 editMenu
.add(getAction(TaxEditorActionFactory
.CUT
.getId()));
152 editMenu
.add(getAction(TaxEditorActionFactory
.COPY
.getId()));
153 editMenu
.add(getAction(TaxEditorActionFactory
.PASTE
.getId()));
154 editMenu
.add(new Separator());
155 editMenu
.add(getAction(TaxEditorActionFactory
.DELETE
.getId()));
160 private MenuManager
WINDOW_MENU() {
161 MenuManager windowMenu
= new MenuManager("&Window",
162 IWorkbenchActionConstants
.M_WINDOW
);
164 windowMenu
.add(getAction(TaxEditorActionFactory
.PREFERENCES
.getId()));
169 private MenuManager
HELP_MENU(){
170 MenuManager helpMenu
= new MenuManager("&Help",
171 IWorkbenchActionConstants
.M_HELP
);
173 helpMenu
.add(getAction(TaxEditorActionFactory
.ABOUT
.getId()));
178 protected void fillMenuBar(IMenuManager menuBar
) {
180 menuBar
.add(FILE_MENU());
182 menuBar
.add(EDIT_MENU());
184 menuBar
.add(WINDOW_MENU());
186 menuBar
.add(HELP_MENU());