tabbed_properties branch merged into trunk completely
authorn.hoffmann <n.hoffmann@localhost>
Wed, 9 Jun 2010 16:56:48 +0000 (16:56 +0000)
committern.hoffmann <n.hoffmann@localhost>
Wed, 9 Jun 2010 16:56:48 +0000 (16:56 +0000)
.gitattributes
taxeditor-navigation/META-INF/MANIFEST.MF
taxeditor-navigation/plugin.xml
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/StateManager.java [new file with mode: 0644]
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTreeNodeHandler.java
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditHandler.java [moved from taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java with 53% similarity]
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/NewTaxonNodeHandler.java
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/NewTaxonomicTreeHandler.java
taxeditor-navigation/src/test/java/eu/etaxonomy/taxeditor/navigation/ApplicationWorkbenchAdvisor.java

index 3305fb34b50e61c80b732c1ec2f73947d97f7147..5a237c7028cfd84ede2d60364cf0e882f8451983 100644 (file)
@@ -380,9 +380,10 @@ taxeditor-navigation/plugin.xml -text
 taxeditor-navigation/pom.xml -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/RecentNamesContributionItem.java -text
+taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/StateManager.java -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/WorkbenchUndoContextAdapterFactory.java -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/DeleteTreeNodeHandler.java -text
-taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java -text
+taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditHandler.java -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/MoveTaxonHandler.java -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/NewTaxonNodeHandler.java -text
 taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/NewTaxonomicTreeHandler.java -text
index 78a0228df7f34cd8f8c1157a2799a6063be7bd09..abda6063672d65a369889d745c0a0eccf1e0f302 100644 (file)
@@ -2,8 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: EDIT Taxonomic Editor - Navigation Bundle
 Bundle-SymbolicName: eu.etaxonomy.taxeditor.navigation;singleton:=true
-Bundle-Version: 2.1.1.qualifier
-Bundle-Activator: eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin
+Bundle-Version: 2.1.0.qualifier
 Bundle-Vendor: EDIT
 Export-Package: eu.etaxonomy.cdm,eu.etaxonomy.taxeditor.navigation,eu.etaxonomy.taxeditor.navigation.handler,eu.etaxonomy.taxeditor.navigation.internal,eu.etaxonomy.taxeditor.navigation.navigator,eu.etaxonomy.taxeditor.navigation.search,eu.etaxonomy.taxeditor.newWizards
 Require-Bundle: org.eclipse.ui;bundle-version="3.4.1",
@@ -19,3 +18,4 @@ Import-Package: org.eclipse.core.resources,
  org.eclipse.core.runtime.jobs,
  org.eclipse.equinox.app,
  org.osgi.framework
+Bundle-Activator: eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin
index 519e20ae9aaac8a3c55f7769ef561ad819eec2b7..4e5df629d24372a8b32ea9797a5aab5484b5f9ee 100644 (file)
@@ -25,7 +25,7 @@
             class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator"
             icon="icons/edit_16x16.gif"
             id="eu.etaxonomy.taxeditor.navigation.navigator"
-            name="Taxonomic Tree"
+            name="Taxon Navigator"
             restorable="true">
       </view>
    </extension>
@@ -46,7 +46,7 @@
             locationURI="menu:eu.etaxonomy.taxeditor.menu.showView">
          <command
                commandId="eu.etaxonomy.taxeditor.navigation.command.showTaxonomicTreeView"
-               label="Taxonomic Tree"
+               label="Taxon Navigator"
                style="push">
          </command>
       </menuContribution>
@@ -75,7 +75,7 @@
             <command
                   commandId="eu.etaxonomy.taxeditor.navigation.newTaxonomicTree"
                   id="eu.etaxonomy.taxeditor.navigation.menu.nu.new.taxonomicTree"
-                  label="Taxonomic Tree"
+                  label="Classification"
                   style="push">
             </command>
          </menu>
                visible="true">
          </separator>
          <command
-               commandId="eu.etaxonomy.taxeditor.navigation.command.editTaxon"
+               commandId="eu.etaxonomy.taxeditor.navigation.command.editSelection"
                label="Edit"
                style="push">       
-            <separator
-                  name="taxeditor-navigation.separator4">
-            </separator>    
             <visibleWhen>
                <reference
                      definitionId="isTaxonNode">
          <command
                commandId="eu.etaxonomy.taxeditor.navigation.newTaxonomicTree"
                id="eu.etaxonomy.taxeditor.navigation.menu.nu.new.taxonomicTree"
-               label="Taxonomic Tree"
+               label="Classification"
                style="push">
          </command>
       </menuContribution>
       <command
             defaultHandler="eu.etaxonomy.taxeditor.navigation.handler.NewTaxonomicTreeHandler"
             id="eu.etaxonomy.taxeditor.navigation.newTaxonomicTree"
-            name="New Taxonomic Tree">
+            name="New Classification">
       </command>
    </extension>
    <extension
          point="org.eclipse.ui.commands">
       <command
-            defaultHandler="eu.etaxonomy.taxeditor.navigation.handler.EditTaxonHandler"
-            id="eu.etaxonomy.taxeditor.navigation.command.editTaxon"
-            name="Edit Taxon">
+            defaultHandler="eu.etaxonomy.taxeditor.navigation.handler.EditHandler"
+            id="eu.etaxonomy.taxeditor.navigation.command.editSelection"
+            name="Edit">
       </command>
       <command
             defaultHandler="eu.etaxonomy.taxeditor.navigation.handler.MoveTaxonHandler"
       </command>
    </extension>
 
-      <extension
-         point="org.eclipse.ui.themes">
-      <themeElementCategory
-            id="eu.etaxonomy.taxeditor.preferences.searchResult"
-            label="Search Result">
-         <description>
-            Colors and fonts used to display the search result.
-         </description>
-      </themeElementCategory>
-      <fontDefinition
-            categoryId="eu.etaxonomy.taxeditor.preferences.searchResult"
-            id="eu.etaxonomy.taxeditor.preferences.searchResult.fontSynonym"
-            isEditable="true"
-            label="Synonym font">
-         <fontValue
-               value="Lucida Sans-italic-11">
-         </fontValue>
-         <description>
-            The font that is used for synonyms in the search result list.
-         </description>
-      </fontDefinition>
-      <fontDefinition
-            categoryId="eu.etaxonomy.taxeditor.preferences.searchResult"
-            id="eu.etaxonomy.taxeditor.preferences.searchResult.fontAccepted"
-            isEditable="true"
-            label="Accepted font">
-         <description>
-            The font that is used for accepted taxa in the search result list.
-         </description>
-         <fontValue
-               value="Lucida Sans-bold-11">
-         </fontValue>
-      </fontDefinition>
-      <fontDefinition
-            categoryId="eu.etaxonomy.taxeditor.preferences.searchResult"
-            id="eu.etaxonomy.taxeditor.preferences.searchResult.fontDefault"
-            isEditable="true"
-            label="Other font">
-         <description>
-            The font used by default in the search result list.
-         </description>
-         <fontValue
-               value="Lucida Grande-11">
-         </fontValue>
-      </fontDefinition>
-   </extension>
+      
       <!--extension
             point="org.eclipse.ui.navigator.viewer">
          <viewer
                   value="eu.etaxonomy.cdm.model.taxon.TaxonNode">
             </instanceof>
          </possibleChildren>
-         <actionProvider
-               class="eu.etaxonomy.taxeditor.navigation.navigator.OpenTaxonActionProvider"
-               id="eu.etaxonomy.taxeditor.navigation.action.open"
-               overrides="org.eclipse.ui.navigator.resources.OpenActions">
-            <enablement>
-               <instanceof
-                     value="eu.etaxonomy.cdm.model.taxon.TaxonNode">
-               </instanceof>
-            </enablement>
-         </actionProvider>
       </navigatorContent>
       <navigatorContent
+            activeByDefault="false"
             contentProvider="eu.etaxonomy.taxeditor.navigation.navigator.SynonymContentProvider"
             id="eu.etaxonomy.taxeditor.navigation.synonymcontent"
             labelProvider="eu.etaxonomy.taxeditor.navigation.navigator.SynonymLabelProvider"
       </primaryWizard-->
       <wizard
             category="eu.etaxonomy.taxeditor.new.category.cdm"
-            class="eu.etaxonomy.taxeditor.newWizards.NewTaxonomicTreeWizard"
+            class="eu.etaxonomy.taxeditor.newWizards.NewClassificationWizard"
             hasPages="true"
             icon="icons/tree_icon_small.jpg"
-            id="eu.etaxonomy.taxeditor.new.taxonomicTree"
-            name="Taxonomic Tree">
+            id="eu.etaxonomy.taxeditor.new.classification"
+            name="Classification">
       </wizard>
       <wizard
             category="eu.etaxonomy.taxeditor.new.category.cdm"
index 37c1748820e32e09c20b591f98e90b31725269a8..c0634673b1f035381ea474cb0479cec997c4c45a 100644 (file)
@@ -9,27 +9,29 @@
 
 package eu.etaxonomy.taxeditor.navigation;
 
-import java.util.HashSet;
 import java.util.Set;
 import java.util.UUID;
 
 import org.apache.log4j.Logger;
-import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.NotEnabledException;
+import org.eclipse.core.commands.NotHandledException;
+import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.commands.operations.UndoContext;
-import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.navigator.CommonViewer;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
@@ -37,6 +39,7 @@ import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.section.BulkEditorOpeningSelectionListener;
 
 /**
  * @author n.hoffmann
@@ -56,10 +59,46 @@ public class NavigationUtil extends AbstractUtility{
         * 
         * @param uuid
         */
-       public static void openEditor(TaxonNode selection) {
+//     public static void openEditor(TaxonNode selection) {
+//             try {
+//                     UUID entityUuid = selection.getUuid();                  
+//                     EditorUtil.openTaxonNode(entityUuid);
+//             } catch (PartInitException e) {
+//                     logger.error("Error opening the editor", e);
+//             }
+//     }
+       
+       public static void executeEditHandler(){
+
+               String commandId = "eu.etaxonomy.taxeditor.navigation.command.editSelection";
+               
+               IHandlerService handlerService = (IHandlerService) NavigationUtil.getService(IHandlerService.class); 
                try {
-                       UUID entityUuid = selection.getUuid();                  
-                       EditorUtil.open(entityUuid);
+                       handlerService.executeCommand(commandId, null);
+               } catch (ExecutionException e) {
+                       logger.error("ExecutionException when trying to execute EditHandler.", e);
+               } catch (NotDefinedException e) {
+                       logger.error("NotDefinedException when trying to execute EditHandler.", e);
+               } catch (NotEnabledException e) {
+                       logger.error("NotEnabledException when trying to execute EditHandler.", e);
+               } catch (NotHandledException e) {
+                       logger.error("NotHandledException when trying to execute EditHandler.", e);
+               }
+       }
+       
+       public static void openEditor(CdmBase selectedObject){
+               UUID entityUuid = selectedObject.getUuid();     
+               try {   
+                       if(selectedObject instanceof TaxonNode){
+                               EditorUtil.openTaxonNode(entityUuid);
+                       }else if(selectedObject instanceof TaxonBase){
+                               EditorUtil.openTaxonBase(entityUuid);
+                       }else if(selectedObject instanceof TaxonNameBase){
+                               // TODO open bulk editor
+                               warningDialog("Not implemented yet", "You tried to open a name. This is not hanlded by the software yet.");
+                       }else{
+                               warningDialog("Unsupported Type", "No editor exists for the current selection: " + selectedObject);
+                       }
                } catch (PartInitException e) {
                        logger.error("Error opening the editor", e);
                }
@@ -132,7 +171,7 @@ public class NavigationUtil extends AbstractUtility{
         * @param parentElement
         */
        public static void selectInNavigator(Object element, Object parentElement) {
-               TaxonNavigator navigator = getNavigator();
+               TaxonNavigator navigator = showNavigator();
                if (navigator != null) {
                        CommonViewer viewer = navigator.getCommonViewer();
                        if (viewer != null) {
@@ -156,19 +195,28 @@ public class NavigationUtil extends AbstractUtility{
                }else if(selection instanceof Synonym){
                        Synonym synonym = (Synonym) selection;
                        
-                       Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
-                       for (Taxon taxon : synonym.getAcceptedTaxa()){
-                               taxonNodes.addAll(taxon.getTaxonNodes());
-                       }
-                       handleOpeningOfMultipleTaxonNodes(taxonNodes);
+                       handleOpeningOfMultipleTaxa(synonym.getAcceptedTaxa());
                        
                }else{
-                       warningDialog("Not implemented yet", "You chose to open a name that has no connection to a taxa. The Editor does not support editing of such a content type at the moment.");
+                       warningDialog("Not implemented yet", "You chose to open a name that has no connection to a taxon. The Editor does not support editing of such a content type at the moment.");
                        logger.warn("Could not open editor for selection. Selection was of type: " + selection.getClass().getSimpleName());
                }
                
        }
 
+       private static void handleOpeningOfMultipleTaxa(Set<Taxon> acceptedTaxa) {
+               if(acceptedTaxa.size() == 1){
+                       openEditor(acceptedTaxa.iterator().next());
+               }else if(acceptedTaxa.size() > 1){
+                       // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
+                       warningDialog("Not implemented yet", "The accepted taxon is in multiple taxonomic trees. We currently do not know which one you want to open." +
+                                       " This case is not handled yet by the software.");
+               }else if(acceptedTaxa.size() == 0){
+                       // this is an undesired state
+                       warningDialog("Incorrect state", "The accepted taxon is not in a taxonomic view. This should not have happened.");
+               }
+       }
+
        /**
         * @param taxonNodes
         */
@@ -190,12 +238,11 @@ public class NavigationUtil extends AbstractUtility{
        /**
         * @return the TaxonNavigator instance if present
         */
-       public static TaxonNavigator getNavigator() {
-               try {
-                       return (TaxonNavigator) getView(TaxonNavigator.ID);
-               } catch (PartInitException e) {
-                       logger.error("Could not get the view.", e);
-                       throw new RuntimeException(e);
-               }
+       public static TaxonNavigator showNavigator() {
+               return (TaxonNavigator) showView(TaxonNavigator.ID);
+       }
+
+       public static TaxonNavigator getNavigator(boolean restore) {
+               return (TaxonNavigator) getView(TaxonNavigator.ID, restore);
        }
 }
\ No newline at end of file
diff --git a/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/StateManager.java b/taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/StateManager.java
new file mode 100644 (file)
index 0000000..3fd66d1
--- /dev/null
@@ -0,0 +1,252 @@
+
+package eu.etaxonomy.taxeditor.navigation;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistable;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchListener;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.XMLMemento;
+
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInputFactory;
+import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
+import eu.etaxonomy.taxeditor.model.IContextListener;
+import eu.etaxonomy.taxeditor.model.MementoHelper;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * 
+ * @author n.hoffmann
+ * @created Apr 1, 2010
+ * @version 1.0
+ */
+public class StateManager implements IContextListener {
+       private static final Logger logger = Logger.getLogger(StateManager.class);
+       
+       private static final String EDITORS = "editors";
+
+       private static final String EDITOR = "editor";
+       
+       private TaxonEditorInputFactory inputFactory;
+
+       private IMemento memento;
+
+
+       public StateManager(){
+               inputFactory = new TaxonEditorInputFactory();
+               PlatformUI.getWorkbench().addWorkbenchListener(new IWorkbenchListener() {
+
+                       @Override
+                       public void postShutdown(IWorkbench workbench) {}
+
+                       @Override
+                       public boolean preShutdown(IWorkbench workbench, boolean forced) {
+                               if(contextAboutToStop()){
+                                       contextStop();
+                               }
+                               // return true in any case, otherwise the application will not stop
+                               return true;
+                       }
+               });
+       }
+       
+       /*
+        * (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.model.IContextListener#onContextEvent(eu.etaxonomy.taxeditor.model.IContextListener.EventType)
+        */
+       public boolean onContextEvent(EventType eventType) {
+               switch(eventType){
+               case START:
+                       return contextStart();
+               case STOP:
+                       return contextStop();
+               case ABOUT_TO_STOP:
+                       return contextAboutToStop();
+               }
+               return false;
+       }
+       
+       /**
+        * Tries to restore the state of the taxon editor and the navigator when a context starts.
+        * 
+        * @return true in any case
+        */
+       private boolean contextStart() {
+               IMemento memento = null;
+               try {
+                       memento = MementoHelper.readMementoFromFile(getStateFileForCurrentDatabase());
+               } catch (FileNotFoundException e) {
+                       // no memento -> no previous state
+               }
+               
+               
+
+               restoreNavigator(memento);
+               
+               restoreEditors(memento); 
+               
+               
+               return true;
+       }
+       
+       /**
+        * Reads taxon node UUIDs from the given memento and tries to open an editor 
+        * for each of the found UUIDs.
+        * 
+        * @param memento
+        */
+       private void restoreEditors(final IMemento memento){
+               if(memento == null){
+                       return;
+               }
+               
+               ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(NavigationUtil.getShell());
+               IRunnableWithProgress runnable = new IRunnableWithProgress() {
+                       
+                       @Override
+                       public void run(IProgressMonitor monitor) throws InvocationTargetException,
+                                       InterruptedException {
+                               IMemento editorMementos = memento.getChild(EDITORS);
+                               IMemento[] editorInputs = editorMementos.getChildren(EDITOR);
+                               
+                               monitor.beginTask("Restoring Editors", 1 + editorInputs.length * 2);
+                               monitor.worked(1);
+                               
+                               for(IMemento editorInput : editorInputs){
+                                       TaxonEditorInput input = (TaxonEditorInput) inputFactory.createElement(editorInput);
+                                       monitor.worked(1);
+                                       if(!monitor.isCanceled() && input != null){
+                                               try {
+                                                       EditorUtil.open(input);
+                                               } catch (PartInitException e) {
+                                                       logger.error("Error opening an editor window", e);
+                                               }
+                                       }
+                                       monitor.worked(1);
+                               }
+                               monitor.done();
+                       }
+               };
+               
+               try {
+                       progressMonitorDialog.run(false, true, runnable);
+               } catch (InvocationTargetException e) {
+                       logger.error("InvocationTargetException when trying to restore open editors", e);
+               } catch (InterruptedException e) {
+                       logger.error("InterruptedException when trying to restore open editors", e);
+               }
+       }
+       
+       /**
+        * Restores the state of the navigator. Will open all previously opened paths.
+        * 
+        * @param memento
+        */
+       private void restoreNavigator(IMemento memento){
+               TaxonNavigator navigator = NavigationUtil.getNavigator(true);
+               navigator.restore(memento);
+       }
+       
+       /**
+        * Saves editor state to memento when the the context is about to shut down.
+        * The memento gets created anew on every shutdown process as to get rid of
+        * stale data from previous sessions on this context.
+        * 
+        * After this point the user may still cancel the process.
+        * 
+        * @return
+        */
+       private boolean contextAboutToStop() {
+               // we are creating the memento here; even if the context is not stopped
+               if (CdmStore.getDataSource() != null) {
+                       
+                       try {
+                               memento = XMLMemento.createWriteRoot(CdmStore.getDataSource().getName());
+                       
+                               saveEditorState(memento);
+                               logger.warn("DataSource found. Memento created.");
+                       } catch (Exception e) {
+                               // The memento could not be created, but a not closable editor is avoided for this case.
+                               logger.error("The memento could not be created: " + e.getMessage());
+                               return false;
+                       }
+               } else {
+                       logger.error("No DataSource present.");
+                       return false;
+               }
+               
+               return true;
+       }
+       
+       /**
+        * If the context 
+        * 
+        * @return
+        */
+       private boolean contextStop() {
+               saveNavigatorState(memento);
+               
+               // save the memento when the context really stops
+               return MementoHelper.saveMementoToFile(memento, getStateFileForCurrentDatabase()) != null;
+       }
+       
+       /**
+        * Saves the UUIDs 
+        * 
+        * @param memento
+        */
+       private void saveEditorState(IMemento memento){
+               Set<IEditorPart> editors = EditorUtil.getOpenEditors();
+               
+               IMemento editorMementos = memento.createChild(EDITORS);
+               
+               for(IEditorPart editor : editors){
+                       IEditorInput input = editor.getEditorInput();
+                       if(input instanceof IPersistable){
+                               IMemento editorMemento = editorMementos.createChild(EDITOR);
+                               ((IPersistable) input).saveState(editorMemento);
+                       }
+               }
+       }
+       
+       /**
+        * 
+        * @param memento
+        */
+       private void saveNavigatorState(IMemento memento){
+               TaxonNavigator navigator = NavigationUtil.getNavigator(false);
+               if(navigator != null){
+                       navigator.save(memento);
+               }
+       }
+
+       /**
+        * 
+        * @return
+        */
+       private File getStateFileForCurrentDatabase() {
+               IPath path = TaxeditorEditorPlugin.getDefault().getStateLocation();
+               if (path == null) {
+                       return null;
+               }
+               path = path.append("editor_state_" + CdmStore.getDataSource().getName() + ".xml");
+               return path.toFile();
+       }
+
+}
index 7d00ff5439c6d688d266209c1a723fa0bf15dc36..2da2c6cd94c53a80f9d561dc268cda81d541226b 100644 (file)
@@ -51,17 +51,18 @@ public class DeleteTreeNodeHandler extends AbstractHandler implements IHandler{
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
                
-               // Prompt user for confirmation
-               if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected taxa?")){
-                       return null;
-               }
-               
                activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
                
-               taxonNavigator = NavigationUtil.getNavigator();
+               taxonNavigator = NavigationUtil.showNavigator();
                                
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
                
+               String plural = selection.size() > 1 ? "s" : "";
+               // Prompt user for confirmation
+               if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected node" + plural +"?")){
+                       return null;
+               }
+               
                Iterator selectionIterator = selection.iterator();
                Set<ITreeNode> treeNodes = new HashSet<ITreeNode>();
                
@@ -108,4 +109,4 @@ public class DeleteTreeNodeHandler extends AbstractHandler implements IHandler{
                        }
                }
        }
-}
+}
\ No newline at end of file
similarity index 53%
rename from taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditTaxonHandler.java
rename to taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/handler/EditHandler.java
index f5b3742e412aaf2182e5166f85f31430f4b1f57e..96d248bcf094a1ac50c84f8ee7fc607b8175c0e0 100644 (file)
@@ -1,3 +1,5 @@
+package eu.etaxonomy.taxeditor.navigation.handler;
+// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy 
@@ -7,38 +9,46 @@
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 
-package eu.etaxonomy.taxeditor.navigation.handler;
 
+import org.apache.log4j.Logger;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.handlers.HandlerUtil;
 
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 
 /**
  * @author n.hoffmann
- * @created 24.03.2009
+ * @created May 12, 2010
  * @version 1.0
  */
-public class EditTaxonHandler extends AbstractHandler {
+public class EditHandler extends AbstractHandler implements IHandler{
+       private static final Logger logger = Logger
+                       .getLogger(EditHandler.class);
 
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
+       @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
+       
+               ISelection selection = HandlerUtil.getCurrentSelection(event);//navigator.getSelection();
                
-               ISelection selection = HandlerUtil.getActiveMenuSelection(event);
-               
-               Object selectedObject = ((StructuredSelection) selection).getFirstElement();
-               
-               if(selectedObject instanceof TaxonNode){
-                       NavigationUtil.openEditor((TaxonNode) selectedObject);
-               }else{
-                       throw new IllegalArgumentException("selectedObject is not of type TaxonNode");
+               if(selection instanceof StructuredSelection){
+                       for(Object selectedObject : ((StructuredSelection) selection).toArray()){
+                               
+                               if(selectedObject instanceof CdmBase){
+                                       // let the openEditor() method handle everything from now on
+                                       NavigationUtil.openEditor((CdmBase) selectedObject);
+                               }else{
+                                       throw new IllegalArgumentException("selectedObject is not of type CdmBase");
+                               }
+                       }
                }
                
                return null;
index 8647332fd0bf8f1a1a8b8195684434b72bfc5bdb..1ff407e31f602f9d5bd5f079fb3030423c1fa5b0 100644 (file)
@@ -48,7 +48,7 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               TaxonNavigator taxonNavigator = NavigationUtil.getNavigator();
+               TaxonNavigator taxonNavigator = NavigationUtil.showNavigator();
                
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
                
@@ -94,4 +94,4 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE
        public boolean postOperation(CdmBase objectAffectedByOperation) {
                return true;
        }
-}
+}
\ No newline at end of file
index c5d8ceedc26e76353d266266f3e5bfb0a7c14b83..779bc0111bad8b9925fbdefa7dcde0cc51ff5217 100644 (file)
@@ -16,7 +16,6 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.IHandler;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.ui.handlers.HandlerUtil;
 
@@ -36,10 +35,8 @@ public class NewTaxonNodeHandler extends AbstractHandler implements IHandler {
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               
-               StructuredSelection selection = (StructuredSelection) HandlerUtil.getActiveMenuSelection(event);
                                
-               NewTaxonNodeWizard wizard = new NewTaxonNodeWizard(selection);
+               NewTaxonNodeWizard wizard = new NewTaxonNodeWizard();
                WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
                int status = dialog.open();
                
index 65e059aa54dedcd280085ed68246018891be9b2b..dd3a5a0668b77e6beec7762aba3c732b5f043d47 100644 (file)
@@ -18,7 +18,7 @@ import org.eclipse.core.commands.IHandler;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.ui.handlers.HandlerUtil;
 
-import eu.etaxonomy.taxeditor.newWizards.NewTaxonomicTreeWizard;
+import eu.etaxonomy.taxeditor.newWizards.NewClassificationWizard;
 
 /**
  * @author n.hoffmann
@@ -35,7 +35,7 @@ public class NewTaxonomicTreeHandler extends AbstractHandler implements
         */
        public Object execute(ExecutionEvent event) throws ExecutionException {
                
-               WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), new NewTaxonomicTreeWizard());
+               WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), new NewClassificationWizard());
                dialog.open();
                
                return null;
index 609483fbb8ce54ee9598c2c117e3668b6f5c127a..830c7e50f02cd5087d9dab9fdc483302a8dfd653 100644 (file)
@@ -2,9 +2,6 @@ package eu.etaxonomy.taxeditor.navigation;
 
 import java.net.URL;
 
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.application.IWorkbenchConfigurer;
 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
@@ -49,9 +46,9 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
                configurer_p.declareImage(symbolicName, desc, shared);
        }
 
-       public IAdaptable getDefaultPageInput() {
-               IWorkspace workspace = ResourcesPlugin.getWorkspace();
-               return workspace.getRoot();
-       }
+//     public IAdaptable getDefaultPageInput() {
+//             IWorkspace workspace = ResourcesPlugin.getWorkspace();
+//             return workspace.getRoot();
+//     }
 
 }