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
>();
28 //check if parameter is set
30 parameter
= event
.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
31 } catch (ExecutionException e
) {
34 if(parameter
instanceof UUID
){
35 selectedElementUUIDs
.add((UUID
) parameter
);
38 //if not, try with current selection
39 ISelection currentSelection
= HandlerUtil
.getCurrentSelection(event
);
40 if(currentSelection
instanceof IStructuredSelection
){
41 Iterator
<?
> selectionIterator
= ((IStructuredSelection
) currentSelection
).iterator();
42 while(selectionIterator
.hasNext()){
43 Object object
= selectionIterator
.next();
44 if(object
instanceof SpecimenOrObservationBase
<?
>){
45 selectedElementUUIDs
.add(((SpecimenOrObservationBase
<?
>) object
).getUuid());
47 else if(object
instanceof IndividualsAssociation
){
48 SpecimenOrObservationBase specimen
= ((IndividualsAssociation
) object
).getAssociatedSpecimenOrObservation();
50 selectedElementUUIDs
.add(specimen
.getUuid());
56 if(!selectedElementUUIDs
.isEmpty()){
57 DerivateViewEditorInput input
= new DerivateViewEditorInput(selectedElementUUIDs
);
59 EditorUtil
.open(input
);
60 } catch (PartInitException e
) {
61 MessagingUtils
.error(OpenDerivateViewHandler
.class, "Could not open Derivative Editor", e
);
62 } catch (NullPointerException npe
){
63 MessagingUtils
.messageDialog("Failed to open Editor", OpenDerivateViewHandler
.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe
);
67 MessagingUtils
.informationDialog("Empty selection", "No Specimen selected.");