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
.apache
.log4j
.Logger
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
21 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.jface
.viewers
.TreePath
;
24 import org
.eclipse
.jface
.viewers
.TreeSelection
;
25 import org
.eclipse
.ui
.IWorkbenchPart
;
26 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
28 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
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
.model
.FeatureNodeContainer
;
33 import eu
.etaxonomy
.taxeditor
.operations
.AbstractPostOperation
;
34 import eu
.etaxonomy
.taxeditor
.operations
.DeleteDescriptionElementOperation
;
35 import eu
.etaxonomy
.taxeditor
.operations
.DeleteMediaOperation
;
36 import eu
.etaxonomy
.taxeditor
.operations
.DeleteTaxonDescriptionOperation
;
37 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
40 * <p>DeleteDescriptionHandler class.</p>
43 * @created Jun 22, 2010
46 public class DeleteDescriptionHandler
extends AbstractHandler
{
47 private static final Logger logger
= Logger
48 .getLogger(DeleteDescriptionHandler
.class);
51 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
54 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
55 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getActiveMenuSelection(event
);
57 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
58 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
61 String label
= event
.getCommand().getName();
63 IUndoContext undoContext
= EditorUtil
.getUndoContext();
65 List
<AbstractPostOperation
> operations
= new ArrayList
<AbstractPostOperation
>();
67 for(Object object
: selection
.toArray()){
69 AbstractPostOperation operation
= null;
72 if(object
instanceof TaxonDescription
){
73 operations
.add(new DeleteTaxonDescriptionOperation(label
, undoContext
, (TaxonDescription
) object
, postOperationEnabled
));
75 // DescriptionElementBase
76 else if(object
instanceof DescriptionElementBase
){
77 operations
.add(new DeleteDescriptionElementOperation(label
, undoContext
, (DescriptionElementBase
) object
, postOperationEnabled
));
79 else if(object
instanceof FeatureNodeContainer
){
80 List
<DescriptionElementBase
> descriptions
= ((FeatureNodeContainer
) object
).getDescriptionElementsForEntireBranch();
82 for(DescriptionElementBase description
: descriptions
){
83 operations
.add(new DeleteDescriptionElementOperation(label
, undoContext
, (DescriptionElementBase
) object
, postOperationEnabled
));
87 else if(object
instanceof Media
){
88 TreeSelection treeSelection
= (TreeSelection
) HandlerUtil
.getActiveMenuSelection(event
);
90 TreePath
[] path
= treeSelection
.getPathsFor(object
);
92 TaxonDescription imageGallery
= (TaxonDescription
) path
[0].getFirstSegment();
94 operations
.add(new DeleteMediaOperation(label
, undoContext
, imageGallery
, (Media
) object
, postOperationEnabled
));
97 logger
.error("Selection os not valid for this delete handler");
101 // execute all cumulated operations
102 for(AbstractPostOperation operation
: operations
){
103 EditorUtil
.executeOperation(operation
);
106 } catch (NotDefinedException e
) {
107 logger
.warn("Command name not set");