Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 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 java.util.Set;
13

    
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.operations.AbstractOperation;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19

    
20
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
21
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
22
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
23
import eu.etaxonomy.cdm.api.service.UpdateResult;
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25

    
26
/**
27
 * @author cmathew
28
 * @date 16 Jun 2015
29
 *
30
 */
31
public abstract class RemotingCdmOperation extends AbstractOperation {
32

    
33
    private final Object source;
34
    private final Action action;
35
    private final boolean async;
36
    protected Class entityType;
37

    
38
    public RemotingCdmOperation(String label, Action action, Object source, boolean async) {
39
        super(label);
40
        this.source = source;
41
        this.action = action;
42
        this.async = async;
43
    }
44

    
45
    /* (non-Javadoc)
46
     * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
47
     */
48
    @Override
49
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
50

    
51
       boolean success = doExecute(monitor, info);
52
       postExecute(success);
53
       return onComplete(success);
54
    }
55

    
56
    protected abstract boolean doExecute(IProgressMonitor monitor, IAdaptable info);
57

    
58
    protected void postExecute(boolean success) {}
59

    
60
    protected abstract IStatus onComplete(boolean success);
61

    
62
    protected void fireDataChangeEvent(Set<CdmBase> changedObjects) {
63
        if(changedObjects != null && !changedObjects.isEmpty()) {
64
            CdmApplicationState.getCurrentDataChangeService().fireChangeEvent(new CdmChangeEvent(action, changedObjects, source.getClass()), async);
65
        }
66
    }
67

    
68
    protected void fireDataChangeEvent(UpdateResult updateResult) {
69
        Set<CdmBase> updatedObjects = updateResult.getUpdatedObjects();
70
        CdmApplicationState.getCurrentDataChangeService()
71
            .fireChangeEvent(new CdmChangeEvent(action, updatedObjects, source.getClass(), entityType), async);
72
    }
73

    
74
    protected void fireDataChangeEvent(CdmBase cdmBase) {
75
        if(cdmBase != null) {
76
            CdmApplicationState.getCurrentDataChangeService().fireChangeEvent(new CdmChangeEvent(action, cdmBase, source.getClass()), async);
77
        }
78
    }
79

    
80
    /* (non-Javadoc)
81
     * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82
     */
83
    @Override
84
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
85
        // TODO Auto-generated method stub
86
        return null;
87
    }
88

    
89
    /* (non-Javadoc)
90
     * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91
     */
92
    @Override
93
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
94
        // TODO Auto-generated method stub
95
        return null;
96
    }
97

    
98
}
(11-11/12)