1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
|
11
|
|
12
|
import java.util.Collection;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.eclipse.core.commands.AbstractHandler;
|
19
|
import org.eclipse.core.commands.ExecutionEvent;
|
20
|
import org.eclipse.core.commands.ExecutionException;
|
21
|
import org.eclipse.jface.viewers.ISelection;
|
22
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
23
|
import org.eclipse.ui.PartInitException;
|
24
|
import org.eclipse.ui.handlers.HandlerUtil;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
27
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
28
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
31
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
32
|
import eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler;
|
33
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
|
34
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
* @author pplitzner
|
39
|
* @date Nov 25, 2014
|
40
|
*
|
41
|
*/
|
42
|
public class OpenDerivateEditorForTaxonHandler extends AbstractHandler {
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
46
|
*/
|
47
|
@Override
|
48
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
49
|
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
|
50
|
if(currentSelection instanceof IStructuredSelection){
|
51
|
Iterator<?> selectionIterator = ((IStructuredSelection) currentSelection).iterator();
|
52
|
Set<UUID> selectedElementUUIDs = new HashSet<UUID>();
|
53
|
while(selectionIterator.hasNext()){
|
54
|
Object object = selectionIterator.next();
|
55
|
if(object instanceof TaxonNode){
|
56
|
TaxonNode node = (TaxonNode)object;
|
57
|
Taxon taxon = node.getTaxon();
|
58
|
Collection<FieldUnit> associatedFieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon(null, taxon, null, null, null, null, null);
|
59
|
//TODO getSpecimensForTaxon
|
60
|
selectedElementUUIDs.add(((SpecimenOrObservationBase<?>) object).getUuid());
|
61
|
}
|
62
|
}
|
63
|
DerivateViewEditorInput input = new DerivateViewEditorInput(selectedElementUUIDs);
|
64
|
try {
|
65
|
EditorUtil.open(input);
|
66
|
} catch (PartInitException e) {
|
67
|
MessagingUtils.error(OpenDerivateViewHandler.class, "Could not open Derivate Editor", e);
|
68
|
} catch (NullPointerException npe){
|
69
|
MessagingUtils.messageDialog("Failed to open Editor", OpenDerivateViewHandler.class, "Could not open Derivate Editor. The derivate hierarchy is corrupted!", npe);
|
70
|
}
|
71
|
}
|
72
|
return null;
|
73
|
}
|
74
|
|
75
|
}
|