started implementing command framework
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / ApplicationActionBarAdvisor.java
index 70c78b5da8d0c91d1b1116f64c301dc80926a833..33a03568b949dc06071363b093e954be8271fcb5 100644 (file)
@@ -9,19 +9,24 @@
 
 package eu.etaxonomy.taxeditor;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
 import org.eclipse.ui.application.ActionBarAdvisor;
 import org.eclipse.ui.application.IActionBarConfigurer;
 
-import eu.etaxonomy.taxeditor.actions.ui.OpenNameRelationWizardAction;
-import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction;
+import eu.etaxonomy.cdm.io.common.ImportWrapper;
+import eu.etaxonomy.taxeditor.actions.TaxEditorActionFactory;
+import eu.etaxonomy.taxeditor.actions.io.ExportAction;
+import eu.etaxonomy.taxeditor.actions.io.ImportAction;
+import eu.etaxonomy.taxeditor.controller.GlobalController;
 
 /**
  * An action bar advisor is responsible for creating, adding, and disposing of
@@ -36,60 +41,155 @@ public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
        private static final Logger logger = Logger
                        .getLogger(ApplicationActionBarAdvisor.class);
 
+       protected void makeActions(final IWorkbenchWindow window) {
+               GlobalController.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
+       }
+
+       protected void fillMenuBar(IMenuManager menuBar) {
+       }
+       
        // Actions - important to allocate these only in makeActions, and then use
        // them in the fill methods. This ensures that the actions aren't recreated
        // when fillActionBars is called with FILL_PROXY.
-       private IWorkbenchAction exitAction;
-       private IWorkbenchAction saveAction;
-       private IWorkbenchAction preferencesAction;
-       private IWorkbenchAction undoAction;
-       
-       private IAction newNameAction;
+//     private IWorkbenchAction exitAction;
+//     private IWorkbenchAction saveAction;
+//     private IWorkbenchAction preferencesAction;
+//     private IWorkbenchAction undoAction;
+//     private IWorkbenchAction redoAction;
+//     
+//     private IAction newNameAction;
+
+       private List<IAction> importActionList;
+
+       private IAction exportJaxbAction;
+
 
        public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
                super(configurer);
        }
 
-       protected void makeActions(final IWorkbenchWindow window) {
+       protected void _makeActions(final IWorkbenchWindow window) {
                // Creates the actions and registers them.
                // Registering is needed to ensure that key bindings work.
                // The corresponding commands keybindings are defined in the plugin.xml
                // file.
                // Registering also provides automatic disposal of the actions when
                // the window is closed.
-
-               saveAction = ActionFactory.SAVE.create(window);
-               register(saveAction);
                
-               undoAction = ActionFactory.UNDO.create(window);
-               register(undoAction);
+               GlobalController.setStatusLineManager(getActionBarConfigurer().getStatusLineManager());
                
-               exitAction = ActionFactory.QUIT.create(window);
-               register(exitAction);
+               // File menu actions
+               register(TaxEditorActionFactory.NEW.create(window));
+               register(TaxEditorActionFactory.SAVE.create(window));
+               register(TaxEditorActionFactory.QUIT.create(window));
                
-               newNameAction = new OpenTaxonEditorAction();
-               register(newNameAction);
+               // Edit menu actions
+               register(TaxEditorActionFactory.UNDO.create(window));
+               register(TaxEditorActionFactory.REDO.create(window));
+               register(TaxEditorActionFactory.CUT.create(window));
+               register(TaxEditorActionFactory.COPY.create(window));
+               register(TaxEditorActionFactory.PASTE.create(window));
+               register(TaxEditorActionFactory.DELETE.create(window));
                
-               preferencesAction = ActionFactory.PREFERENCES.create(window);
+               // Window menu actions
+               register(TaxEditorActionFactory.PREFERENCES.create(window));
+               
+               // Help menu actions
+               register(TaxEditorActionFactory.ABOUT.create(window));
+               
+               
+               
+               makeImportActions();
+               
+               exportJaxbAction = new ExportAction(ExportAction.JAXB);
+               register(exportJaxbAction);
        }
 
-       protected void fillMenuBar(IMenuManager menuBar) {
+
+       private void makeImportActions() {
+               
+               importActionList = new ArrayList<IAction>();
+               
+               for (ImportWrapper wrapper : ImportWrapper.list()) {
+                       IAction importAction = new ImportAction(wrapper);
+                       register(importAction);
+                       importActionList.add(importAction);             
+               }
+       }
+       
+       private MenuManager FILE_MENU(){
                MenuManager fileMenu = new MenuManager("&File",
-                               null);
-               // Note: to hook into Eclipse File Menu, to use open File for instance,
-               //  replace NULL with IWorkbenchActionConstants.M_FILE);
-
-               menuBar.add(fileMenu);
-               fileMenu.add(newNameAction);
-               fileMenu.add(saveAction);
-               fileMenu.add(undoAction);
+                               IWorkbenchActionConstants.M_FILE);
+               
+               // Create submenu for imports
+               MenuManager importMenu = new MenuManager("Import ...", null);
+               
+               // Create submenu for exports
+               MenuManager exportMenu = new MenuManager("Export as ...", null);
+       
+               // Populate file menu
+               fileMenu.add(getAction(TaxEditorActionFactory.NEW.getId()));
+               fileMenu.add(getAction(TaxEditorActionFactory.SAVE.getId()));
+               fileMenu.add(new Separator());
+               fileMenu.add(importMenu);
+               fileMenu.add(exportMenu);
                fileMenu.add(new Separator());
-               fileMenu.add(exitAction);
+               fileMenu.add(getAction(TaxEditorActionFactory.QUIT.getId()));
+               
+               // Populate submenu for imports
+               for (IAction importAction : importActionList) {
+                       importMenu.add(importAction);
+               }
+
+               // Populate submenu for exports
+               exportMenu.add(exportJaxbAction);
+               
+               return fileMenu;
+       }
+
+       
+       private MenuManager EDIT_MENU() {
+
+               MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
+               
+               editMenu.add(getAction(TaxEditorActionFactory.UNDO.getId()));
+               editMenu.add(getAction(TaxEditorActionFactory.REDO.getId()));
+               editMenu.add(new Separator());
+               editMenu.add(getAction(TaxEditorActionFactory.CUT.getId()));
+               editMenu.add(getAction(TaxEditorActionFactory.COPY.getId()));
+               editMenu.add(getAction(TaxEditorActionFactory.PASTE.getId()));
+               editMenu.add(new Separator());
+               editMenu.add(getAction(TaxEditorActionFactory.DELETE.getId()));
+               
+               return editMenu;
+       }
+
+       private MenuManager WINDOW_MENU() {
+               MenuManager windowMenu = new MenuManager("&Window",
+                               IWorkbenchActionConstants.M_WINDOW);
+
+               windowMenu.add(getAction(TaxEditorActionFactory.PREFERENCES.getId()));
+               
+               return windowMenu;
+       }
+       
+       private MenuManager HELP_MENU(){
+               MenuManager helpMenu = new MenuManager("&Help",
+                               IWorkbenchActionConstants.M_HELP);
                
-               MenuManager preferencesMenu = new MenuManager("&Preferences",
-                               null);
-               menuBar.add(preferencesMenu);
-               preferencesMenu.add(preferencesAction);
+               helpMenu.add(getAction(TaxEditorActionFactory.ABOUT.getId()));
+               
+               return helpMenu;
        }
 
-}
+       protected void _fillMenuBar(IMenuManager menuBar) {
+               
+               menuBar.add(FILE_MENU());
+               
+               menuBar.add(EDIT_MENU());
+               
+               menuBar.add(WINDOW_MENU());
+               
+               menuBar.add(HELP_MENU());
+       }
+}
\ No newline at end of file