Merge branch 'move-to-luna' 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 java.util.ArrayList;
13 import java.util.List;
14
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.commands.operations.IUndoContext;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.IStatus;
20
21 import eu.etaxonomy.cdm.api.service.IDescriptionService;
22 import eu.etaxonomy.cdm.model.description.TaxonDescription;
23 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27
28 /**
29 * <p>DeleteTaxonDescriptionOperation class.</p>
30 *
31 * @author p.ciardelli
32 * @author n.hoffmann
33 * @created 05.02.2009
34 * @version 1.0
35 */
36 public class DeleteTaxonDescriptionOperation extends AbstractPostTaxonOperation {
37
38 private final TaxonDescription description;
39
40 /**
41 * <p>Constructor for DeleteTaxonDescriptionOperation.</p>
42 *
43 * @param label a {@link java.lang.String} object.
44 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
45 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
46 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
47 */
48 public DeleteTaxonDescriptionOperation(String label,
49 IUndoContext undoContext,
50 TaxonDescription description,
51 IPostOperationEnabled postOperationEnabled,
52 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
53 super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
54
55 this.description = description;
56 element = description.getTaxon();
57 }
58
59 /* (non-Javadoc)
60 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
61 */
62 /** {@inheritDoc} */
63 @Override
64 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
65 throws ExecutionException {
66
67 monitor.worked(20);
68 if (description != null){
69 List<String> propertyPaths = new ArrayList<String>();
70 propertyPaths.add("taxon");
71 TaxonDescription loadedDescription = (TaxonDescription) CdmStore.getService(IDescriptionService.class).load(description.getUuid(), propertyPaths);
72 CdmStore.getService(IDescriptionService.class).deleteDescription(loadedDescription);
73 return postExecute(description);
74 }
75 return null;
76
77 }
78
79 /* (non-Javadoc)
80 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
81 */
82 /** {@inheritDoc} */
83 @Override
84 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86 return execute(monitor, info);
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 */
92 /** {@inheritDoc} */
93 @Override
94 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
95 throws ExecutionException {
96
97 element.addDescription(description);
98
99 return postExecute(null);
100 }
101 }