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
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
22 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
28 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 * <p>DeleteSynonymOperation class.</p>
38 public class DeleteSynonymOperation
extends AbstractPostTaxonOperation
{
40 private final Synonym synonym
;
41 private Set
<SynonymRelationshipType
> synonymTypes
;
44 * <p>Constructor for DeleteSynonymOperation.</p>
46 * @param label a {@link java.lang.String} object.
47 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
48 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
50 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
52 public DeleteSynonymOperation(String label
, IUndoContext undoContext
,
53 Taxon taxon
, Synonym synonym
, IPostOperationEnabled postOperationEnabled
) {
54 super(label
, undoContext
, taxon
, postOperationEnabled
);
55 this.synonym
= synonym
;
59 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
63 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
64 throws ExecutionException
{
66 // Store synonymRelationshipType for later undo operations
67 synonymTypes
= synonym
.getRelationType(element
);
70 // Remove synonym from taxon
72 ICdmApplicationConfiguration controller
;
74 controller
= (ICdmApplicationConfiguration
) CdmStore
.getCurrentApplicationConfiguration();
76 ITaxonService service
= controller
.getTaxonService();
77 if (synonym
.getId() == 0){
78 element
.removeSynonym(synonym
);
82 DeleteResult result
= service
.deleteSynonym(synonym
, null);
83 if (result
.isError()){
84 MessageDialog
.openError(null, "Delete failed", result
.getExceptions().get(0).getMessage());
85 } else if (result
.getUpdatedObjects().size() != 0){
86 MessageDialog
.openInformation(null, "Delete successfull", "The Synonym could be deleted, but there is an updated object: " + result
.getExceptions().get(0).getMessage());
89 // taxon.removeSynonym(synonym);
90 // CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
91 // CdmStore.getTaxonService().delete(synonym);
95 // Redraw editor if exists
97 return postExecute(element
);
101 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
106 throws ExecutionException
{
107 return execute(monitor
, info
);
111 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
116 throws ExecutionException
{
118 // Add synonym to taxon
119 for (SynonymRelationshipType synonymType
: synonymTypes
){
120 element
.addSynonym(synonym
, synonymType
);
123 // Redraw editor if exists
124 return postExecute(synonym
);