AT: committing latest changes to the Tax Editor after a first round of Code review
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / operation / DeleteUseRecordOperation.java
1 package eu.etaxonomy.taxeditor.editor.view.uses.operation;
2
3
4 import org.eclipse.core.commands.ExecutionException;
5 import org.eclipse.core.commands.operations.IUndoContext;
6 import org.eclipse.core.runtime.IAdaptable;
7 import org.eclipse.core.runtime.IProgressMonitor;
8 import org.eclipse.core.runtime.IStatus;
9
10 import eu.etaxonomy.cdm.model.description.DescriptionBase;
11 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
12 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
13 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
14 import eu.etaxonomy.taxeditor.store.StoreUtil;
15
16 /**
17 * The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
18 *
19 * @author a.theys
20 * @created mar 13, 2012
21 * @version 1.0
22 */
23 public class DeleteUseRecordOperation extends AbstractPostOperation {
24 private DescriptionElementBase element;
25 private DescriptionBase description = null;
26
27
28 public DeleteUseRecordOperation(String label, IUndoContext undoContext,
29 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
30 super(label, undoContext, postOperationEnabled);
31
32 this.element = element;
33 }
34
35
36 @Override
37 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
38 throws ExecutionException {
39 description = element.getInDescription();
40
41 monitor.worked(20);
42
43 // Remove element from description
44 if (description == null) {
45 StoreUtil.error(this.getClass(), "Couldn't find element's description!", null);
46 } else {
47 description.removeElement(element);
48 }
49 monitor.worked(40);
50
51 // Redraw editor if exists
52 return postExecute(null);
53 }
54
55
56 @Override
57 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
58 throws ExecutionException {
59 return execute(monitor, info);
60 }
61
62
63 @Override
64 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
65 throws ExecutionException {
66
67 description.addElement(element);
68
69 return postExecute(element);
70 }
71
72 }