3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.handler
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.eclipse
.core
.commands
.AbstractHandler
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
20 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.jface
.viewers
.TreePath
;
23 import org
.eclipse
.jface
.viewers
.TreeSelection
;
24 import org
.eclipse
.ui
.IWorkbenchPart
;
25 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
27 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
28 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
29 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
30 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.DeleteDescriptionElementOperation
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.DeleteTaxonDescriptionOperation
;
33 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.operation
.DeleteMediaOperation
;
34 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
35 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
36 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
37 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
38 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
41 * <p>DeleteDescriptionHandler class.</p>
44 * @created Jun 22, 2010
47 public class DeleteHandler
extends AbstractHandler
{
50 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
53 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
54 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getActiveSite(event
).getSelectionProvider().getSelection();
56 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
57 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
60 String label
= event
.getCommand().getName();
62 IUndoContext undoContext
= EditorUtil
.getUndoContext();
64 List
<AbstractPostTaxonOperation
> operations
= new ArrayList
<AbstractPostTaxonOperation
>();
66 for(Object object
: selection
.toArray()){
68 AbstractPostOperation operation
= null;
71 if(object
instanceof TaxonDescription
){
72 operations
.add(new DeleteTaxonDescriptionOperation(label
, undoContext
, (TaxonDescription
) object
, postOperationEnabled
));
74 // DescriptionElementBase
75 else if(object
instanceof DescriptionElementBase
){
76 operations
.add(new DeleteDescriptionElementOperation(label
, undoContext
, (DescriptionElementBase
) object
, postOperationEnabled
));
78 else if(object
instanceof FeatureNodeContainer
){
79 List
<DescriptionElementBase
> descriptions
= ((FeatureNodeContainer
) object
).getDescriptionElementsForEntireBranch();
81 for(DescriptionElementBase description
: descriptions
){
82 operations
.add(new DeleteDescriptionElementOperation(label
, undoContext
, description
, postOperationEnabled
));
86 else if(object
instanceof Media
){
87 TreeSelection treeSelection
= (TreeSelection
) selection
;
89 TreePath
[] path
= treeSelection
.getPathsFor(object
);
91 TaxonDescription imageGallery
= (TaxonDescription
) path
[0].getFirstSegment();
93 operations
.add(new DeleteMediaOperation(label
, undoContext
, imageGallery
, (Media
) object
, postOperationEnabled
));
96 MessagingUtils
.error(getClass(), "Selection is not valid for this delete handler", null);
100 // execute all cumulated operations
101 for(AbstractPostOperation operation
: operations
){
102 EditorUtil
.executeOperation(operation
);
105 } catch (NotDefinedException e
) {
106 MessagingUtils
.warn(getClass(), "Command name not set.");