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
.Iterator
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.ui
.PartInitException
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
24 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
25 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
26 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 * @created Jan 25, 2011
33 public class OpenRelatedConceptHandler
extends AbstractHandler
{
36 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
40 MultiPageTaxonEditor editor
= EditorUtil
.getActiveMultiPageTaxonEditor();
42 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
44 if(selection
instanceof IStructuredSelection
){
45 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
46 Iterator iterator
= structuredSelection
.iterator();
48 while (iterator
.hasNext()){
49 Object element
= iterator
.next();
50 if(element
instanceof TaxonRelationship
){
51 Taxon relatedTaxon
= getRelatedTaxon((TaxonRelationship
) element
, editor
.getTaxon());
54 EditorUtil
.openTaxonBase(relatedTaxon
.getUuid());
55 } catch (PartInitException e
) {
56 MessagingUtils
.messageDialog("Could not open taxon", getClass(),
57 String
.format("Could not open the taxon: %s" ,relatedTaxon
), e
);
67 private Taxon
getRelatedTaxon(TaxonRelationship relationship
, Taxon taxon
){
68 if (relationship
.getFromTaxon().equals(taxon
)){
69 return relationship
.getToTaxon();
71 else if(relationship
.getToTaxon().equals(taxon
)){
72 return relationship
.getFromTaxon();