Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / operation / DeleteTaxonDescriptionOperation.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.api.service.IDescriptionService;
19 import eu.etaxonomy.cdm.model.description.TaxonDescription;
20 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
21 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 * <p>DeleteTaxonDescriptionOperation class.</p>
27 *
28 * @author p.ciardelli
29 * @author n.hoffmann
30 * @created 05.02.2009
31 * @version 1.0
32 */
33 public class DeleteTaxonDescriptionOperation extends AbstractPostTaxonOperation {
34
35 private final TaxonDescription description;
36
37 /**
38 * <p>Constructor for DeleteTaxonDescriptionOperation.</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 description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
43 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
44 */
45 public DeleteTaxonDescriptionOperation(String label,
46 IUndoContext undoContext,
47 TaxonDescription description,
48 IPostOperationEnabled postOperationEnabled,
49 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
50 super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
51
52 this.description = description;
53 element = description.getTaxon();
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 */
59 /** {@inheritDoc} */
60 @Override
61 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62 throws ExecutionException {
63
64 monitor.worked(20);
65 if (description != null){
66 CdmStore.getService(IDescriptionService.class).deleteDescription(description.getUuid());
67 return postExecute(description);
68 }
69 return null;
70
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 */
76 /** {@inheritDoc} */
77 @Override
78 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
79 throws ExecutionException {
80 return execute(monitor, info);
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 /** {@inheritDoc} */
87 @Override
88 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
89 throws ExecutionException {
90
91 element.addDescription(description);
92
93 return postExecute(null);
94 }
95 }