ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / handler / DeleteHandler.java
index 04fbab44f75cd005592cd878bc4129cc8f91d778..7616eb9d27948f670f9d44b17982c58fde0a6326 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -24,16 +23,22 @@ import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.SpecimenDescription;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteDescriptionElementOperation;
+import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteSpecimenDescriptionOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation;
 import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 
 /**
  * <p>DeleteDescriptionHandler class.</p>
@@ -43,68 +48,71 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  * @version 1.0
  */
 public class DeleteHandler extends AbstractHandler {
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
-       public Object execute(ExecutionEvent event) throws ExecutionException {
+       @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
                IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection();
 
                IWorkbenchPart part = HandlerUtil.getActivePart(event);
                IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
-               
+               ICdmEntitySessionEnabled cdmEntitySessionEnabled = (part instanceof ICdmEntitySessionEnabled) ? (ICdmEntitySessionEnabled) part : null;
+
                try {
                        String label = event.getCommand().getName();
-               
+
                        IUndoContext undoContext = EditorUtil.getUndoContext();
-                       
-                       List<AbstractPostOperation> operations = new ArrayList<AbstractPostOperation>();
-                       
+
+                       List<AbstractPostOperation<?>> operations = new ArrayList<AbstractPostOperation<?>>();
+
                        for(Object object : selection.toArray()){
-                               
-                               AbstractPostOperation operation = null;
-                               
+
                                // TaxonDescription
                                if(object instanceof TaxonDescription){
-                                       operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, postOperationEnabled));
+                                       operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, postOperationEnabled, cdmEntitySessionEnabled));
+                               }
+                               else if(object instanceof SpecimenDescription){
+                                   operations.add(new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) object, postOperationEnabled, cdmEntitySessionEnabled)) ;
                                }
                                // DescriptionElementBase
                                else if(object instanceof DescriptionElementBase){
-                                       operations.add(new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) object, postOperationEnabled));
+                                       operations.add(new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) object, postOperationEnabled, cdmEntitySessionEnabled));
                                }
                                else if(object instanceof FeatureNodeContainer){
                                        List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) object).getDescriptionElementsForEntireBranch();
-                                       
+
                                        for(DescriptionElementBase description : descriptions){
-                                               operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, postOperationEnabled)); 
+                                               operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, postOperationEnabled, cdmEntitySessionEnabled));
                                        }
                                }
                                // Media
                                else if(object instanceof Media){
                                        TreeSelection treeSelection = (TreeSelection) selection;
-                                       
+
                                        TreePath[] path = treeSelection.getPathsFor(object);
-                                       
-                                       TaxonDescription imageGallery = (TaxonDescription) path[0].getFirstSegment();
-                                                                               
+
+                                       DescriptionBase<?> imageGallery = (DescriptionBase<?>) path[0].getFirstSegment();
+
                                        operations.add(new DeleteMediaOperation(label, undoContext, imageGallery, (Media) object, postOperationEnabled));
                                }
                                else{
-                                       EditorUtil.error(getClass(), "Selection is not valid for this delete handler", null);
-                               }       
+                                       MessagingUtils.error(getClass(), "Selection is not valid for this delete handler", null);
+                               }
                        }
-                       
+
                        // execute all cumulated operations
-                       for(AbstractPostOperation operation : operations){
-                               EditorUtil.executeOperation(operation);
+                       for(AbstractPostOperation<?> operation : operations){
+                               AbstractUtility.executeOperation(operation);
                        }
-                       
+
                } catch (NotDefinedException e) {
-                       EditorUtil.warn(getClass(), "Command name not set.");
+                       MessagingUtils.warn(getClass(), "Command name not set.");
                }
-               
-               
+
+
                return null;
        }
 }