Project

General

Profile

« Previous | Next » 

Revision 34014ada

Added by Patrick Plitzner over 8 years ago

Open a newly created specimen in specimen editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/OpenDerivateViewHandler.java
21 21

  
22 22
public class OpenDerivateViewHandler extends AbstractHandler {
23 23

  
24
    /* (non-Javadoc)
25
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
26
     */
27 24
    @Override
28 25
    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());
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);
31
        }
32
        else{
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());
41
                    }
42
                    else if(object instanceof IndividualsAssociation){
43
                        SpecimenOrObservationBase specimen = ((IndividualsAssociation) object).getAssociatedSpecimenOrObservation();
44
                        if(specimen!=null){
45
                            selectedElementUUIDs.add(specimen.getUuid());
46
                        }
42 47
                    }
43 48
                }
44 49
            }
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.");
50
        }
51
        if(!selectedElementUUIDs.isEmpty()){
52
            DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
53
            try {
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);
57 59
            }
58 60
        }
61
        else{
62
            MessagingUtils.informationDialog("Empty selection", "No Specimen selected.");
63
        }
59 64
        return null;
60 65
    }
61 66

  

Also available in: Unified diff