Project

General

Profile

Download (2.92 KB) Statistics
| Branch: | Tag: | Revision:
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.termtree.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.persistence.dto.TermNodeDto;
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
public class AddFeatureOperation extends AbstractPostOperation<Feature> {
36

    
37
    private UUID nodeUuid;
38

    
39
    private int position;
40
    private UUID featureUuid;
41

    
42
    public AddFeatureOperation(UUID featureUuid, TermNodeDto node,
43
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled<Feature> cdmEntitySessionEnabled) {
44
        this(featureUuid, node.getUuid(), 0, postOperationEnabled, cdmEntitySessionEnabled);
45
    }
46
    public AddFeatureOperation(UUID featureUuid, UUID nodeUuid, int position,
47
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled<Feature> cdmEntitySessionEnabled) {
48
        super("Add Feature", StoreUtil.getUndoContext(), null, postOperationEnabled, cdmEntitySessionEnabled);
49

    
50
        this.nodeUuid = nodeUuid;
51
        this.featureUuid = featureUuid;
52
        this.position = position;
53
    }
54

    
55
    @Override
56
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
57
        UpdateResult updateResult = CdmStore.getService(ITermNodeService.class).addChildNode(nodeUuid, featureUuid, position);
58
        if(updateResult.isError()){
59
            Exception exception = StoreUtil.mergeUpdateResultExceptions(updateResult);
60
            MessagingUtils.errorDialog("Error during operation", this, "Could not add term", TaxeditorStorePlugin.PLUGIN_ID, exception, false);
61
            return Status.CANCEL_STATUS;
62
        }
63
        return postExecute(updateResult.getCdmEntity());
64
    }
65

    
66
    @Override
67
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
68
        return null;
69
    }
70

    
71
    @Override
72
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
73
        return null;
74
    }
75
}
(1-1/6)