Refactored description editor per #577
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / operations / name / RemoveSynonymOperation.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.operations.name;
11
12 import java.util.Set;
13
14 import org.apache.log4j.Logger;
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.model.taxon.Synonym;
22 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation;
25
26 /**
27 * @author p.ciardelli
28 * @created 14.01.2009
29 * @version 1.0
30 */
31 public class RemoveSynonymOperation extends AbstractEditorOperation {
32 private static final Logger logger = Logger
33 .getLogger(RemoveSynonymOperation.class);
34
35 private Synonym synonym;
36 private Set<SynonymRelationshipType> synonymTypes;
37
38 public RemoveSynonymOperation(String label, IUndoContext undoContext,
39 Taxon taxon, Synonym synonym) {
40 super(label, undoContext, taxon);
41 this.synonym = synonym;
42 }
43
44 /* (non-Javadoc)
45 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
46 */
47 @Override
48 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
49 throws ExecutionException {
50
51 // Store synonymRelationshipType for later undo operations
52 synonymTypes = synonym.getRelationType(taxon);
53
54 // Remove synonym from taxon
55 taxon.removeSynonym(synonym);
56
57 // Redraw editor if exists
58 return redrawOpenEditor();
59 }
60
61 /* (non-Javadoc)
62 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
63 */
64 @Override
65 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
66 throws ExecutionException {
67 return execute(monitor, info);
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
72 */
73 @Override
74 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
75 throws ExecutionException {
76
77 // Add synonym to taxon
78 for (SynonymRelationshipType synonymType : synonymTypes){
79 taxon.addSynonym(synonym, synonymType);
80 }
81
82 // Redraw editor if exists
83 return redrawOpenEditor();
84 }
85 }