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
.ICdmApplicationConfiguration
;
21 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
22 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
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
.editor
.internal
.TaxeditorEditorPlugin
;
27 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 * <p>DeleteSynonymOperation class.</p>
39 public class DeleteSynonymOperation
extends AbstractPostTaxonOperation
{
41 private final Synonym synonym
;
42 private Set
<SynonymRelationshipType
> synonymTypes
;
45 * <p>Constructor for DeleteSynonymOperation.</p>
47 * @param label a {@link java.lang.String} object.
48 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
49 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
50 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
51 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
53 public DeleteSynonymOperation(String label
, IUndoContext undoContext
,
54 Taxon taxon
, Synonym synonym
, IPostOperationEnabled postOperationEnabled
) {
55 super(label
, undoContext
, taxon
, postOperationEnabled
);
56 this.synonym
= synonym
;
60 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
65 throws ExecutionException
{
67 // Store synonymRelationshipType for later undo operations
68 synonymTypes
= synonym
.getRelationType(element
);
71 // Remove synonym from taxon
73 ICdmApplicationConfiguration controller
;
75 controller
= CdmStore
.getCurrentApplicationConfiguration();
77 ITaxonService service
= controller
.getTaxonService();
78 if (synonym
.getId() == 0){
79 element
.removeSynonym(synonym
);
82 //TODO: this should be moved to the handler, the operations should not contain ui code
83 DeleteResult result
= service
.deleteSynonym(synonym
.getUuid(), element
.getUuid(), null);
84 if (result
.isError()){
85 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "Delete failed", TaxeditorEditorPlugin
.PLUGIN_ID
);
86 } else if (!result
.getUpdatedObjects().isEmpty()){
87 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "The Synonym could be deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin
.PLUGIN_ID
);
90 // taxon.removeSynonym(synonym);
91 // CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
92 // CdmStore.getTaxonService().delete(synonym);
96 // Redraw editor if exists
98 return postExecute(element
);
102 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
107 throws ExecutionException
{
108 return execute(monitor
, info
);
112 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
117 throws ExecutionException
{
119 // Add synonym to taxon
120 for (SynonymRelationshipType synonymType
: synonymTypes
){
121 element
.addSynonym(synonym
, synonymType
);
124 // Redraw editor if exists
125 return postExecute(synonym
);