Merge branch 'release/4.6.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
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.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 * @version 1.0
32 */
33 public class DeleteDescriptionElementOperation extends AbstractPostTaxonOperation {
34
35 private final DescriptionElementBase element;
36 private DescriptionBase description = null;
37
38 /**
39 * <p>Constructor for DeleteDescriptionElementOperation.</p>
40 *
41 * @param label a {@link java.lang.String} object.
42 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
43 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
44 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
45 */
46 public DeleteDescriptionElementOperation(String label, IUndoContext undoContext,
47 DescriptionElementBase element, IPostOperationEnabled postOperationEnabled,
48 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
49 super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
50
51 this.element = element;
52 }
53
54 /* (non-Javadoc)
55 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56 */
57 /** {@inheritDoc} */
58 @Override
59 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60 throws ExecutionException {
61
62 description = element.getInDescription();
63
64 monitor.worked(20);
65
66 // Remove element from description
67 if (description == null) {
68 MessagingUtils.error(this.getClass(), Messages.DeleteDescriptionElementOperation_DESC_NOT_FOUND, null);
69 } else {
70 description.removeElement(element);
71 }
72 monitor.worked(40);
73
74 // Redraw editor if exists
75 return postExecute(description);
76 }
77
78 /* (non-Javadoc)
79 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 */
81 /** {@inheritDoc} */
82 @Override
83 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
84 throws ExecutionException {
85 return execute(monitor, info);
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 /** {@inheritDoc} */
92 @Override
93 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95
96 description.addElement(element);
97
98 return postExecute(element);
99 }
100 }