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