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