5ab896416a098180f21660be378e251d2eb2c19f
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / 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.store.operations;
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
24 /**
25 * @author p.ciardelli
26 * @created 14.01.2009
27 * @version 1.0
28 */
29 public class DeleteSynonymOperation extends AbstractPostOperation {
30
31 private Synonym synonym;
32 private Set<SynonymRelationshipType> synonymTypes;
33
34 public DeleteSynonymOperation(String label, IUndoContext undoContext,
35 Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled) {
36 super(label, undoContext, taxon, postOperationEnabled);
37 this.synonym = synonym;
38 }
39
40 /* (non-Javadoc)
41 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
42 */
43 @Override
44 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
45 throws ExecutionException {
46
47 // Store synonymRelationshipType for later undo operations
48 synonymTypes = synonym.getRelationType(taxon);
49
50 // Remove synonym from taxon
51 taxon.removeSynonym(synonym);
52
53 // Redraw editor if exists
54 return postExecute(null);
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 */
60 @Override
61 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
62 throws ExecutionException {
63 return execute(monitor, info);
64 }
65
66 /* (non-Javadoc)
67 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68 */
69 @Override
70 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
71 throws ExecutionException {
72
73 // Add synonym to taxon
74 for (SynonymRelationshipType synonymType : synonymTypes){
75 taxon.addSynonym(synonym, synonymType);
76 }
77
78 // Redraw editor if exists
79 return postExecute(synonym);
80 }
81 }