automated build configuration is on its way
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / DeleteSynonymOperation.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.name.operation;
11
12 import java.util.Set;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.IUndoContext;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25
26 /**
27 * <p>DeleteSynonymOperation class.</p>
28 *
29 * @author p.ciardelli
30 * @created 14.01.2009
31 * @version 1.0
32 */
33 public class DeleteSynonymOperation extends AbstractPostOperation {
34
35 private Synonym synonym;
36 private Set<SynonymRelationshipType> synonymTypes;
37
38 /**
39 * <p>Constructor for DeleteSynonymOperation.</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 taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
44 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
45 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
46 */
47 public DeleteSynonymOperation(String label, IUndoContext undoContext,
48 Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) {
49 super(label, undoContext, taxon, postOperationEnabled);
50 this.synonym = synonym;
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55 */
56 /** {@inheritDoc} */
57 @Override
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60
61 // Store synonymRelationshipType for later undo operations
62 synonymTypes = synonym.getRelationType(taxon);
63 monitor.worked(20);
64
65 // Remove synonym from taxon
66
67 taxon.removeSynonym(synonym);
68 // CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
69 // CdmStore.getTaxonService().delete(synonym);
70
71 monitor.worked(40);
72
73 // Redraw editor if exists
74 return postExecute(null);
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79 */
80 /** {@inheritDoc} */
81 @Override
82 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
83 throws ExecutionException {
84 return execute(monitor, info);
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 */
90 /** {@inheritDoc} */
91 @Override
92 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
93 throws ExecutionException {
94
95 // Add synonym to taxon
96 for (SynonymRelationshipType synonymType : synonymTypes){
97 taxon.addSynonym(synonym, synonymType);
98 }
99
100 // Redraw editor if exists
101 return postExecute(synonym);
102 }
103 }