#4855 add MoveSynonymToAnotherAcceptedTaxonHandler and some clean up of the plugin...
[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.store.CdmStore;
26
27 /**
28 * <p>DeleteTaxonDescriptionOperation class.</p>
29 *
30 * @author p.ciardelli
31 * @author n.hoffmann
32 * @created 05.02.2009
33 * @version 1.0
34 */
35 public class DeleteTaxonDescriptionOperation extends AbstractPostTaxonOperation {
36
37 private final TaxonDescription description;
38
39 /**
40 * <p>Constructor for DeleteTaxonDescriptionOperation.</p>
41 *
42 * @param label a {@link java.lang.String} object.
43 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
45 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
46 */
47 public DeleteTaxonDescriptionOperation(String label, IUndoContext undoContext,
48 TaxonDescription description, IPostOperationEnabled postOperationEnabled) {
49 super(label, undoContext, postOperationEnabled);
50
51 this.description = description;
52 element = description.getTaxon();
53 }
54
55 /* (non-Javadoc)
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57 */
58 /** {@inheritDoc} */
59 @Override
60 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61 throws ExecutionException {
62
63 monitor.worked(20);
64 if (description != null){
65 List<String> propertyPaths = new ArrayList<String>();
66 propertyPaths.add("taxon");
67 TaxonDescription loadedDescription = (TaxonDescription) CdmStore.getService(IDescriptionService.class).load(description.getUuid(), propertyPaths);
68 CdmStore.getService(IDescriptionService.class).deleteDescription(loadedDescription);
69 return postExecute(description);
70 }
71 return null;
72
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 element.addDescription(description);
94
95 return postExecute(null);
96 }
97 }