Project

General

Profile

Download (3.75 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2013 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.operation;
10

    
11
import org.eclipse.core.commands.operations.AbstractOperation;
12
import org.eclipse.core.commands.operations.IUndoContext;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.Status;
15

    
16
import eu.etaxonomy.cdm.model.common.ICdmBase;
17
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
18

    
19
/**
20
 * @author pplitzner
21
 * @date 03.12.2013
22
 *
23
 */
24
public abstract class AbstractPostOperation<T extends ICdmBase> extends AbstractOperation {
25

    
26

    
27
    /**
28
     * A reference to the {@link ICdmBase} element the concrete operation is working on
29
     */
30
    protected T element;
31

    
32
    /**
33
     *
34
     */
35
    protected IPostOperationEnabled postOperationEnabled;
36

    
37
    private ICdmEntitySessionEnabled cdmEntitySessionEnabled;
38

    
39

    
40
    /**
41
     * @param label
42
     * @param element
43
     * @param postOperationEnabled
44
     */
45
    public AbstractPostOperation(String label, IUndoContext undoContext,
46
            T element, IPostOperationEnabled postOperationEnabled) {
47
        this(label, undoContext, element, postOperationEnabled, null);
48
    }
49

    
50
    public AbstractPostOperation(String label, IUndoContext undoContext,
51
            T element, IPostOperationEnabled postOperationEnabled,
52
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
53
        super(label);
54
        addContext(undoContext);
55
        this.element = element;
56
        this.postOperationEnabled = postOperationEnabled;
57
        this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
58
    }
59

    
60
    /**
61
     * This method will try to call the post operation on a possibly registered
62
     * IPostOperationEnabled implementor. Objects that were affected by the operation
63
     * may be passed to the registered IPostOperationEnabled implementor.
64
     *
65
     * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
66
     * @return a {@link org.eclipse.core.runtime.IStatus} object.
67
     */
68
    protected IStatus postExecute(Object objectAffectedByOperation) {
69

    
70
        if(postOperationEnabled != null){
71
            return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
72
        }
73
        return Status.OK_STATUS;
74
    }
75

    
76
    /**
77
     * <p>Getter for the field <code>postOperationEnabled</code>.</p>
78
     *
79
     * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
80
     */
81
    public IPostOperationEnabled getPostOperationEnabled() {
82
        return postOperationEnabled;
83
    }
84

    
85
//    protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
86
//        Set<CdmBase> affectedObjects;
87
//        if(updateResult == null) {
88
//            affectedObjects = new HashSet<CdmBase>();
89
//        } else {
90
//            affectedObjects = updateResult.getUpdatedObjects();
91
//        }
92
//
93
//        if(cdmEntitySessionEnabled != null) {
94
//            cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
95
//        }
96
//        return Status.OK_STATUS;
97
//    }
98
//
99
//    protected IStatus updateSession(UUID uuid) {
100
//
101
//        if(cdmEntitySessionEnabled != null) {
102
//            CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
103
//            cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
104
//        }
105
//        return Status.OK_STATUS;
106
//    }
107

    
108
    public ICdmEntitySessionEnabled getCdmEntitySessionEnabled() {
109
        return cdmEntitySessionEnabled;
110
    }
111

    
112
}
(3-3/11)