- fixed possible ClassCastException (#4533)
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 9 Dec 2014 15:46:17 +0000 (15:46 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 9 Dec 2014 15:46:17 +0000 (15:46 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/operation/DeleteMediaOperation.java

index 753f38769c7d592ed1b4765bd83803b71fe8ff17..844f0a1f039734cdcb25965245617cc438029896 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * 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.
 */
 * 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,6 +24,7 @@ import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 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.TaxonDescription;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.media.Media;
@@ -31,10 +32,11 @@ import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteDescriptionElementOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation;
 import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteDescriptionElementOperation;
 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.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 
 /**
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 
 /**
@@ -45,28 +47,29 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  * @version 1.0
  */
 public class DeleteHandler extends AbstractHandler {
  * @version 1.0
  */
 public class DeleteHandler extends AbstractHandler {
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
        /* (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;
                IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection();
 
                IWorkbenchPart part = HandlerUtil.getActivePart(event);
                IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
-               
+
                try {
                        String label = event.getCommand().getName();
                try {
                        String label = event.getCommand().getName();
-               
+
                        IUndoContext undoContext = EditorUtil.getUndoContext();
                        IUndoContext undoContext = EditorUtil.getUndoContext();
-                       
+
                        List<AbstractPostTaxonOperation> operations = new ArrayList<AbstractPostTaxonOperation>();
                        List<AbstractPostTaxonOperation> operations = new ArrayList<AbstractPostTaxonOperation>();
-                       
+
                        for(Object object : selection.toArray()){
                        for(Object object : selection.toArray()){
-                               
+
                                AbstractPostOperation operation = null;
                                AbstractPostOperation operation = null;
-                               
+
                                // TaxonDescription
                                if(object instanceof TaxonDescription){
                                        operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, postOperationEnabled));
                                // TaxonDescription
                                if(object instanceof TaxonDescription){
                                        operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, postOperationEnabled));
@@ -77,36 +80,36 @@ public class DeleteHandler extends AbstractHandler {
                                }
                                else if(object instanceof FeatureNodeContainer){
                                        List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) object).getDescriptionElementsForEntireBranch();
                                }
                                else if(object instanceof FeatureNodeContainer){
                                        List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) object).getDescriptionElementsForEntireBranch();
-                                       
+
                                        for(DescriptionElementBase description : descriptions){
                                        for(DescriptionElementBase description : descriptions){
-                                               operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, postOperationEnabled)); 
+                                               operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, postOperationEnabled));
                                        }
                                }
                                // Media
                                else if(object instanceof Media){
                                        TreeSelection treeSelection = (TreeSelection) selection;
                                        }
                                }
                                // Media
                                else if(object instanceof Media){
                                        TreeSelection treeSelection = (TreeSelection) selection;
-                                       
+
                                        TreePath[] path = treeSelection.getPathsFor(object);
                                        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{
                                        MessagingUtils.error(getClass(), "Selection is not valid for this delete handler", null);
                                        operations.add(new DeleteMediaOperation(label, undoContext, imageGallery, (Media) object, postOperationEnabled));
                                }
                                else{
                                        MessagingUtils.error(getClass(), "Selection is not valid for this delete handler", null);
-                               }       
+                               }
                        }
                        }
-                       
+
                        // execute all cumulated operations
                        // execute all cumulated operations
-                       for(AbstractPostOperation operation : operations){
-                               EditorUtil.executeOperation(operation);
+                       for(AbstractPostOperation<?> operation : operations){
+                               AbstractUtility.executeOperation(operation);
                        }
                        }
-                       
+
                } catch (NotDefinedException e) {
                        MessagingUtils.warn(getClass(), "Command name not set.");
                }
                } catch (NotDefinedException e) {
                        MessagingUtils.warn(getClass(), "Command name not set.");
                }
-               
-               
+
+
                return null;
        }
 }
                return null;
        }
 }
index 63172152fec8b8be561b289b4fc5d6cbfa74e0da..b14889f28074e5ee2eb1a553c2f5a647fdb429ed 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * 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.
 */
 * 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.
 */
@@ -29,12 +29,11 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  * @created 31.03.2009
  * @version 1.0
  */
  * @created 31.03.2009
  * @version 1.0
  */
-@Deprecated // I don't think this is really used anymore
 public class DeleteMediaOperation extends AbstractPostTaxonOperation {
 public class DeleteMediaOperation extends AbstractPostTaxonOperation {
-       
-       private Media media;
 
 
-       private DescriptionBase<?> description;
+       private final Media media;
+
+       private final DescriptionBase<?> description;
 
        /**
         * <p>Constructor for DeleteMediaOperation.</p>
 
        /**
         * <p>Constructor for DeleteMediaOperation.</p>
@@ -48,7 +47,7 @@ public class DeleteMediaOperation extends AbstractPostTaxonOperation {
        public DeleteMediaOperation(String label, IUndoContext undoContext,
                        DescriptionBase<?> description, Media media, IPostOperationEnabled postOperationEnabled) {
                super(label, undoContext, postOperationEnabled);
        public DeleteMediaOperation(String label, IUndoContext undoContext,
                        DescriptionBase<?> description, Media media, IPostOperationEnabled postOperationEnabled) {
                super(label, undoContext, postOperationEnabled);
-               
+
                this.media = media;
                this.description = description;
        }
                this.media = media;
                this.description = description;
        }
@@ -85,9 +84,9 @@ public class DeleteMediaOperation extends AbstractPostTaxonOperation {
        @Override
        public IStatus undo(IProgressMonitor monitor, IAdaptable info)
                        throws ExecutionException {
        @Override
        public IStatus undo(IProgressMonitor monitor, IAdaptable info)
                        throws ExecutionException {
-               
+
                ImagesUtility.addMediaToGallery(description, media);
                ImagesUtility.addMediaToGallery(description, media);
-               
+
                return postExecute(null);
        }
 
                return postExecute(null);
        }