1 |
6c610cc5
|
Cherian Mathew
|
/**
|
2 |
|
|
* Copyright (C) 2015 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 |
ae7e2680
|
Cherian Mathew
|
import java.util.Set;
|
12 |
|
|
|
13 |
6c610cc5
|
Cherian Mathew
|
import org.eclipse.core.commands.ExecutionException;
|
14 |
|
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
15 |
|
|
import org.eclipse.core.runtime.IAdaptable;
|
16 |
|
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17 |
|
|
import org.eclipse.core.runtime.IStatus;
|
18 |
|
|
|
19 |
ae7e2680
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
20 |
|
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
|
21 |
|
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
22 |
|
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
23 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24 |
|
|
|
25 |
6c610cc5
|
Cherian Mathew
|
/**
|
26 |
|
|
* @author cmathew
|
27 |
|
|
* @date 16 Jun 2015
|
28 |
|
|
*
|
29 |
|
|
*/
|
30 |
|
|
public abstract class RemotingCdmOperation extends AbstractOperation {
|
31 |
|
|
|
32 |
ae7e2680
|
Cherian Mathew
|
private final Object source;
|
33 |
|
|
private final Action action;
|
34 |
|
|
private final boolean async;
|
35 |
c69c2dcd
|
Cherian Mathew
|
protected Class entityType;
|
36 |
ae7e2680
|
Cherian Mathew
|
|
37 |
|
|
public RemotingCdmOperation(String label, Action action, Object source, boolean async) {
|
38 |
6c610cc5
|
Cherian Mathew
|
super(label);
|
39 |
ae7e2680
|
Cherian Mathew
|
this.source = source;
|
40 |
|
|
this.action = action;
|
41 |
|
|
this.async = async;
|
42 |
6c610cc5
|
Cherian Mathew
|
}
|
43 |
|
|
|
44 |
|
|
/* (non-Javadoc)
|
45 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
46 |
|
|
*/
|
47 |
|
|
@Override
|
48 |
|
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
49 |
|
|
|
50 |
|
|
boolean success = doExecute(monitor, info);
|
51 |
|
|
postExecute(success);
|
52 |
|
|
return onComplete(success);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
ae7e2680
|
Cherian Mathew
|
protected abstract boolean doExecute(IProgressMonitor monitor, IAdaptable info);
|
56 |
|
|
|
57 |
|
|
protected void postExecute(boolean success) {}
|
58 |
6c610cc5
|
Cherian Mathew
|
|
59 |
ae7e2680
|
Cherian Mathew
|
protected abstract IStatus onComplete(boolean success);
|
60 |
6c610cc5
|
Cherian Mathew
|
|
61 |
6c511765
|
Cherian Mathew
|
protected void fireDataChangeEvent(Set<CdmBase> changedObjects) {
|
62 |
ae7e2680
|
Cherian Mathew
|
if(changedObjects != null && !changedObjects.isEmpty()) {
|
63 |
|
|
CdmApplicationState.getCurrentDataChangeService().fireChangeEvent(new CdmChangeEvent(action, changedObjects, source.getClass()), async);
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
protected void fireDataChangeEvent(UpdateResult updateResult) {
|
68 |
|
|
Set<CdmBase> updatedObjects = updateResult.getUpdatedObjects();
|
69 |
c69c2dcd
|
Cherian Mathew
|
CdmApplicationState.getCurrentDataChangeService()
|
70 |
|
|
.fireChangeEvent(new CdmChangeEvent(action, updatedObjects, source.getClass(), entityType), async);
|
71 |
ae7e2680
|
Cherian Mathew
|
}
|
72 |
6c610cc5
|
Cherian Mathew
|
|
73 |
9bc47800
|
Cherian Mathew
|
protected void fireDataChangeEvent(CdmBase cdmBase) {
|
74 |
|
|
if(cdmBase != null) {
|
75 |
|
|
CdmApplicationState.getCurrentDataChangeService().fireChangeEvent(new CdmChangeEvent(action, cdmBase, source.getClass()), async);
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
6c610cc5
|
Cherian Mathew
|
/* (non-Javadoc)
|
80 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
81 |
|
|
*/
|
82 |
|
|
@Override
|
83 |
|
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
84 |
|
|
// TODO Auto-generated method stub
|
85 |
|
|
return null;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/* (non-Javadoc)
|
89 |
|
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
90 |
|
|
*/
|
91 |
|
|
@Override
|
92 |
|
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
93 |
|
|
// TODO Auto-generated method stub
|
94 |
|
|
return null;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
}
|