Merge branch 'release/5.19.0'
[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 package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
10
11 import org.eclipse.core.commands.ExecutionException;
12 import org.eclipse.core.commands.operations.IUndoContext;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16
17 import eu.etaxonomy.cdm.model.description.DescriptionBase;
18 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
19 import eu.etaxonomy.cdm.model.taxon.Taxon;
20 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
21 import eu.etaxonomy.taxeditor.model.MessagingUtils;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
23 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
25
26 /**
27 * <p>DeleteDescriptionElementOperation class.</p>
28 *
29 * @author p.ciardelli
30 * @created 05.02.2009
31 */
32 public class DeleteDescriptionElementOperation extends AbstractPostTaxonOperation {
33
34 private final DescriptionElementBase element;
35 private DescriptionBase<?> description = null;
36
37 /**
38 * <p>Constructor for DeleteDescriptionElementOperation.</p>
39 *
40 * @param label a {@link java.lang.String} object.
41 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
42 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
43 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
44 */
45 public DeleteDescriptionElementOperation(String label, IUndoContext undoContext,
46 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled,
47 ICdmEntitySessionEnabled<Taxon> cdmEntitySessionEnabled) {
48 super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
49
50 this.element = element;
51 }
52
53 @Override
54 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55 throws ExecutionException {
56
57 description = element.getInDescription();
58
59 monitor.worked(20);
60
61 // Remove element from description
62 if (description == null) {
63 MessagingUtils.error(this.getClass(), Messages.DeleteDescriptionElementOperation_DESC_NOT_FOUND, null);
64 } else {
65 description.removeElement(element);
66 }
67 monitor.worked(40);
68
69 // Redraw editor if exists
70 return postExecute(description);
71 }
72
73 @Override
74 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
75 throws ExecutionException {
76 return execute(monitor, info);
77 }
78
79 @Override
80 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
81 throws ExecutionException {
82
83 description.addElement(element);
84
85 return postExecute(element);
86 }
87 }