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
.AbstractOperation
;
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
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.ui
.PartInitException
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.taxeditor
.UiUtil
;
25 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
32 public class DeleteTaxonOperation
extends AbstractEditorOperation
{
33 private static Logger logger
= Logger
.getLogger(DeleteTaxonOperation
.class);
35 private Taxon parentTaxon
;
36 public DeleteTaxonOperation(String text
, IUndoContext undoContext
,
38 super(text
, undoContext
, taxon
);
40 parentTaxon
= taxon
.getTaxonomicParent();
44 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
47 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
48 throws ExecutionException
{
50 // TODO move this logic to another place
53 String taxonName
= taxon
.getName().getTitleCache();
55 // Prompt user for confirmation
56 if(! MessageDialog
.openConfirm(UiUtil
.getShell(), "Confirm Deletion", "Are you sure you want to delete taxon '" + taxonName
+ "'?")){
58 return Status
.CANCEL_STATUS
;
61 // Get and start progress monitor
62 monitor
.beginTask("Deleting taxon '" + taxonName
+ "'.", 10);
68 // If the taxon has children, cancel operation
69 // TODO add option to continue, and delete children
70 if (taxon
.hasTaxonomicChildren()) {
71 MessageDialog
.openInformation(UiUtil
.getShell(), "Cannot delete taxon",
72 "'" + taxonName
+ "' has taxonomic children. " +
73 "These must be manually deleted before their parent.");
75 return Status
.CANCEL_STATUS
;
80 // Close taxon's editor, if any is active
82 UiUtil
.closeEditor(taxon
, true);
83 } catch (PartInitException e
) {
88 // Delete taxon from CDM layer
89 CdmSessionDataRepository
.getDefault().removeTaxon(taxon
);
96 // Close the progress monitor
99 // Announce taxon was deleted on status line
100 UiUtil
.setStatusLine("Deleted taxon '" + taxonName
+ "'.");
102 return Status
.OK_STATUS
;
106 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
110 throws ExecutionException
{
111 return execute(monitor
, info
);
115 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
118 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
119 throws ExecutionException
{
120 // FIXME we have to add old citation
121 parentTaxon
.addTaxonomicChild(taxon
, null, null);
122 CdmSessionDataRepository
.getDefault().addTaxon(taxon
);
123 return Status
.OK_STATUS
;