1
|
/**
|
2
|
* Copyright (C) 2011 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler;
|
10
|
|
11
|
import javax.inject.Named;
|
12
|
|
13
|
import org.eclipse.e4.core.di.annotations.Execute;
|
14
|
import org.eclipse.e4.ui.di.UISynchronize;
|
15
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
16
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
|
17
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
18
|
import org.eclipse.jface.viewers.TreeNode;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
23
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
24
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
25
|
//import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateNamedescriptionOperation;
|
26
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation;
|
27
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
|
28
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
29
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
30
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
* @author pplitzner
|
35
|
* @date 15.08.2017
|
36
|
*
|
37
|
*/
|
38
|
public class CreateDescriptionHandlerE4 {
|
39
|
|
40
|
@Execute
|
41
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MMenuItem menuItem,
|
42
|
UISynchronize sync) {
|
43
|
|
44
|
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
|
45
|
|
46
|
AbstractPostOperation<?> operation;
|
47
|
Object viewerInput = factualDataPart.getViewer().getInput();
|
48
|
if(viewerInput instanceof TreeNode){
|
49
|
viewerInput = ((TreeNode) viewerInput).getValue();
|
50
|
}
|
51
|
if(viewerInput instanceof SpecimenOrObservationBase<?>){
|
52
|
operation = new CreateSpecimenDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>) viewerInput, factualDataPart);
|
53
|
AbstractUtility.executeOperation(operation, sync);
|
54
|
}
|
55
|
if(viewerInput instanceof TaxonBase){
|
56
|
operation = createTaxonOperation(menuItem.getLocalizedLabel(), (Taxon) viewerInput, factualDataPart);
|
57
|
if(operation!=null){
|
58
|
AbstractUtility.executeOperation(operation, sync);
|
59
|
}
|
60
|
}
|
61
|
// if(viewerInput instanceof TaxonName){
|
62
|
// operation = new CreateNamedescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (TaxonName) viewerInput, factualDataPart);
|
63
|
// if(operation!=null){
|
64
|
// AbstractUtility.executeOperation(operation, sync);
|
65
|
// }
|
66
|
// }
|
67
|
}
|
68
|
|
69
|
protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
|
70
|
return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, null, postOperationEnabled);
|
71
|
}
|
72
|
|
73
|
}
|