1
|
/**
|
2
|
* Copyright (C) 2018 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.featuretree.e4.operation;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.eclipse.core.commands.ExecutionException;
|
14
|
import org.eclipse.core.runtime.IAdaptable;
|
15
|
import org.eclipse.core.runtime.IProgressMonitor;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.core.runtime.Status;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.ITermNodeService;
|
20
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.model.term.TermNode;
|
23
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
24
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
25
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
26
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
29
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
30
|
|
31
|
/**
|
32
|
* @author pplitzner
|
33
|
* @since Apr 30, 2018
|
34
|
*
|
35
|
*/
|
36
|
public class AddFeatureOperation extends AbstractPostOperation<Feature> {
|
37
|
|
38
|
private TermNode<Feature> node;
|
39
|
private int position;
|
40
|
private UUID featureUuid;
|
41
|
|
42
|
public AddFeatureOperation(UUID featureUuid, TermNode<Feature> node,
|
43
|
IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
44
|
this(featureUuid, node, 0, postOperationEnabled, cdmEntitySessionEnabled);
|
45
|
}
|
46
|
public AddFeatureOperation(UUID featureUuid, TermNode<Feature> node, int position,
|
47
|
IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
48
|
super("Add Feature", StoreUtil.getUndoContext(), null, postOperationEnabled, cdmEntitySessionEnabled);
|
49
|
this.node = node;
|
50
|
this.featureUuid = featureUuid;
|
51
|
this.position = position;
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
56
|
UpdateResult updateResult = CdmStore.getService(ITermNodeService.class).addChildNode(node.getUuid(), featureUuid, position);
|
57
|
if(updateResult.isError()){
|
58
|
Exception exception = StoreUtil.mergeUpdateResultExceptions(updateResult);
|
59
|
MessagingUtils.errorDialog("Error during operation", this, "Could not add term", TaxeditorStorePlugin.PLUGIN_ID, exception, false);
|
60
|
return Status.CANCEL_STATUS;
|
61
|
}
|
62
|
return postExecute(updateResult.getCdmEntity());
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
67
|
return null;
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
72
|
return null;
|
73
|
}
|
74
|
|
75
|
}
|