2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.operation
;
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
;
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
.AbstractPostTaxonOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 * <p>DeleteSynonymOperation class.</p>
36 public class DeleteSynonymOperation
extends AbstractPostTaxonOperation
{
38 private final Synonym synonym
;
39 private Set
<SynonymRelationshipType
> synonymTypes
;
42 * <p>Constructor for DeleteSynonymOperation.</p>
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.
50 public DeleteSynonymOperation(String label
, IUndoContext undoContext
,
51 Taxon taxon
, Synonym synonym
, IPostOperationEnabled postOperationEnabled
) {
52 super(label
, undoContext
, taxon
, postOperationEnabled
);
53 this.synonym
= synonym
;
57 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
61 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
62 throws ExecutionException
{
64 // Store synonymRelationshipType for later undo operations
65 synonymTypes
= synonym
.getRelationType(element
);
68 // Remove synonym from taxon
70 CdmApplicationController controller
;
72 controller
= (CdmApplicationController
) CdmStore
.getCurrentApplicationConfiguration();
74 ITaxonService service
= controller
.getTaxonService();
75 if (synonym
.getId() == 0){
76 element
.removeSynonym(synonym
);
79 service
.deleteSynonym(synonym
, null);
81 // taxon.removeSynonym(synonym);
82 // CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
83 // CdmStore.getTaxonService().delete(synonym);
87 // Redraw editor if exists
89 return postExecute(element
);
93 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
98 throws ExecutionException
{
99 return execute(monitor
, info
);
103 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
107 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
108 throws ExecutionException
{
110 // Add synonym to taxon
111 for (SynonymRelationshipType synonymType
: synonymTypes
){
112 element
.addSynonym(synonym
, synonymType
);
115 // Redraw editor if exists
116 return postExecute(synonym
);