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
.operations
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
15 import org
.eclipse
.core
.runtime
.IAdaptable
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.model
.TaxonUtil
;
26 * Delete a taxon from the model.
28 * TODO: Currently all data in session data repository has to be saved before deleting
29 * a taxon and the whole logic is happening here. This way we would have to implement
30 * the same logic in another place if we want to delete outside of an operation context
31 * (NOT undoable). Therefore it is desirable to have the logic implemented in another
32 * place and merely call a method here.
38 public class DeleteTaxonOperation
extends AbstractPostOperation
{
40 @SuppressWarnings("unused")
41 private static Logger logger
= Logger
.getLogger(DeleteTaxonOperation
.class);
44 * The taxonomical parent of the taxon to be deleted.
46 private Taxon parentTaxon
;
48 public DeleteTaxonOperation(String text
, IUndoContext undoContext
,
50 super(text
, undoContext
, taxon
, null);
52 parentTaxon
= taxon
.getTaxonomicParent();
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
60 throws ExecutionException
{
62 // Get taxon name - watch out for null names
63 String taxonName
= "";
64 if (taxon
.getName() != null) {
65 taxonName
= taxon
.getName().getTitleCache();
68 // Prompt user for confirmation
69 if(! MessageDialog
.openConfirm((Shell
) info
.getAdapter(Shell
.class), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName
+ "'?")){
71 return Status
.CANCEL_STATUS
;
75 // If the taxon has children, cancel operation
76 // TODO add option to continue, and delete children
77 if (taxon
.hasTaxonomicChildren()) {
78 MessageDialog
.openInformation((Shell
) info
.getAdapter(Shell
.class), "Cannot delete taxon",
79 "'" + taxonName
+ "' has taxonomic children. " +
80 "These must be manually deleted before their parent.");
82 return Status
.CANCEL_STATUS
;
85 // delete the taxon in an isolated conversation
86 TaxonUtil
.deleteTaxonBaseIsolated(taxon
.getUuid());
89 return postExecute(null);
93 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
97 throws ExecutionException
{
98 return execute(monitor
, info
);
102 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
106 throws ExecutionException
{
107 // FIXME we have to add old citation
108 parentTaxon
.addTaxonomicChild(taxon
, null, null);
109 // FIXME readding has to take place in an isolated conversation as well
110 // so that all the mediation magic does the rest for us
111 return postExecute(null);