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
.concept
.handler
;
12 import java
.util
.HashSet
;
13 import java
.util
.Iterator
;
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
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.ui
.IWorkbenchPart
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
26 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
27 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.operation
.DeleteConceptRelationOperation
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
36 * @created Jan 25, 2011
39 public class DeleteConceptRelationHandler
extends AbstractHandler
{
42 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
45 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
46 TaxonNameEditor editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(
49 ISelection selection
= HandlerUtil
.getActiveSite(event
).getSelectionProvider().getSelection();
51 Set
<TaxonRelationship
> relations
= new HashSet
<TaxonRelationship
>();
53 if(selection
instanceof IStructuredSelection
){
54 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
55 Iterator iterator
= structuredSelection
.iterator();
57 while (iterator
.hasNext()){
58 Object element
= iterator
.next();
59 if(element
instanceof TaxonRelationship
){
60 relations
.add((TaxonRelationship
) element
);
65 IWorkbenchPart activePart
= HandlerUtil
.getActivePart(event
);
66 IPostOperationEnabled postOperationEnabled
= (activePart
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) activePart
: null;
69 AbstractPostOperation operation
= new DeleteConceptRelationOperation(event
.getCommand().getName(),
70 editor
.getUndoContext(), editor
.getTaxon(), relations
, postOperationEnabled
);
71 EditorUtil
.executeOperation(operation
);
72 } catch (NotDefinedException e
) {
73 MessagingUtils
.warn(getClass(), "Command name not set"); //$NON-NLS-1$