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
.SynonymType
;
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>
38 public class DeleteSynonymOperation
extends AbstractPostTaxonOperation
{
40 private final Synonym synonym
;
41 private SynonymType synonymType
;
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
;
60 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
61 throws ExecutionException
{
63 // Store SynonymType for later undo operations
64 synonymType
= synonym
.getType();
67 // Remove synonym from taxon
68 ICdmApplicationConfiguration controller
;
70 controller
= CdmStore
.getCurrentApplicationConfiguration();
72 ITaxonService service
= controller
.getTaxonService();
73 if (synonym
.getId() == 0){
74 element
.removeSynonym(synonym
);
77 //TODO: this should be moved to the handler, the operations should not contain ui code
78 DeleteResult result
= service
.deleteSynonym(synonym
.getUuid(), null);
79 if (result
.isError()){
80 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "Delete failed", TaxeditorEditorPlugin
.PLUGIN_ID
);
81 } else if (!result
.getUpdatedObjects().isEmpty()){
82 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "The Synonym could be deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin
.PLUGIN_ID
);
85 // taxon.removeSynonym(synonym);
86 // CdmStore.getTaxonService().deleteSynonymRelationships(synonym);
87 // CdmStore.getTaxonService().delete(synonym);
91 // Redraw editor if exists
93 return postExecute(element
);
98 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
99 throws ExecutionException
{
100 return execute(monitor
, info
);
105 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
106 throws ExecutionException
{
108 // Add synonym to taxon
109 element
.addSynonym(synonym
, synonymType
);
111 // Redraw editor if exists
112 return postExecute(synonym
);