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