improve messaging for deleteResult
authorU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Tue, 6 Oct 2015 07:16:00 +0000 (09:16 +0200)
committerU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Tue, 6 Oct 2015 07:16:00 +0000 (09:16 +0200)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/DefaultNewEntityListener.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientDescriptionService.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionToOtherTaxonOperation.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DeleteResultMessagingUtils.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java

index 15ca691727c485428c2316c9648b0e3dac73e96a..49aaed016979134fb34b298ea768515b33ea906e 100644 (file)
@@ -10,6 +10,9 @@
 
 package eu.etaxonomy.taxeditor.bulkeditor.handler;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -44,6 +47,7 @@ import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
+import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -84,6 +88,7 @@ public class DeleteHandler extends AbstractHandler {
 
                                LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
                                DeleteResult result = new DeleteResult();
+                               String errorMessage= "The object ";
                                //result.setError();
                                try {
                                        ICdmApplicationConfiguration controller;
@@ -93,60 +98,64 @@ public class DeleteHandler extends AbstractHandler {
                                                IOccurrenceService service = controller.getOccurrenceService();
                                                if (object != null){
                                                        result = service.delete(((SpecimenOrObservationBase) object).getUuid());
+                                                       errorMessage = "The specimen or observation ";
                                                }
                                        } else if (object instanceof Reference){
                                                IReferenceService service = controller.getReferenceService();
                                                if (object != null){
                                                        result = service.delete(((Reference) object).getUuid());
+                                                       errorMessage = "The reference ";
                                                }
 
                                        } else if (object instanceof Group){
                                                IGroupService service = controller.getGroupService();
                                                if (object != null){
                                                        result = service.delete(((Group) object).getUuid());
+                                                       errorMessage = "The group ";
                                                }
                                        }else if (object instanceof User){
                                                IUserService service = controller.getUserService();
                                                if (object != null){
                                                        result = service.delete(((User) object).getUuid());
+                                                       errorMessage = "The user ";
                                                }
                                        } else if (object instanceof TaxonNameBase){
                                                INameService service = controller.getNameService();
                                                if (object != null){
                                                        NameDeletionConfigurator config = new NameDeletionConfigurator();
                                                        result = service.delete(((TaxonNameBase) object).getUuid(), config);
+                                                       errorMessage = "The name ";
                                                }
                                        } else if (object instanceof TaxonBase){
                                                ITaxonService service = controller.getTaxonService();
                                                if (object != null){
                                                        if (object instanceof Taxon){
                                                                result = service.deleteTaxon(((TaxonBase) object).getUuid(), null, null);
+                                                               errorMessage = "The taxon ";
                                                        }else{
                                                                result = service.deleteSynonym(((Synonym)object).getUuid(), null);
+                                                               errorMessage = "The synonym ";
                                                        }
                                                }
                                        } else if (object instanceof TeamOrPersonBase){
                                                IAgentService service = controller.getAgentService();
                                                //TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
                                                result = service.delete(((TeamOrPersonBase)object).getUuid());
+                                               errorMessage = "The team or person ";
                                        }
                                } catch (Exception e){
                                        MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(), e.getMessage(), TaxeditorBulkeditorPlugin.PLUGIN_ID, null, true);
                                }
                                if (result.isError() || result.isAbort()){
                                        if (!result.getExceptions().isEmpty()) {
-                                               String message = null;
+                                               List<String> messages = new ArrayList<String>();
                                                int i = result.getExceptions().size();
                                                for (Exception e:result.getExceptions()){
-                                                       i--;
-                                                       message+= e.getMessage();
-                                                       if (i>0){
-                                                               message+= ", ";
-                                                       }
+                                                       messages.add(e.getMessage());
                                                }
+                                               errorMessage += "could not be deleted.";
 
-
-                                               MessagingUtils.messageDialog("Delete not possible", getClass(), result.getExceptions().toString(), null);
+                                               DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
                                        }else{
                                                MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
                                        }
@@ -154,7 +163,13 @@ public class DeleteHandler extends AbstractHandler {
                                if (result.isOk() ){
                                        ((BulkEditor) editor).removeAnnotatedLine(annotation);
                                        if(result.getUpdatedObjects().size() != 0 || !result.getExceptions().isEmpty()){
-                                               MessagingUtils.informationDialog("Delete successfull", "The object is deleted but there are updated objects: " + result.toString());
+                                           List<String> messages = new ArrayList<String>();
+                        int i = result.getExceptions().size();
+                        for (Exception e:result.getExceptions()){
+                            messages.add(e.getMessage());
+                        }
+                                           errorMessage += "was deleted but there where updated objects";
+                                           DeleteResultMessagingUtils.messageDialogWithDetails(result, errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
                                        }
 
                                }
index c265577310b0a3c49b1a2c0d3490e61940442e4f..aaf23e9ef04c5d4bcc811f0d4d028b445acd3719 100644 (file)
@@ -31,7 +31,9 @@ public class DefaultNewEntityListener implements NewEntityListener {
     @Override
     public void onCreate(CdmBase cdmBase) {
         logger.warn("New Entity created : " + cdmBase);
-        ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession().addNewCdmEntity(cdmBase);
+        if(CdmApplicationState.getCurrentAppConfig() instanceof CdmApplicationRemoteController){
+            ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession().addNewCdmEntity(cdmBase);
+        }
     }
 
 }
index b7d278bc0492875af4bbee9895fd128222d019db..eed62fa607605f0927732ae7d453c2d7e668b28f 100644 (file)
@@ -1204,12 +1204,24 @@ public class TransientDescriptionService implements IDescriptionService {
         return defaultService.merge(arg0, arg1);
     }
 
+    /* (non-Javadoc)
+
+     * @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveTaxonDescription(java.util.UUID, java.util.UUID)
+     */
+    @Override
+    public UpdateResult moveTaxonDescription(UUID descriptionUuid, UUID targetTaxonUuid) {
+        return defaultService.moveTaxonDescription(descriptionUuid, targetTaxonUuid);
+    }
+
     /* (non-Javadoc)
      * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
      */
     @Override
     public List<DescriptionBase> merge(List<DescriptionBase> arg0, boolean arg1) {
+
         return defaultService.merge(arg0, arg1);
     }
 
+
+
 }
index aeac3d41eb92ebb43a98133a73a24f1b3f799a32..1a04b047cc568120fd57bf35534136d4dc6fd4ea 100644 (file)
@@ -17,6 +17,8 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.model.common.Annotation;
@@ -89,7 +91,13 @@ public class MoveDescriptionToOtherTaxonOperation extends
                annotation.setAnnotationType(AnnotationType.TECHNICAL());
                description.addAnnotation(annotation);
                newAcceptedTaxonNode.getTaxon().addDescription(description);
-               CdmStore.getService(IDescriptionService.class).merge(description);
+               if (CdmApplicationState.getCurrentAppConfig() instanceof CdmApplicationRemoteController) {
+            CdmStore.getService(IDescriptionService.class).merge(description);
+        } else {
+            CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);
+        }
+
+       //      CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
                monitor.worked(40);
 
                return postExecute(description);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DeleteResultMessagingUtils.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DeleteResultMessagingUtils.java
new file mode 100644 (file)
index 0000000..ef473c3
--- /dev/null
@@ -0,0 +1,53 @@
+// $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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+import eu.etaxonomy.cdm.api.service.DeleteResult;
+
+/**
+ * @author k.luther
+ * @date Oct 5, 2015
+ *
+ */
+public class DeleteResultMessagingUtils extends MessagingUtils {
+    /**
+     * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
+     *
+     * @param title
+     * @param source
+     * @param message
+     */
+    public static void messageDialogWithDetails(DeleteResult result, String message, String pluginId) {
+        if (result.isOk() && result.getExceptions().isEmpty()){
+            return;
+        }
+        List<String> details = new ArrayList<String>();
+        String title= "";
+
+        if (result.isOk() && result.getExceptions().size() > 0){
+            for (Exception e:result.getExceptions()){
+                details.add(e.getMessage());
+            }
+            title = "The delete was successfull.";
+        }
+        String stackTraceWithContext = getContextInfo(details);
+        CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, new Status(IStatus.ERROR, pluginId, null), stackTraceWithContext);
+        ced.open();
+
+
+
+    }
+}
index b316c2a0692e06056eb5f368d5a5206dbb07c898..36777e8ca31e1e9dbcf5e70aa73468a226b11902 100644 (file)
@@ -219,6 +219,19 @@ public class MessagingUtils {
         return stackTraceAndContextInfo.toString();
     }
 
+    public static String getContextInfo(List<String> contextInfo)  {
+        StringBuffer scontextInfoStringBuffer = new StringBuffer();
+
+
+        for(String infoItem : contextInfo) {
+            scontextInfoStringBuffer.append(infoItem + System.getProperty("line.separator"));
+        }
+
+
+
+        return scontextInfoStringBuffer.toString();
+    }
+
     private static Throwable getDefaultThrowable() {
         return new Throwable("Error thrown but no associated exception");
     }
index 7cbc1e76d0fcce6278a3b0c43e398776f40a2d89..ef365a8ec60eeee2293c100585813dc78d4458cf 100644 (file)
@@ -53,12 +53,14 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizard<ITaxonTreeNode>{
             Taxon taxon = taxonNodePage.getTaxon();
             try{
                 TaxonNode taxonNode = parent.addChildTaxon(taxon, parent.getReference(), parent.getMicroReference());
+
                 if(CdmStore.getCurrentSessionManager().isRemoting()) {
                     taxonNode = CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
                 } else {
                     taxonNode = CdmStore.getService(ITaxonNodeService.class).save(taxonNode);
                 }
                 generatedTaxonNodeUuid = taxonNode.getUuid();
+
                 Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
                 //FIXME:Remoting Hack for now - need to generalise this
                 // by making the affected objects a set of ICdmBase
index cce5f0c6eccfe395abb85cddb5c3c46a383e345f..d0b4db5f86234acc74498459526bc940ac580db9 100644 (file)
@@ -170,10 +170,11 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
 
                } else if (eventSource == selection_reuseExistingName) {
                        boolean enabled = selection_reuseExistingName.getEntity() == null;
+                       setTaxon(selection_reuseExistingName.getEntity());
                        selection_reuseExistingTaxon.setEnabled(enabled);
                        textNewTaxonName.setEnabled(enabled);
 
-                       setTaxon(selection_reuseExistingName.getEntity());
+                       //setTaxon(selection_reuseExistingName.getEntity());
                        complete = !textNewTaxonName.getText().isEmpty();
                } else if (eventSource == textNewTaxonName) {
                        boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
@@ -279,6 +280,7 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                        }
                }
                taxon = Taxon.NewInstance(taxonName, secundum);
+               //textNewTaxonName.setText(taxonName.getTitleCache());
        }
 
        private void setOpenInEditor(boolean openInEditor) {