Partial fix of Ticket #4728
authorAlexander Oppermann <a.oppermann@bgbm.org>
Wed, 29 Apr 2015 15:17:22 +0000 (15:17 +0000)
committerAlexander Oppermann <a.oppermann@bgbm.org>
Wed, 29 Apr 2015 15:17:22 +0000 (15:17 +0000)
.gitattributes
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientClassificationService.java
eu.etaxonomy.taxeditor.navigation/plugin.xml
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CreateClassificationHierarchyHandler.java [moved from eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/FixClassificationHierarchyHandler.java with 56% similarity]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreateNewTaxonHierarchyOperation.java [new file with mode: 0644]

index be12c22..77114bc 100644 (file)
@@ -978,9 +978,9 @@ eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigatio
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/dnd/TaxonNavigatorDragAdapterAssistant.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/ChangeAcceptedTaxonToSynonymHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CopyHandler.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CreateClassificationHierarchyHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/EditHandler.java -text
-eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/FixClassificationHierarchyHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveFactualDataHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/NewClassificationHandler.java -text
@@ -993,6 +993,7 @@ eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigatio
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/EditClassificationOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreateClassification.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreateNewTaxonHierarchyOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreatePolytomousKey.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreateTaxonNode.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/Messages.java -text
index de0f1f7..61f361f 100644 (file)
@@ -22,6 +22,7 @@ import org.hibernate.envers.query.criteria.AuditCriterion;
 
 import eu.etaxonomy.cdm.api.service.DeleteResult;
 import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.api.service.config.CreateHierarchyForClassificationConfigurator;
 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
@@ -940,7 +941,7 @@ public class TransientClassificationService implements IClassificationService {
      * @see eu.etaxonomy.cdm.api.service.IClassificationService#createHierarchyInClassification(java.util.Map, eu.etaxonomy.cdm.model.taxon.Classification)
      */
     @Override
-    public Classification createHierarchyInClassification(Classification arg1, CreateHierarchyForClassificationConfigurator arg2) {
+    public UpdateResult createHierarchyInClassification(Classification arg1, CreateHierarchyForClassificationConfigurator arg2) {
        return defaultService.createHierarchyInClassification(arg1, arg2);
     }
 
index 39cbba9..2317fff 100644 (file)
             name="%command.name.moveFactualData">
       </command>
       <command
-            defaultHandler="eu.etaxonomy.taxeditor.navigation.navigator.handler.FixClassificationHierarchyHandler"
+            defaultHandler="eu.etaxonomy.taxeditor.navigation.navigator.handler.CreateClassificationHierarchyHandler"
             id="eu.etaxonomy.taxeditor.navigation.navigator.handler.OpenFixClassificationHierarchyHandler"
             name="%command.name.10">
       </command>
@@ -10,14 +10,17 @@ import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.navigation.operation.CreateNewTaxonHierarchyOperation;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 
-public class FixClassificationHierarchyHandler extends AbstractHandler {
+public class CreateClassificationHierarchyHandler extends AbstractHandler {
 
-    private static final Logger logger = Logger.getLogger(FixClassificationHierarchyHandler.class);
+    private static final Logger logger = Logger.getLogger(CreateClassificationHierarchyHandler.class);
 
     TaxonNavigator taxonNavigator = (TaxonNavigator)NavigationUtil.showView(TaxonNavigator.ID);
     /*
@@ -36,19 +39,30 @@ public class FixClassificationHierarchyHandler extends AbstractHandler {
 
                 Classification classification = (Classification) selectedElement;
                 try {
-                    IClassificationService service = CdmStore.getService(IClassificationService.class);
+//                    IClassificationService service = CdmStore.getService(IClassificationService.class);
 
                     // Map<String, List<TaxonNode>> sortedGenusList =
                     // service.getSortedGenusList(classification.getAllNodes());
 
-                    Classification newClassification = service.createHierarchyInClassification(classification, null);
 
-                    MessagingUtils.messageDialog("Fix Hierarchy successful",
-                            FixClassificationHierarchyHandler.class, "Operation 'Fix Hierarchy' was successful. New classification is " + newClassification.getTitleCache());
+                    CreateNewTaxonHierarchyOperation operation = new CreateNewTaxonHierarchyOperation("Create Taxon Hierarchy", StoreUtil.getUndoContext(),classification,NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false) );
+
+                    AbstractUtility.executeOperation(operation);
+//                    UpdateResult result = service.createHierarchyInClassification(classification, null);
+//
+//                    Classification classification2 = CdmBase.deproxy(result.getCdmEntity(), Classification.class);
+//
+//                    Set<CdmBase> updatedObjects = result.getUpdatedObjects();
+//
+//                    Shell activeShell = HandlerUtil.getActiveShell(event);
+
+//                    MessagingUtils.messageDialog("Add Hierarchy successful",
+//                            FixClassificationHierarchyHandler.class, "Operation 'Fix Hierarchy' was successful. New classification is "
+//                    + classification2.getTitleCache() + "\nUpdated Objects: " + updatedObjects.size());
                     //Success
                     taxonNavigator.refresh();
                 } catch (Exception e) {
-                    MessagingUtils.messageDialog("Failed to open Editor", FixClassificationHierarchyHandler.class,
+                    MessagingUtils.messageDialog("Failed to open Editor", CreateClassificationHierarchyHandler.class,
                             "Could not open ChecklistView. The hierarchy is corrupted!", e);
                 }
             }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreateNewTaxonHierarchyOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/operation/CreateNewTaxonHierarchyOperation.java
new file mode 100644 (file)
index 0000000..f9b77e0
--- /dev/null
@@ -0,0 +1,82 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.navigation.operation;
+
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author a.oppermann
+ * @date 28.04.2015
+ *
+ */
+public class CreateNewTaxonHierarchyOperation extends AbstractPersistentPostOperation {
+
+    private final Classification classification;
+
+    private final IClassificationService service;
+
+    /**
+     * @param label
+     * @param undoContext
+     */
+    public CreateNewTaxonHierarchyOperation(String label, IUndoContext undoContext, Classification classification,
+            IPostOperationEnabled postOperationEnabled,
+            IConversationEnabled conversationEnabled) {
+        super(label, undoContext, postOperationEnabled, conversationEnabled);
+
+        this.classification = classification;
+        this.service = CdmStore.getService(IClassificationService.class);
+
+    }
+
+    @Override
+    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+        monitor.worked(20);
+        UpdateResult result = service.createHierarchyInClassification(classification, null);
+        monitor.worked(60);
+        Set<CdmBase> updatedObjects = result.getUpdatedObjects();
+        Set<CdmBase> unchangedObjects = result.getUnchangedObjects();
+        Classification classification2 = CdmBase.deproxy(result.getCdmEntity(), Classification.class);
+
+        MessagingUtils.informationDialog("Add Hierarchy successful", "New classification is "
+      + classification2.getTitleCache() + "\nCreated Genus: " + updatedObjects.size()
+      +"\nCreated Subspecies: " + unchangedObjects.size());
+
+        return postExecute(result.getCdmEntity());
+    }
+
+    @Override
+    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        return null;
+    }
+
+    @Override
+    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+        return null;
+    }
+
+}