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
.TaxonNode
;
23 import eu
.etaxonomy
.taxeditor
.model
.TaxonNodeUtil
;
26 * Delete a taxon node from its TaxonomicTree and thus from the current taxonomic view.
33 public class DeleteTaxonNodeOperation
extends AbstractPostOperation
{
35 @SuppressWarnings("unused")
36 private static Logger logger
= Logger
.getLogger(DeleteTaxonNodeOperation
.class);
39 * The taxonomical parent of the taxon to be deleted.
41 private TaxonNode parentTaxonNode
;
43 public DeleteTaxonNodeOperation(String text
, IUndoContext undoContext
,
44 TaxonNode taxonNode
) {
45 super(text
, undoContext
, taxonNode
, null);
47 parentTaxonNode
= taxonNode
.getParent();
51 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
54 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
55 throws ExecutionException
{
57 // Get taxon name - watch out for null names
58 String taxonName
= "";
59 if (taxon
.getName() != null) {
60 taxonName
= taxon
.getName().getTitleCache();
63 // Prompt user for confirmation
64 if(! MessageDialog
.openConfirm((Shell
) info
.getAdapter(Shell
.class), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName
+ "' from this taxonomic view?")){
66 return Status
.CANCEL_STATUS
;
70 // If the taxon node has child nodes, cancel operation
71 // TODO add option to continue, and delete children
72 if (taxonNode
.getChildNodes().size() > 0) {
73 MessageDialog
.openInformation((Shell
) info
.getAdapter(Shell
.class), "Cannot delete taxon",
74 "'" + taxonName
+ "' has taxonomic children. " +
75 "These must be manually deleted before their parent.");
77 return Status
.CANCEL_STATUS
;
80 // delete the taxon in an isolated conversation
81 TaxonNodeUtil
.deleteTaxonNodeIsolated(taxonNode
.getUuid());
84 return postExecute(null);
88 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
92 throws ExecutionException
{
93 return execute(monitor
, info
);
97 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
100 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
101 throws ExecutionException
{
102 // FIXME we have to add old citation
103 parentTaxonNode
.addChild(taxon
);
104 // FIXME readding has to take place in an isolated conversation as well
105 // so that all the mediation magic does the rest for us
106 return postExecute(null);