2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.eclipse
.core
.commands
.AbstractHandler
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.jface
.viewers
.TreePath
;
22 import org
.eclipse
.jface
.viewers
.TreeSelection
;
23 import org
.eclipse
.ui
.IWorkbenchPart
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
27 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
28 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
29 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
30 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
31 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.DeleteDescriptionElementOperation
;
33 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.DeleteSpecimenDescriptionOperation
;
34 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.DeleteTaxonDescriptionOperation
;
35 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.operation
.DeleteMediaOperation
;
36 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
37 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
38 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
39 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
40 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
41 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
44 * <p>DeleteDescriptionHandler class.</p>
47 * @created Jun 22, 2010
50 public class DeleteHandler
extends AbstractHandler
{
53 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
57 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
58 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getActiveSite(event
).getSelectionProvider().getSelection();
60 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
61 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
62 ICdmEntitySessionEnabled cdmEntitySessionEnabled
= (part
instanceof ICdmEntitySessionEnabled
) ?
(ICdmEntitySessionEnabled
) part
: null;
65 String label
= event
.getCommand().getName();
67 IUndoContext undoContext
= EditorUtil
.getUndoContext();
69 List
<AbstractPostOperation
<?
>> operations
= new ArrayList
<AbstractPostOperation
<?
>>();
71 for(Object object
: selection
.toArray()){
74 if(object
instanceof TaxonDescription
){
75 operations
.add(new DeleteTaxonDescriptionOperation(label
, undoContext
, (TaxonDescription
) object
, postOperationEnabled
, cdmEntitySessionEnabled
));
77 else if(object
instanceof SpecimenDescription
){
78 operations
.add(new DeleteSpecimenDescriptionOperation(label
, undoContext
, (SpecimenDescription
) object
, postOperationEnabled
, cdmEntitySessionEnabled
)) ;
80 // DescriptionElementBase
81 else if(object
instanceof DescriptionElementBase
){
82 operations
.add(new DeleteDescriptionElementOperation(label
, undoContext
, (DescriptionElementBase
) object
, postOperationEnabled
, cdmEntitySessionEnabled
));
84 else if(object
instanceof FeatureNodeContainer
){
85 List
<DescriptionElementBase
> descriptions
= ((FeatureNodeContainer
) object
).getDescriptionElementsForEntireBranch();
87 for(DescriptionElementBase description
: descriptions
){
88 operations
.add(new DeleteDescriptionElementOperation(label
, undoContext
, description
, postOperationEnabled
, cdmEntitySessionEnabled
));
92 else if(object
instanceof Media
){
93 TreeSelection treeSelection
= (TreeSelection
) selection
;
95 TreePath
[] path
= treeSelection
.getPathsFor(object
);
97 DescriptionBase
<?
> imageGallery
= (DescriptionBase
<?
>) path
[0].getFirstSegment();
99 operations
.add(new DeleteMediaOperation(label
, undoContext
, imageGallery
, (Media
) object
, postOperationEnabled
));
102 MessagingUtils
.error(getClass(), "Selection is not valid for this delete handler", null);
106 // execute all cumulated operations
107 for(AbstractPostOperation
<?
> operation
: operations
){
108 AbstractUtility
.executeOperation(operation
);
111 } catch (NotDefinedException e
) {
112 MessagingUtils
.warn(getClass(), "Command name not set.");