1 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
.handler
;
3 import java
.util
.ArrayList
;
6 import org
.eclipse
.core
.commands
.AbstractHandler
;
7 import org
.eclipse
.core
.commands
.ExecutionEvent
;
8 import org
.eclipse
.core
.commands
.ExecutionException
;
9 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
10 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
11 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
12 import org
.eclipse
.jface
.viewers
.TreePath
;
13 import org
.eclipse
.jface
.viewers
.TreeSelection
;
14 import org
.eclipse
.ui
.IWorkbenchPart
;
15 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
17 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
18 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
19 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
20 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
21 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.DeleteDescriptionElementOperation
;
22 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.operation
.DeleteMediaOperation
;
23 import eu
.etaxonomy
.taxeditor
.editor
.view
.uses
.operation
.DeleteTaxonUseOperation
;
24 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 public class DeleteUseHandler
extends AbstractHandler
{
34 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
38 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
39 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
40 .getActiveSite(event
).getSelectionProvider().getSelection();
42 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
43 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
47 String label
= event
.getCommand().getName();
49 IUndoContext undoContext
= EditorUtil
.getUndoContext();
51 List
<AbstractPostOperation
> operations
= new ArrayList
<AbstractPostOperation
>();
53 for (Object object
: selection
.toArray()) {
55 AbstractPostOperation operation
= null;
58 if (object
instanceof TaxonDescription
) {
59 operations
.add(new DeleteTaxonUseOperation(label
,
60 undoContext
, (TaxonDescription
) object
,
61 postOperationEnabled
));
63 // DescriptionElementBase
64 else if (object
instanceof DescriptionElementBase
) {
65 operations
.add(new DeleteDescriptionElementOperation(label
,
66 undoContext
, (DescriptionElementBase
) object
,
67 postOperationEnabled
));
68 } else if (object
instanceof FeatureNodeContainer
) {
69 List
<DescriptionElementBase
> descriptions
= ((FeatureNodeContainer
) object
)
70 .getDescriptionElementsForEntireBranch();
72 for (DescriptionElementBase description
: descriptions
) {
73 operations
.add(new DeleteDescriptionElementOperation(
74 label
, undoContext
, description
,
75 postOperationEnabled
));
79 else if (object
instanceof Media
) {
80 TreeSelection treeSelection
= (TreeSelection
) selection
;
82 TreePath
[] path
= treeSelection
.getPathsFor(object
);
84 TaxonDescription imageGallery
= (TaxonDescription
) path
[0]
88 .add(new DeleteMediaOperation(label
, undoContext
,
89 imageGallery
, (Media
) object
,
90 postOperationEnabled
));
92 EditorUtil
.error(getClass(),
93 "Selection is not valid for this delete handler",
98 // execute all cumulated operations
99 for (AbstractPostOperation operation
: operations
) {
100 EditorUtil
.executeOperation(operation
);
103 } catch (NotDefinedException e
) {
104 EditorUtil
.warn(getClass(), "Command name not set.");