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
.concept
.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
.runtime
.Status
;
18 import org
.eclipse
.swt
.widgets
.Event
;
19 import org
.eclipse
.ui
.IWorkbenchPart
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
24 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
25 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
27 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.operation
.CreateConceptRelationOperation
;
28 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
29 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 import eu
.etaxonomy
.taxeditor
.model
.TaxonRelationshipTypeInverseContainer
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonBaseSelectionDialog
;
36 * <p>CreateConceptRelationHandler class.</p>
42 public class CreateConceptRelationHandler
extends AbstractHandler
{
45 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
49 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 TaxonNameEditor editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(
53 Taxon taxonToBeFiltered
= editor
.getTaxon();
55 /* we need to get the activePart before calling TaxonBaseSelectionDialog.selectTaxon(), otherwise the
56 * the variable of the parent applicationContext in event are overwritten during this method call
57 * this is Linux specific bugfix see: #2685 ([LINUX] Editing concept relationships does not work under linux)
59 IWorkbenchPart activePart
= HandlerUtil
.getActivePart(event
);
61 Taxon relatedConcept
= TaxonBaseSelectionDialog
.selectTaxon(HandlerUtil
.getActiveShell(event
), editor
.getConversationHolder(), taxonToBeFiltered
);
64 if(relatedConcept
== null){
65 return Status
.CANCEL_STATUS
;
67 TaxonRelationshipType type
= (TaxonRelationshipType
) ((Event
)event
.getTrigger()).data
;
68 boolean isInverse
= type
.getInverseLabel().isEmpty()?
false:true;
69 TaxonRelationshipTypeInverseContainer typeInverseContainer
=new TaxonRelationshipTypeInverseContainer(type
, isInverse
) ;
72 IPostOperationEnabled postOperationEnabled
= (activePart
instanceof IPostOperationEnabled
) ?
(IPostOperationEnabled
) activePart
: null;
75 AbstractPostOperation operation
= new CreateConceptRelationOperation(event
.getCommand().getName(),
76 editor
.getUndoContext(), editor
.getTaxon(), relatedConcept
, typeInverseContainer
, postOperationEnabled
);
77 AbstractUtility
.executeOperation(operation
);
78 } catch (NotDefinedException e
) {
79 MessagingUtils
.warn(getClass(), "Command name not set");