public class OpenDerivateViewHandler extends AbstractHandler {
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if(currentSelection instanceof IStructuredSelection){
- Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
- Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
- while(selectionIterator.hasNext()){
- Object object = selectionIterator.next();
- if(object instanceof SpecimenOrObservationBase<?>){
- selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
- }
- else if(object instanceof IndividualsAssociation){
- SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
- if(specimen!=null){
- selectedElementUUIDs.add(specimen.getUuid());
+ Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
+ //check if parameter is set
+ Object parameter = event.getObjectParameterForExecution("eu.etaxonomy.taxeditor.specimenUuidParameter");
+ if(parameter instanceof UUID){
+ selectedElementUUIDs.add((UUID) parameter);
+ }
+ else{
+ //if not, try with current selection
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ if(currentSelection instanceof IStructuredSelection){
+ Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
+ while(selectionIterator.hasNext()){
+ Object object = selectionIterator.next();
+ if(object instanceof SpecimenOrObservationBase<?>){
+ selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
+ }
+ else if(object instanceof IndividualsAssociation){
+ SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
+ if(specimen!=null){
+ selectedElementUUIDs.add(specimen.getUuid());
+ }
}
}
}
- if(!selectedElementUUIDs.isEmpty()){
- DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
- try {
- EditorUtil.open(input);
- } catch (PartInitException e) {
- MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
- } catch (NullPointerException npe){
- MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
- }
- }
- else{
- MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
+ }
+ if(!selectedElementUUIDs.isEmpty()){
+ DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
+ try {
+ EditorUtil.open(input);
+ } catch (PartInitException e) {
+ MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
+ } catch (NullPointerException npe){
+ MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
}
}
+ else{
+ MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
+ }
return null;
}