Project

General

Profile

Download (4.65 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2013 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.taxeditor.operation;
11

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

    
17
import eu.etaxonomy.cdm.model.common.CdmBase;
18
import eu.etaxonomy.cdm.model.common.ICdmBase;
19
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
20

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

    
28

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

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

    
39
    private ICdmEntitySessionEnabled cdmEntitySessionEnabled;
40

    
41

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

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

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

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

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

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

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

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

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

    
138
}
(3-3/12)