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.Feature;
|
26
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
27
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
28
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation;
|
29
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
32
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
33
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
34
|
|
35
|
/**
|
36
|
*
|
37
|
* @author pplitzner
|
38
|
* @date 15.08.2017
|
39
|
*
|
40
|
*/
|
41
|
public class CreateDescriptionElementHandlerE4 {
|
42
|
|
43
|
@Execute
|
44
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
45
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MHandledMenuItem menuItem) {
|
46
|
|
47
|
String commandId = menuItem.getCommand().getElementId();
|
48
|
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".feature.uuid");
|
49
|
Feature feature = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), Feature.class);
|
50
|
|
51
|
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
|
52
|
|
53
|
if (description != null) {
|
54
|
AbstractPostOperation operation = null;
|
55
|
// TODO use undo context specific to editor
|
56
|
operation = operationCreationInstance(menuItem.getLocalizedLabel(), feature, description, factualDataPart);
|
57
|
AbstractUtility.executeOperation(operation);
|
58
|
} else {
|
59
|
MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$
|
60
|
}
|
61
|
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Added to make the Class more generic and limit the amount of code changes required
|
66
|
* @param label
|
67
|
* @param event
|
68
|
* @param taxon
|
69
|
* @param description
|
70
|
* @param postOperationEnabled
|
71
|
* @return
|
72
|
*/
|
73
|
protected AbstractPostOperation operationCreationInstance(String label, Feature feature, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
|
74
|
return new CreateDescriptionElementOperation(label, EditorUtil.getUndoContext(), description, feature, postOperationEnabled);
|
75
|
}
|
76
|
|
77
|
}
|