- refactored DerivateViewEditorInput to use UUIDs instead of CDM entities
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 11 Nov 2014 08:34:23 +0000 (08:34 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 11 Nov 2014 08:34:23 +0000 (08:34 +0000)
 - added delete operation to DerivateView (currently only deleting leafs of the derivate tree is allowed)

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/DeleteDerivateHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/operation/DeleteDerivateOperation.java

index ec743254295cc25407643fd674219102a1f6bfc1..0bb16deea2dc1214ee84fd731d0d4488303ca593 100644 (file)
@@ -31,6 +31,7 @@ import eu.etaxonomy.cdm.api.service.DeleteResult;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
+import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
 import eu.etaxonomy.cdm.api.service.dto.DerivateHierarchyDTO;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.api.service.search.SearchResult;
@@ -946,8 +947,16 @@ public class TransientOccurenceService implements IOccurrenceService {
      * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#deleteDerivateHierarchy(eu.etaxonomy.cdm.model.common.ICdmBase)
      */
     @Override
-    public DeleteResult deleteDerivateHierarchy(ICdmBase arg0) {
-        return defaultService.deleteDerivateHierarchy(arg0);
+    public DeleteResult deleteDerivateHierarchy(ICdmBase from, SpecimenDeleteConfigurator config) {
+        return defaultService.deleteDerivateHierarchy(from, config);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#delete(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase, eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator)
+     */
+    @Override
+    public DeleteResult delete(SpecimenOrObservationBase<?> specimen, SpecimenDeleteConfigurator config) {
+        return defaultService.delete(specimen, config);
     }
 
 }
index 263d12a243fb7f5dd281ed1cef05cb5a4cc47aca..1e1da7b5bde030cb6e32e859edfdf8541fd86672 100644 (file)
@@ -10,6 +10,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.jface.viewers.Viewer;
 
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.model.molecular.DnaSample;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
@@ -17,7 +18,7 @@ import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 public class DerivateContentProvider implements ITreeContentProvider {
 
@@ -33,16 +34,14 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
        @Override
        public Object[] getElements(Object inputElement) {
-           SpecimenOrObservationBase specimen = null;
+           SpecimenOrObservationBase<?> rootElement = null;
            if(inputElement instanceof DerivateViewEditorInput){
-               specimen = ((DerivateViewEditorInput) inputElement).getDerivate();
+               rootElement = CdmStore.getService(IOccurrenceService.class).load(((DerivateViewEditorInput) inputElement).getRootElementUUID());
            }
 
-           specimen = EditorUtil.getTopMostDerivate(specimen);
-
-           if(specimen!=null){
+           if(rootElement!=null){
                //show topmost element in the derivate hierarchy if no field unit was found
-               TreeNode node = new TreeNode(specimen);
+               TreeNode node = new TreeNode(rootElement);
             return Collections.singleton(node).toArray();
            }
            return null;
@@ -112,8 +111,8 @@ public class DerivateContentProvider implements ITreeContentProvider {
             return !((Sequence)element).getSingleReads().isEmpty();
         }
         else if(element instanceof SpecimenOrObservationBase){
-               SpecimenOrObservationBase specimenOrObservation = (SpecimenOrObservationBase)element;
-               for(DerivationEvent event:(Set<DerivationEvent>)specimenOrObservation.getDerivationEvents()){
+               SpecimenOrObservationBase<?> specimenOrObservation = (SpecimenOrObservationBase<?>)element;
+               for(DerivationEvent event:specimenOrObservation.getDerivationEvents()){
                    if(!event.getDerivatives().isEmpty()){
                        return true;
                    }
@@ -122,9 +121,9 @@ public class DerivateContentProvider implements ITreeContentProvider {
                return false;
        }
 
-       private List<DerivedUnit> getDerivates(SpecimenOrObservationBase specimenOrObservation){
+       private List<DerivedUnit> getDerivates(SpecimenOrObservationBase<?> specimenOrObservation){
            List<DerivedUnit> derivates = new ArrayList<DerivedUnit>();
-           for(DerivationEvent derivationEvent:(Set<DerivationEvent>)specimenOrObservation.getDerivationEvents()){
+           for(DerivationEvent derivationEvent:specimenOrObservation.getDerivationEvents()){
                derivates.addAll(derivationEvent.getDerivatives());
            }
            return derivates;
index a971784de2b3d74d020967abaf6011d9ce70a2de..963cd911fb11615a7d962ff2abe1953a7e7fb145 100644 (file)
@@ -31,7 +31,9 @@ import org.eclipse.ui.part.EditorPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
@@ -41,6 +43,7 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
 
@@ -50,17 +53,7 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
  */
 public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
         IConversationEnabled, IPartContentHasDetails, IPartContentHasMedia, IPartContentHasSupplementalData,
-        ISelectionChangedListener {
-
-       /**
-     * Key used for storing a single DerivateView in a memento
-     */
-    private static final String DERIVATE_VIEW_MEMENTO_KEY = "derivateView";
-
-    /**
-     * Key to to group mementos for every single DerivateView
-     */
-    private static final String DERIVATE_VIEWS_MEMENTO_KEY = "derivateViews";
+        ISelectionChangedListener, IPostOperationEnabled {
 
     public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView";
 
@@ -112,8 +105,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         IEditorInput editorInput = getEditorInput();
         viewer.setInput(editorInput);
         if(editorInput instanceof DerivateViewEditorInput){
-            SpecimenOrObservationBase<?> specimen = ((DerivateViewEditorInput) editorInput).getDerivate();
-            SpecimenOrObservationBase<?> rootElement = ((DerivateViewEditorInput) editorInput).getRootElement();
+            SpecimenOrObservationBase<?> specimen = CdmStore.getService(IOccurrenceService.class).load(((DerivateViewEditorInput) editorInput).getDerivateUUID());
+            SpecimenOrObservationBase<?> rootElement = CdmStore.getService(IOccurrenceService.class).load(((DerivateViewEditorInput) editorInput).getRootElementUUID());
             setPartName(labelProvider.getDerivateText(rootElement));
             viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
         }
@@ -304,4 +297,34 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         return selection;
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
+     */
+    @Override
+    public boolean postOperation(CdmBase objectAffectedByOperation) {
+        refreshTree();
+        if(objectAffectedByOperation!=null){
+            DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput();
+            if(objectAffectedByOperation.getUuid().equals(derivateViewEditorInput.getRootElementUUID())){
+                // TODO close derivate view if root element is deleted
+//                this.getViewer().setEditorSite().getPage().close();
+                return true;
+            }
+            else if(objectAffectedByOperation.getUuid().equals(derivateViewEditorInput.getDerivateUUID())){
+                derivateViewEditorInput.setRootAsDerivate();
+            }
+            changed(objectAffectedByOperation);
+            return true;
+        }
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
+     */
+    @Override
+    public boolean onComplete() {
+        return true;
+    }
+
 }
index 18f89f0f035806eeb6dfc9511315a88db8a7bd91..c323cb3f0621f4e74b88a409a45499e2a0cab642 100644 (file)
@@ -13,11 +13,10 @@ import java.util.UUID;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IPersistable;
 import org.eclipse.ui.IPersistableElement;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
@@ -33,20 +32,16 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @date 25.11.2013
  *
  */
-public class DerivateViewEditorInput implements IEditorInput, IPersistable {
+public class DerivateViewEditorInput implements IEditorInput{
 
     /**
-     * Key used for saving the {@link UUID} to a memento
+     * The selected derivate {@link UUID}
      */
-    public static final String UUID_MEMENTO_KEY = "UUID";
+    private UUID derivateUUID;
     /**
-     * The selected derivate
+     * The {@link UUID} of the root of the hierarchy (may be the same object as the derivate)
      */
-    private final SpecimenOrObservationBase<?> derivate;
-    /**
-     * The root of the hierarchy (may be the same object as the derivate)
-     */
-    private SpecimenOrObservationBase<?> root;
+    private UUID rootUUID;
 
     private final ConversationHolder conversationHolder;
 
@@ -54,22 +49,24 @@ public class DerivateViewEditorInput implements IEditorInput, IPersistable {
      * Creates an editor input for the {@link DerivateView} with the currently selected derivate and the
      * corresponding {@link FieldUnit} (both may be the same object).
      * @param derivateUuid the {@link UUID} of the derivate for which the derivate hierarchy should be shown
-     * @param root the root of the hierarchy
+     * @param rootUUID the root of the hierarchy
      */
     public DerivateViewEditorInput(UUID derivateUuid) {
         super();
         this.conversationHolder = CdmStore.createConversation();
-        this.derivate = CdmStore.getCurrentApplicationConfiguration().getOccurrenceService().load(derivateUuid);
+        this.derivateUUID = derivateUuid;
+        SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(derivateUuid);
         if(derivate instanceof FieldUnit){
-            this.root = derivate;
+            this.rootUUID = derivateUUID;
         }
         else if(derivate instanceof DerivedUnit){
-            root = EditorUtil.getTopMostDerivate(derivate);
-            if(root==null){
-                root = derivate;
+            SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+            rootUUID = topMostDerivate==null?null:topMostDerivate.getUuid();
+            if(rootUUID==null){
+                rootUUID = derivateUUID;
             }
         }
-        if(root==null){
+        if(rootUUID==null){
             MessagingUtils.messageDialog("Failed initializing editor", DerivateViewEditorInput.class, "No root element found!");
         }
     }
@@ -105,7 +102,7 @@ public class DerivateViewEditorInput implements IEditorInput, IPersistable {
      */
     @Override
     public String getName() {
-        return derivate.toString();
+        return derivateUUID.toString();
     }
 
     /* (non-Javadoc)
@@ -121,27 +118,21 @@ public class DerivateViewEditorInput implements IEditorInput, IPersistable {
      */
     @Override
     public String getToolTipText() {
-        return derivate.toString();
+        return derivateUUID.toString();
     }
 
+    public UUID getDerivateUUID() {
+        return derivateUUID;
+    }
 
-    /**
-     * @return the specimen
-     */
-    public SpecimenOrObservationBase<?> getDerivate() {
-        return derivate;
+    public UUID getRootElementUUID() {
+        return rootUUID;
     }
 
-    /**
-     * @return the fieldUnit
-     */
-    public SpecimenOrObservationBase<?> getRootElement() {
-        return root;
+    public void setRootAsDerivate(){
+        this.derivateUUID = this.rootUUID;
     }
 
-    /**
-     * @return the conversationHolder
-     */
     public ConversationHolder getConversationHolder() {
         return conversationHolder;
     }
@@ -153,7 +144,7 @@ public class DerivateViewEditorInput implements IEditorInput, IPersistable {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((root == null) ? 0 : root.hashCode());
+        result = prime * result + ((rootUUID == null) ? 0 : rootUUID.hashCode());
         return result;
     }
 
@@ -172,23 +163,14 @@ public class DerivateViewEditorInput implements IEditorInput, IPersistable {
             return false;
         }
         DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
-        if (root == null) {
-            if (other.root != null) {
+        if (rootUUID == null) {
+            if (other.rootUUID != null) {
                 return false;
             }
-        } else if (!root.equals(other.root)) {
+        } else if (!rootUUID.equals(other.rootUUID)) {
             return false;
         }
         return true;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
-     */
-    @Override
-    public void saveState(IMemento memento) {
-        UUID uuid = derivate.getUuid();
-        memento.putString(UUID_MEMENTO_KEY, uuid.toString());
-    }
-
 }
index 7f8cc9be4ccb609c35e9b123337b0dd8488a510f..7a38d5936199b5310d1aa4a86be70157c1d745cc 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
@@ -61,7 +62,10 @@ public class DeleteDerivateHandler extends AbstractHandler {
                     TreeNode treeNode = (TreeNode)object;
                     Object value = ((TreeNode) object).getValue();
                     if(value instanceof SpecimenOrObservationBase<?> || value instanceof Sequence || value instanceof SingleRead){
-                        DeleteDerivateOperation deleteDerivateOperation = new DeleteDerivateOperation(label, undoContext, (CdmBase) value, postOperationEnabled);
+                        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
+                        config.setDeleteChildren(false);
+                        config.setShiftHierarchyUp(false);
+                        DeleteDerivateOperation deleteDerivateOperation = new DeleteDerivateOperation(label, undoContext, (CdmBase) value, postOperationEnabled, config);
                         AbstractUtility.executeOperation(deleteDerivateOperation);
                     }
                 }
index 9ef94508c5147595e1f1a573969f49e1a3a51206..5032dde4168c692c542897a6675c5be41ed89a75 100644 (file)
@@ -15,9 +15,14 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 
+import eu.etaxonomy.cdm.api.service.DeleteResult;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  *
@@ -27,11 +32,20 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  */
 public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
 
+    private final SpecimenDeleteConfigurator deleteConfigurator;
+
     public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
             IPostOperationEnabled postOperationEnabled) {
+        this(label, undoContext, element, postOperationEnabled, new SpecimenDeleteConfigurator());
+    }
+
+    public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
+            IPostOperationEnabled postOperationEnabled, SpecimenDeleteConfigurator config) {
         super(label, undoContext, element, postOperationEnabled);
+        this.deleteConfigurator = config;
     }
 
+
     /*
      * (non-Javadoc)
      *
@@ -42,7 +56,17 @@ public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
     /** {@inheritDoc} */
     @Override
     public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-        return postExecute(null);
+        DeleteResult deleteResult = CdmStore.getService(IOccurrenceService.class).deleteDerivateHierarchy(element, deleteConfigurator);
+        if(!deleteResult.isOk()){
+            String exceptionMessage = "";
+            for(Exception exception:deleteResult.getExceptions()){
+                exceptionMessage += exception.getLocalizedMessage();
+            }
+            //TODO: add method to DeleteResult to sum up exceptions
+            MessagingUtils.warningDialog("Deletion failed", this, exceptionMessage);
+            return postExecute(null);
+        }
+        return postExecute(element);
     }
 
     /*