1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import javax.inject.Named;
|
15
|
|
16
|
import org.eclipse.e4.core.di.annotations.Execute;
|
17
|
import org.eclipse.e4.core.di.annotations.Optional;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
20
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
23
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
24
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
25
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
26
|
import eu.etaxonomy.cdm.model.description.Feature;
|
27
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
28
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
29
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation;
|
30
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
31
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
32
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
33
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
34
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
*
|
39
|
* @author pplitzner
|
40
|
* @date 15.08.2017
|
41
|
*
|
42
|
*/
|
43
|
public class CreateDescriptionElementHandlerE4 {
|
44
|
|
45
|
@Execute
|
46
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
47
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object object, MHandledMenuItem menuItem) {
|
48
|
|
49
|
String commandId = menuItem.getCommand().getElementId();
|
50
|
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".feature.uuid");
|
51
|
Feature feature = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), Feature.class);
|
52
|
|
53
|
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
|
54
|
|
55
|
DescriptionBase description = null;
|
56
|
if(object instanceof FeatureNodeContainer){
|
57
|
description = ((FeatureNodeContainer) object).getDescription();
|
58
|
}
|
59
|
else if(object instanceof DescriptionElementBase){
|
60
|
DescriptionElementBase elementBase = HibernateProxyHelper.deproxy(object, DescriptionElementBase.class);
|
61
|
description = elementBase.getInDescription();
|
62
|
}
|
63
|
else if (object instanceof DescriptionBase) {
|
64
|
description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
|
65
|
} else {
|
66
|
MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$
|
67
|
return;
|
68
|
}
|
69
|
AbstractPostOperation operation = operationCreationInstance(menuItem.getLocalizedLabel(), feature, description, factualDataPart);
|
70
|
// TODO use undo context specific to editor
|
71
|
AbstractUtility.executeOperation(operation);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Added to make the Class more generic and limit the amount of code changes required
|
76
|
* @param label
|
77
|
* @param event
|
78
|
* @param taxon
|
79
|
* @param description
|
80
|
* @param postOperationEnabled
|
81
|
* @return
|
82
|
*/
|
83
|
protected AbstractPostOperation operationCreationInstance(String label, Feature feature, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
|
84
|
return new CreateDescriptionElementOperation(label, EditorUtil.getUndoContext(), description, feature, postOperationEnabled);
|
85
|
}
|
86
|
|
87
|
}
|