Project

General

Profile

Download (4.64 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.CdmBase;
17
import eu.etaxonomy.cdm.model.common.ICdmBase;
18
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
19

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

    
27

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

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

    
38
    private ICdmEntitySessionEnabled cdmEntitySessionEnabled;
39

    
40

    
41
    /**
42
     * <p>Constructor for AbstractPostOperation.</p>
43
     *
44
     * @param label a {@link java.lang.String} object.
45
     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
46
     */
47
    protected AbstractPostOperation(String label, IUndoContext undoContext) {
48
        super(label);
49
        addContext(undoContext);
50
    }
51

    
52
    /**
53
     * <p>Constructor for AbstractPostOperation.</p>
54
     *
55
     * @param label a {@link java.lang.String} object.
56
     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57
     * @param element a {@link ICdmBase} object on which this operation is working.
58
     */
59
    public AbstractPostOperation(String label, IUndoContext undoContext, T element) {
60
        this(label, undoContext);
61
        this.element = element;
62
    }
63

    
64
    /**
65
     * @param label
66
     * @param element
67
     * @param postOperationEnabled
68
     */
69
    public AbstractPostOperation(String label, IUndoContext undoContext,
70
            T element, IPostOperationEnabled postOperationEnabled) {
71
        this(label, undoContext);
72
        this.element = element;
73
        this.postOperationEnabled = postOperationEnabled;
74
    }
75

    
76
    public AbstractPostOperation(String label, IUndoContext undoContext,
77
            T element, IPostOperationEnabled postOperationEnabled,
78
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
79
        this(label, undoContext);
80
        this.element = element;
81
        this.postOperationEnabled = postOperationEnabled;
82
        this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
83
    }
84

    
85
    /**
86
     * This method will try to call the post operation on a possibly registered
87
     * IPostOperationEnabled implementor. Objects that were affected by the operation
88
     * may be passed to the registered IPostOperationEnabled implementor.
89
     *
90
     * @param objectAffectedByOperation the affected object. Should be <code>null</code> if not needed
91
     * @return a {@link org.eclipse.core.runtime.IStatus} object.
92
     */
93
    protected IStatus postExecute(CdmBase objectAffectedByOperation) {
94

    
95
        if(postOperationEnabled != null){
96
            return postOperationEnabled.postOperation(objectAffectedByOperation) ? Status.OK_STATUS : Status.CANCEL_STATUS;
97
        }
98
        return Status.OK_STATUS;
99
    }
100

    
101
    /**
102
     * <p>Getter for the field <code>postOperationEnabled</code>.</p>
103
     *
104
     * @return a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
105
     */
106
    public IPostOperationEnabled getPostOperationEnabled() {
107
        return postOperationEnabled;
108
    }
109

    
110
//    protected IStatus updateSession(CdmBase clientObjectAffectedByOperation, UpdateResult updateResult) {
111
//        Set<CdmBase> affectedObjects;
112
//        if(updateResult == null) {
113
//            affectedObjects = new HashSet<CdmBase>();
114
//        } else {
115
//            affectedObjects = updateResult.getUpdatedObjects();
116
//        }
117
//
118
//        if(cdmEntitySessionEnabled != null) {
119
//            cdmEntitySessionEnabled.getCdmEntitySession().update(clientObjectAffectedByOperation, affectedObjects);
120
//        }
121
//        return Status.OK_STATUS;
122
//    }
123
//
124
//    protected IStatus updateSession(UUID uuid) {
125
//
126
//        if(cdmEntitySessionEnabled != null) {
127
//            CdmBase cdmBase = cdmEntitySessionEnabled.getCdmEntitySession().remoteLoad(CdmStore.getService(IService.class),uuid);
128
//            cdmEntitySessionEnabled.getCdmEntitySession().update(null, cdmBase);
129
//        }
130
//        return Status.OK_STATUS;
131
//    }
132

    
133
    public ICdmEntitySessionEnabled getCdmEntitySessionEnabled() {
134
        return cdmEntitySessionEnabled;
135
    }
136

    
137
}
(3-3/12)