Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / RemotingCdmOperation.java
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
37 public RemotingCdmOperation(String label, Action action, Object source, boolean async) {
38 super(label);
39 this.source = source;
40 this.action = action;
41 this.async = async;
42 }
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 protected abstract boolean doExecute(IProgressMonitor monitor, IAdaptable info);
56
57 protected void postExecute(boolean success) {}
58
59 protected abstract IStatus onComplete(boolean success);
60
61 protected void fireDataChangeEvent(Set<CdmBase> changedObjects) {
62 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 if(updatedObjects != null && !updatedObjects.isEmpty()) {
70 CdmApplicationState.getCurrentDataChangeService().fireChangeEvent(new CdmChangeEvent(action, updatedObjects, source.getClass()), async);
71 }
72 }
73
74 /* (non-Javadoc)
75 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76 */
77 @Override
78 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
79 // TODO Auto-generated method stub
80 return null;
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 */
86 @Override
87 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
88 // TODO Auto-generated method stub
89 return null;
90 }
91
92 }