1
|
package eu.etaxonomy.taxeditor.editor.handler;
|
2
|
|
3
|
import java.util.HashSet;
|
4
|
import java.util.Iterator;
|
5
|
import java.util.Set;
|
6
|
import java.util.UUID;
|
7
|
|
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;
|
15
|
|
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;
|
21
|
|
22
|
public class OpenDerivateViewHandler extends AbstractHandler {
|
23
|
|
24
|
/* (non-Javadoc)
|
25
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
26
|
*/
|
27
|
@Override
|
28
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
29
|
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
|
30
|
if(currentSelection instanceof IStructuredSelection){
|
31
|
Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
|
32
|
Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
|
33
|
while(selectionIterator.hasNext()){
|
34
|
Object object = selectionIterator.next();
|
35
|
if(object instanceof SpecimenOrObservationBase<?>){
|
36
|
selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
|
37
|
}
|
38
|
else if(object instanceof IndividualsAssociation){
|
39
|
SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
|
40
|
if(specimen!=null){
|
41
|
selectedElementUUIDs.add(specimen.getUuid());
|
42
|
}
|
43
|
}
|
44
|
}
|
45
|
if(!selectedElementUUIDs.isEmpty()){
|
46
|
DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
|
47
|
try {
|
48
|
EditorUtil.open(input);
|
49
|
} catch (PartInitException e) {
|
50
|
MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivative Editor", e);
|
51
|
} catch (NullPointerException npe){
|
52
|
MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivative Editor. The derivate hierarchy is corrupted!", npe);
|
53
|
}
|
54
|
}
|
55
|
else{
|
56
|
MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
|
57
|
}
|
58
|
}
|
59
|
return null;
|
60
|
}
|
61
|
|
62
|
}
|