refactoring actions in the treeviewer
authorn.hoffmann <n.hoffmann@localhost>
Mon, 19 Jan 2009 10:50:15 +0000 (10:50 +0000)
committern.hoffmann <n.hoffmann@localhost>
Mon, 19 Jan 2009 10:50:15 +0000 (10:50 +0000)
.gitattributes
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/DeleteTaxonAction.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenNewChildNameEditorAction.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java [new file with mode: 0644]
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java [new file with mode: 0644]

index 0645dbc4db594b3e884b1c468933d8eeb2483ee6..98c98bdd84dd3ec35f3d4a468743cc99f0a80d4f 100644 (file)
@@ -513,6 +513,8 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/Tax
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/AbstractEditorOperation.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeHomotypicGroupOperation.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeMisappliedNameToSynonymOperation.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/name/ChangeSynonymToMisappliedNameOperation.java -text
index 7025581041030c421a18c52ca002c5880ec4cf88..993e531d20d721e3462ef9d5b83ec56e75a32dd3 100644 (file)
@@ -42,11 +42,16 @@ import org.eclipse.ui.views.properties.PropertySheetPage;
 import eu.etaxonomy.cdm.model.description.Feature;\r
 import eu.etaxonomy.cdm.model.name.NameRelationshipType;\r
 import eu.etaxonomy.cdm.model.name.Rank;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction;\r
+import eu.etaxonomy.taxeditor.datasource.CdmTransactionController;\r
 import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;\r
+import eu.etaxonomy.taxeditor.editor.name.CdmParserController;\r
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;\r
 import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
 import eu.etaxonomy.taxeditor.model.NameEditorInput;\r
+import eu.etaxonomy.taxeditor.navigation.RecentNamesView;\r
 import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView;\r
 import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer;\r
 import eu.etaxonomy.taxeditor.propertysheet.CustomSortPropertySheetEntry;\r
@@ -103,6 +108,45 @@ public class UiUtil {
 //             ps.addPropertyListener(l)\r
        }\r
        \r
+       public static void saveAll(){\r
+               setIsSaving(true);\r
+               \r
+               // Get all open windows\r
+               for (IEditorPart taxonEditor : getOpenTaxonEditors()) {\r
+\r
+                       // Save the dirty ones\r
+                       if (taxonEditor.isDirty()) {\r
+                               \r
+                               \r
+                               IEditorInput input = taxonEditor.getEditorInput();\r
+                               if (input.getAdapter(Taxon.class) != null) {\r
+                                       Taxon taxon = (Taxon) input.getAdapter(Taxon.class);\r
+                                       CdmSessionDataRepository.getDefault().saveTaxon(taxon);\r
+                                       if (taxonEditor instanceof MultiPageTaxonEditor) {\r
+                                               ((MultiPageTaxonEditor) taxonEditor).setDirtyExtern(false);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // Commit the transaction       \r
+               CdmTransactionController.commitTransaction();\r
+       \r
+               // Force library objects to be associated with new transaction\r
+               CdmSessionDataRepository.getDefault().clearNonTaxonData();\r
+               \r
+               // Start a new transaction\r
+               CdmTransactionController.startTransaction();\r
+               \r
+               // Put all open taxa in the new transaction\r
+               CdmTransactionController.addSessionTaxaToTransaction();\r
+               \r
+               setIsSaving(false);\r
+               // TODO: delete undoHistory\r
+       }\r
+       \r
+       //public void deleteTaxon()\r
+       \r
        /**\r
         * @param input\r
         * @return\r
@@ -180,8 +224,43 @@ public class UiUtil {
                return getActivePage().openEditor(input, editorId);\r
        }\r
        \r
+       /**\r
+        * Open an emtpy taxon editor\r
+        * \r
+        * @return\r
+        * @throws PartInitException\r
+        */\r
+       public static IEditorPart openTaxonEditor() \r
+                       throws PartInitException{\r
+               return openTaxonEditor(null);\r
+       }\r
+       \r
+       /** \r
+        * Open a taxon editor for the given taxon\r
+        * \r
+        * @param taxon\r
+        * @return\r
+        * @throws PartInitException\r
+        */\r
        public static IEditorPart openTaxonEditor(Taxon taxon)\r
                        throws PartInitException{\r
+               if(taxon == null){\r
+                       TaxonNameBase name = CdmParserController.parseFullReference("", null, null);\r
+                       name.setFullTitleCache("", false);\r
+                       name.setTitleCache("", false);\r
+                       taxon = Taxon.NewInstance(name, \r
+                                       CdmSessionDataRepository.getDefault().getDefaultSec());\r
+               }else{\r
+                       // If this taxon is not visible in the tree, open node\r
+                       TaxonomicTreeViewer treeViewer = getTreeViewer(); \r
+                       if (treeViewer != null) {\r
+                               treeViewer.revealTaxon(taxon);\r
+                       }\r
+                       \r
+                       // Add to recent names list\r
+                       RecentNamesView.addRecentName(taxon);\r
+               }\r
+               \r
                IEditorInput input = new NameEditorInput(taxon);\r
                return openEditor(input, MultiPageTaxonEditor.ID);\r
        }\r
@@ -285,7 +364,9 @@ public class UiUtil {
        }\r
 \r
        public static IUndoContext getWorkbenchUndoContext() {\r
-               return getOperationSupport().getUndoContext();\r
+               // TODO make this more specific than GLOBAL_UNDO_CONTEXT\r
+//             return getOperationSupport().getUndoContext();\r
+               return IOperationHistory.GLOBAL_UNDO_CONTEXT;\r
        }\r
 \r
        public static void doEditorSave(Taxon taxon, boolean confirm) {\r
index 3b8a251effe76c42bfbc8a33d200880448ce00a2..fabf90a7d1b286a7d03a41ba4e160f5f66df741d 100644 (file)
@@ -15,19 +15,20 @@ package eu.etaxonomy.taxeditor.actions.cdm;
  * @version 1.0\r
  */\r
 import org.apache.log4j.Logger;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.IOperationHistory;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.commands.operations.IUndoableOperation;\r
 import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.ui.PartInitException;\r
 \r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
 import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
 import eu.etaxonomy.taxeditor.UiUtil;\r
-import eu.etaxonomy.taxeditor.actions.SaveAllAction;\r
-import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
-import eu.etaxonomy.taxeditor.model.CdmUtil;\r
+import eu.etaxonomy.taxeditor.operations.DeleteTaxonOperation;\r
 \r
 /**\r
  * Delete this taxon from the CDM\r
@@ -43,11 +44,17 @@ public class DeleteTaxonAction extends Action {
        private ImageDescriptor image = TaxEditorPlugin.getDefault()\r
                        .getImageDescriptor(ITaxEditorConstants.ACTIVE_DELETE_ICON);\r
 \r
+       private IOperationHistory operationHistory;\r
+       private IUndoContext undoContext;\r
+       \r
        Taxon taxon;\r
 \r
        public DeleteTaxonAction() {\r
                super(text);\r
                setImageDescriptor(image);\r
+               \r
+               operationHistory = UiUtil.getOperationHistory();\r
+               undoContext = UiUtil.getWorkbenchUndoContext();\r
        }\r
 \r
        public DeleteTaxonAction(Taxon taxon) {\r
@@ -57,53 +64,69 @@ public class DeleteTaxonAction extends Action {
        }\r
 \r
        public void run() {\r
-               \r
-               // Get taxon name for progress monitor\r
-               String taxonName = CdmUtil.getDisplayName(taxon);\r
-               \r
-               // Get and start progress monitor\r
+               IUndoableOperation operation = new DeleteTaxonOperation\r
+                               (this.getText(), undoContext, taxon);\r
+\r
                IProgressMonitor monitor = UiUtil.getStatusLineProgressMonitor();\r
-               monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10);\r
                \r
-               // Call save all action\r
-               new SaveAllAction().run(null);\r
-               monitor.worked(2);\r
-               \r
-               // If the taxon has children, cancel operation\r
-               // TODO add option to continue, and delete children\r
-               if (taxon.hasTaxonomicChildren()) {\r
-                       MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", \r
-                                       "'" + CdmUtil.getDisplayName(taxon) + "' has taxonomic children. " +\r
-                                       "These must be manually deleted before their parent.");\r
-                       monitor.done();\r
-                       return;\r
-               }\r
-               monitor.worked(1);\r
-               \r
-               // Close taxon's editor, if any is active\r
                try {\r
-                       UiUtil.closeEditor(taxon, true);\r
-               } catch (PartInitException e) {\r
-                       e.printStackTrace();\r
-               }\r
-               monitor.worked(1);\r
-\r
-               // Delete taxon from CDM layer\r
-               CdmSessionDataRepository.getDefault().deleteTaxon(taxon);\r
-               monitor.worked(4);\r
-                               \r
-               // Call save all action\r
-               new SaveAllAction().run(null);\r
-               monitor.worked(2);\r
-               \r
-               // Close the progress monitor\r
-               monitor.done();\r
+                       IStatus status = operationHistory.execute(operation, monitor, null);\r
+               } catch (ExecutionException e) {\r
+                       logger.error("Error deleting taxon", e);\r
+               }       \r
                \r
-               // Announce taxon was deleted on status line\r
-               UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'.");\r
+               // Handle this in an operation so we are able to undo it\r
                \r
-//             Status status = new Status(IStatus.INFO, TaxEditorPlugin.PLUGIN_ID, \r
-//                             "Deleted.", null);\r
-//             StatusManager.getManager().handle(status, StatusManager.SHOW);\r
+//             \r
+//             // Get taxon name for progress monitor\r
+//             String taxonName = CdmUtil.getDisplayName(taxon);\r
+//             \r
+//             // Get and start progress monitor\r
+//             IProgressMonitor monitor = UiUtil.getStatusLineProgressMonitor();\r
+//             monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10);\r
+//             \r
+//             // Call save all action\r
+//             new SaveAllAction().run(null);\r
+//             monitor.worked(2);\r
+//             \r
+//             // If the taxon has children, cancel operation\r
+//             // TODO add option to continue, and delete children\r
+//             if (taxon.hasTaxonomicChildren()) {\r
+//                     MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", \r
+//                                     "'" + CdmUtil.getDisplayName(taxon) + "' has taxonomic children. " +\r
+//                                     "These must be manually deleted before their parent.");\r
+//                     monitor.done();\r
+//                     return;\r
+//             }\r
+//             monitor.worked(1);\r
+//             \r
+//             \r
+//             // Close taxon's editor, if any is active\r
+//             try {\r
+//                     UiUtil.closeEditor(taxon, true);\r
+//             } catch (PartInitException e) {\r
+//                     e.printStackTrace();\r
+//             }\r
+//             monitor.worked(1);\r
+//\r
+//             // Delete taxon from CDM layer\r
+//             CdmSessionDataRepository.getDefault().deleteTaxon(taxon);\r
+//             monitor.worked(4);\r
+//                             \r
+//             \r
+//             \r
+//             // Call save all action\r
+//             new SaveAllAction().run(null);\r
+//             monitor.worked(2);\r
+//             \r
+//             // Close the progress monitor\r
+//             monitor.done();\r
+//             \r
+//             // Announce taxon was deleted on status line\r
+//             UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'.");\r
+//             \r
+////           Status status = new Status(IStatus.INFO, TaxEditorPlugin.PLUGIN_ID, \r
+////                           "Deleted.", null);\r
+////           StatusManager.getManager().handle(status, StatusManager.SHOW);\r
        }\r
 }
\ No newline at end of file
index f27ec8ad6f9cb7d0964aabd4898d77cc3d16e413..55523882d52b08a48b041a8c5575cd42f499d16e 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.actions.ui;
 import org.apache.log4j.Logger;\r
 import org.eclipse.jface.action.Action;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.ui.PartInitException;\r
 \r
 import eu.etaxonomy.cdm.model.name.BotanicalName;\r
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
@@ -21,6 +22,7 @@ import eu.etaxonomy.cdm.model.reference.ReferenceBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
 import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
+import eu.etaxonomy.taxeditor.UiUtil;\r
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
 \r
 /**\r
@@ -62,6 +64,13 @@ public class OpenNewChildNameEditorAction extends Action {
                \r
                parentTaxon.addTaxonomicChild(taxon, null, null);\r
                \r
-               new OpenTaxonEditorAction(taxon).run();\r
+               // Open editor for new taxon\r
+               try {\r
+                       UiUtil.openTaxonEditor(taxon);\r
+               } catch (PartInitException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               //new OpenTaxonEditorAction(taxon).run();\r
        }\r
 }
\ No newline at end of file
index 445bae36b27ea9b17c4907faaa7f9e5330e522e2..d0d19433966a3bd4389f90b13385af034cbd1a6f 100644 (file)
@@ -64,39 +64,12 @@ public class OpenTaxonEditorAction extends Action implements IWorkbenchWindowAct
        public OpenTaxonEditorAction() {\r
                super(newTaxonText);\r
                setImageDescriptor(image);\r
-//             setActionDefinitionId(ID);\r
                setId(ID);\r
        }\r
        \r
        @Override\r
        public void run() {\r
                \r
-               // Initialize taxon\r
-               if (taxon == null) {\r
-                       \r
-                       // Passing the parser an empty string will return a new\r
-                       //  new name object with the name class specified in the\r
-                       //  preference store, i.e. BotanicalName\r
-                       TaxonNameBase name = CdmParserController.parseFullReference("", null, null);\r
-                       name.setFullTitleCache("", false);\r
-                       name.setTitleCache("", false);\r
-                       this.taxon = Taxon.NewInstance(name, \r
-                                       CdmSessionDataRepository.getDefault().getDefaultSec());\r
-               \r
-                       // Note: don't add taxon to repository - it's not yet valid\r
-\r
-               } else {\r
-                       \r
-                       // If this taxon is not visible in the tree, open node\r
-                       TaxonomicTreeViewer treeViewer = UiUtil.getTreeViewer(); \r
-                       if (treeViewer != null) {\r
-                               treeViewer.revealTaxon(taxon);\r
-                       }\r
-                       \r
-                       // Add to recent names list\r
-                       RecentNamesView.addRecentName(taxon);\r
-               }\r
-               \r
        try {\r
                        UiUtil.openTaxonEditor(taxon);\r
                } catch (PartInitException e) {\r
diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/DeleteTaxonOperation.java
new file mode 100644 (file)
index 0000000..e815ad1
--- /dev/null
@@ -0,0 +1,125 @@
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.taxeditor.operations;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.AbstractOperation;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.ui.PartInitException;\r
+\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.UiUtil;\r
+import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
+\r
+/**\r
+ * @author n.hoffmann\r
+ * @created 16.01.2009\r
+ * @version 1.0\r
+ */\r
+public class DeleteTaxonOperation extends AbstractEditorOperation {\r
+       private static Logger logger = Logger.getLogger(DeleteTaxonOperation.class);\r
+\r
+       private Taxon parentTaxon;\r
+       public DeleteTaxonOperation(String text, IUndoContext undoContext,\r
+                       Taxon taxon) {\r
+               super(text, undoContext, taxon);\r
+\r
+               parentTaxon = taxon.getTaxonomicParent();\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+        */\r
+       @Override\r
+       public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+\r
+               // TODO move this logic to another place\r
+               \r
+               // Get taxon name\r
+               String taxonName = taxon.getName().getTitleCache();\r
+               \r
+               // Prompt user for confirmation\r
+               if(! MessageDialog.openConfirm(UiUtil.getShell(), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName + "'?")){\r
+                       monitor.done();\r
+                       return Status.CANCEL_STATUS;\r
+               }\r
+               \r
+               // Get and start progress monitor\r
+               monitor.beginTask("Deleting taxon '" + taxonName + "'.", 10);\r
+               \r
+               // Call save all\r
+               UiUtil.saveAll();\r
+               monitor.worked(2);\r
+               \r
+               // If the taxon has children, cancel operation\r
+               // TODO add option to continue, and delete children\r
+               if (taxon.hasTaxonomicChildren()) {\r
+                       MessageDialog.openInformation(UiUtil.getShell(), "Cannot delete taxon", \r
+                                       "'" + taxonName + "' has taxonomic children. " +\r
+                                       "These must be manually deleted before their parent.");\r
+                       monitor.done();\r
+                       return Status.CANCEL_STATUS;\r
+               }\r
+               monitor.worked(1);\r
+               \r
+               \r
+               // Close taxon's editor, if any is active\r
+               try {\r
+                       UiUtil.closeEditor(taxon, true);\r
+               } catch (PartInitException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               monitor.worked(1);\r
+\r
+               // Delete taxon from CDM layer\r
+               CdmSessionDataRepository.getDefault().removeTaxon(taxon);\r
+               monitor.worked(4);\r
+                               \r
+               // Call save all\r
+               UiUtil.saveAll();\r
+               monitor.worked(2);\r
+               \r
+               // Close the progress monitor\r
+               monitor.done();\r
+               \r
+               // Announce taxon was deleted on status line\r
+               UiUtil.setStatusLine("Deleted taxon '" + taxonName + "'.");\r
+               \r
+               return Status.OK_STATUS;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+        */\r
+       @Override\r
+       public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               return execute(monitor, info);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+        */\r
+       @Override\r
+       public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               // FIXME we have to add old citation\r
+               parentTaxon.addTaxonomicChild(taxon, null, null);\r
+               CdmSessionDataRepository.getDefault().addTaxon(taxon);\r
+               return Status.OK_STATUS;\r
+       }\r
+}\r
diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java
new file mode 100644 (file)
index 0000000..9117a8a
--- /dev/null
@@ -0,0 +1,77 @@
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.taxeditor.operations;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
+\r
+/**\r
+ * @author n.hoffmann\r
+ * @created 16.01.2009\r
+ * @version 1.0\r
+ */\r
+public class MoveTaxonOperation extends AbstractEditorOperation {\r
+       \r
+\r
+       private static Logger logger = Logger.getLogger(MoveTaxonOperation.class);\r
+       private Taxon newParentTaxon;\r
+       private Taxon oldParentTaxon;\r
+\r
+       public MoveTaxonOperation(String label, IUndoContext undoContext,\r
+                       Taxon taxon, Taxon newParentTaxon) {\r
+               super(label, undoContext, taxon);\r
+\r
+               this.newParentTaxon = newParentTaxon;\r
+               \r
+               // Save old parent taxon for undo\r
+               this.oldParentTaxon = taxon.getTaxonomicParent();\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+        */\r
+       @Override\r
+       public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               CdmSessionDataRepository.getDefault().setTaxonomicParent(taxon, newParentTaxon);\r
+               CdmSessionDataRepository.getDefault().saveTaxon(taxon);\r
+               \r
+               return Status.OK_STATUS;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+        */\r
+       @Override\r
+       public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               return execute(monitor, info);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
+        */\r
+       @Override\r
+       public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
+                       throws ExecutionException {\r
+               CdmSessionDataRepository.getDefault().setTaxonomicParent(taxon, oldParentTaxon);\r
+               CdmSessionDataRepository.getDefault().saveTaxon(taxon);\r
+               \r
+               return Status.OK_STATUS;\r
+       }\r
+}\r