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
.derivate
.handler
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jface
.viewers
.TreeNode
;
20 import org
.eclipse
.ui
.IWorkbenchPart
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
25 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
26 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.operation
.DeleteDerivateOperation
;
29 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
39 public class DeleteDerivateHandler
extends AbstractHandler
{
42 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getActiveSite(event
).getSelectionProvider().getSelection();
49 IWorkbenchPart part
= HandlerUtil
.getActivePart(event
);
50 IPostOperationEnabled postOperationEnabled
= (part
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) part
: null;
53 String label
= event
.getCommand().getName();
55 IUndoContext undoContext
= EditorUtil
.getUndoContext();
57 if(selection
.size()>0){
58 Object object
= selection
.iterator().next();
60 if(object
instanceof TreeNode
){
61 TreeNode treeNode
= (TreeNode
)object
;
62 Object value
= ((TreeNode
) object
).getValue();
63 if(value
instanceof SpecimenOrObservationBase
<?
> || value
instanceof Sequence
|| value
instanceof SingleRead
){
64 DeleteDerivateOperation deleteDerivateOperation
= new DeleteDerivateOperation(label
, undoContext
, (CdmBase
) object
, postOperationEnabled
);
65 AbstractUtility
.executeOperation(deleteDerivateOperation
);
69 MessagingUtils
.error(getClass(), "Selection is not valid for this delete handler", null);
73 } catch (NotDefinedException e
) {
74 MessagingUtils
.warn(getClass(), "Command name not set.");