merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / operation / DeleteDescriptionElementOperation.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
11
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17
18 import eu.etaxonomy.cdm.model.description.DescriptionBase;
19 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
21 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22 import eu.etaxonomy.taxeditor.store.StoreUtil;
23
24 /**
25 * <p>DeleteDescriptionElementOperation class.</p>
26 *
27 * @author p.ciardelli
28 * @created 05.02.2009
29 * @version 1.0
30 */
31 public class DeleteDescriptionElementOperation extends AbstractPostTaxonOperation {
32
33 private DescriptionElementBase element;
34 private DescriptionBase description = null;
35
36 /**
37 * <p>Constructor for DeleteDescriptionElementOperation.</p>
38 *
39 * @param label a {@link java.lang.String} object.
40 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
41 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
42 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
43 */
44 public DeleteDescriptionElementOperation(String label, IUndoContext undoContext,
45 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
46 super(label, undoContext, postOperationEnabled);
47
48 this.element = element;
49 }
50
51 /* (non-Javadoc)
52 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
53 */
54 /** {@inheritDoc} */
55 @Override
56 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
57 throws ExecutionException {
58
59 description = element.getInDescription();
60
61 monitor.worked(20);
62
63 // Remove element from description
64 if (description == null) {
65 StoreUtil.error(this.getClass(), "Couldn't find element's description!", null);
66 } else {
67 description.removeElement(element);
68 }
69 monitor.worked(40);
70
71 // Redraw editor if exists
72 return postExecute(null);
73 }
74
75 /* (non-Javadoc)
76 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77 */
78 /** {@inheritDoc} */
79 @Override
80 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
81 throws ExecutionException {
82 return execute(monitor, info);
83 }
84
85 /* (non-Javadoc)
86 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
87 */
88 /** {@inheritDoc} */
89 @Override
90 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
91 throws ExecutionException {
92
93 description.addElement(element);
94
95 return postExecute(element);
96 }
97 }