1 package eu
.etaxonomy
.taxeditor
.editor
.handler
;
3 import java
.util
.HashSet
;
4 import java
.util
.Iterator
;
8 import org
.eclipse
.core
.commands
.AbstractHandler
;
9 import org
.eclipse
.core
.commands
.ExecutionEvent
;
10 import org
.eclipse
.core
.commands
.ExecutionException
;
11 import org
.eclipse
.jface
.viewers
.ISelection
;
12 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
13 import org
.eclipse
.ui
.PartInitException
;
14 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
16 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
17 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
18 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
19 import eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.DerivateViewEditorInput
;
20 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
22 public class OpenDerivateViewHandler
extends AbstractHandler
{
25 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
26 Set
<UUID
> selectedElementUUIDs
= new HashSet
<UUID
>();
27 //check if parameter is set
28 Object parameter
= event
.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
29 if(parameter
instanceof UUID
){
30 selectedElementUUIDs
.add((UUID
) parameter
);
33 //if not, try with current selection
34 ISelection currentSelection
= HandlerUtil
.getCurrentSelection(event
);
35 if(currentSelection
instanceof IStructuredSelection
){
36 Iterator
<?
> selectionIterator
= ((IStructuredSelection
) currentSelection
).iterator();
37 while(selectionIterator
.hasNext()){
38 Object object
= selectionIterator
.next();
39 if(object
instanceof SpecimenOrObservationBase
<?
>){
40 selectedElementUUIDs
.add(((SpecimenOrObservationBase
<?
>) object
).getUuid());
42 else if(object
instanceof IndividualsAssociation
){
43 SpecimenOrObservationBase specimen
= ((IndividualsAssociation
) object
).getAssociatedSpecimenOrObservation();
45 selectedElementUUIDs
.add(specimen
.getUuid());
51 if(!selectedElementUUIDs
.isEmpty()){
52 DerivateViewEditorInput input
= new DerivateViewEditorInput(selectedElementUUIDs
);
54 EditorUtil
.open(input
);
55 } catch (PartInitException e
) {
56 MessagingUtils
.error(OpenDerivateViewHandler
.class, "Could not open Derivative Editor", e
);
57 } catch (NullPointerException npe
){
58 MessagingUtils
.messageDialog("Failed to open Editor", OpenDerivateViewHandler
.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe
);
62 MessagingUtils
.informationDialog("Empty selection", "No Specimen selected.");