3 * Copyright (C) 2014 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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.handler
;
12 import java
.util
.HashSet
;
13 import java
.util
.Iterator
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.eclipse
.core
.commands
.AbstractHandler
;
19 import org
.eclipse
.core
.commands
.ExecutionEvent
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
30 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
31 import eu
.etaxonomy
.taxeditor
.editor
.handler
.OpenDerivateViewHandler
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateViewEditorInput
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 public class OpenDerivateEditorForTaxonHandler
extends AbstractHandler
{
44 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
48 ISelection currentSelection
= HandlerUtil
.getCurrentSelection(event
);
49 if(currentSelection
instanceof IStructuredSelection
){
50 Iterator
<?
> selectionIterator
= ((IStructuredSelection
) currentSelection
).iterator();
51 Set
<UUID
> derivateUuids
= new HashSet
<UUID
>();
52 while(selectionIterator
.hasNext()){
53 Object object
= selectionIterator
.next();
54 if(object
instanceof TaxonNode
){
55 TaxonNode node
= (TaxonNode
)object
;
56 Taxon taxon
= node
.getTaxon();
57 List
<SpecimenOrObservationBase
> listByAssociatedTaxon
= CdmStore
.getService(IOccurrenceService
.class).listByAssociatedTaxon(null, null, taxon
, null, null, null, null, null);
58 for (SpecimenOrObservationBase specimenOrObservationBase
: listByAssociatedTaxon
) {
59 derivateUuids
.add(specimenOrObservationBase
.getUuid());
63 if(derivateUuids
.isEmpty()){
64 MessagingUtils
.warningDialog("Could not open Derivate Editor", this, "No Derivates found");
67 DerivateViewEditorInput input
= new DerivateViewEditorInput(derivateUuids
);
69 EditorUtil
.open(input
);
70 } catch (PartInitException e
) {
71 MessagingUtils
.error(OpenDerivateViewHandler
.class, "Could not open Derivate Editor", e
);
72 } catch (NullPointerException npe
){
73 MessagingUtils
.messageDialog("Failed to open Editor", OpenDerivateViewHandler
.class, "Could not open Derivate Editor. The derivate hierarchy is corrupted!", npe
);