Project

General

Profile

Download (2.15 KB) Statistics
| Branch: | Tag: | Revision:
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.occurrence.SpecimenOrObservationBase;
17
import eu.etaxonomy.taxeditor.editor.EditorUtil;
18
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
19
import eu.etaxonomy.taxeditor.model.MessagingUtils;
20

    
21
public class OpenDerivateViewHandler extends AbstractHandler {
22

    
23
    /* (non-Javadoc)
24
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
25
     */
26
    @Override
27
    public Object execute(ExecutionEvent event) throws ExecutionException {
28
        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
29
        if(currentSelection instanceof IStructuredSelection){
30
            Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
31
            Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
32
            while(selectionIterator.hasNext()){
33
                Object object = selectionIterator.next();
34
                if(object instanceof SpecimenOrObservationBase<?>){
35
                    selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
36
                }
37
            }
38
            DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
39
            try {
40
                EditorUtil.open(input);
41
            } catch (PartInitException e) {
42
                MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivate Editor", e);
43
            } catch (NullPointerException npe){
44
                MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivate Editor. The derivate hierarchy is corrupted!", npe);
45
            }
46
        }
47
        return null;
48
    }
49

    
50
}
(3-3/6)