3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.operations
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.core
.runtime
.IAdaptable
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
23 import org
.eclipse
.swt
.widgets
.Shell
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 public class DeleteTaxonomicTreeOperation
extends AbstractPostOperation
{
36 private static final Logger logger
= Logger
37 .getLogger(DeleteTaxonomicTreeOperation
.class);
39 private TaxonomicTree taxonomicTree
;
46 * @param postOperationEnabled
48 public DeleteTaxonomicTreeOperation(String label
, IUndoContext undoContext
,
49 TaxonomicTree taxonomicTree
) {
50 super(label
, undoContext
);
52 this.taxonomicTree
= taxonomicTree
;
57 * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
60 throws ExecutionException
{
62 // Prompt user for confirmation
63 if(! MessageDialog
.openConfirm((Shell
) info
.getAdapter(Shell
.class), "Confirm Deletion", "Are you sure you want to delete the taxonomic view '" + taxonomicTree
.getTitleCache() + "'?")){
65 return Status
.CANCEL_STATUS
;
68 // If the taxonomic tree has child nodes, cancel operation
69 // TODO add option to continue, and delete children
70 if (taxonomicTree
.getRootNodes().size() > 0) {
71 MessageDialog
.openInformation((Shell
) info
.getAdapter(Shell
.class), "Cannot delete taxon",
72 "'" + taxonomicTree
.getTitleCache() + "' has taxonomic children. " +
73 "These must be manually deleted before their parent.");
75 return Status
.CANCEL_STATUS
;
78 deleteTaxonomicTreeIsolated(taxonomicTree
.getUuid());
80 return postExecute(null);
84 * @see org.eclipse.core.commands.operations.IUndoableOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
87 throws ExecutionException
{
88 // TODO Auto-generated method stub
94 * @see org.eclipse.core.commands.operations.IUndoableOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
97 throws ExecutionException
{
98 // TODO Auto-generated method stub
105 private boolean deleteTaxonomicTreeIsolated(UUID uuid
) {
106 // get a new conversation
107 ConversationHolder conversation
= CdmStore
.NewTransactionalConversation();
109 TaxonomicTree taxonomicTree
= CdmStore
.getTaxonService().getTaxonomicTreeByUuid(uuid
);
110 CdmStore
.getTaxonService().removeTaxonomicTree(taxonomicTree
);
112 // commit the conversation
113 conversation
.commit(true);