c45db001b9353d7a60d4bc99a8eb1dafdd4a3b14
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / DeleteTaxonomicTreeOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.operations;
12
13 import java.util.UUID;
14
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;
24
25 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
26 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
27 import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * @author n.hoffmann
32 * @created 23.06.2009
33 * @version 1.0
34 */
35 public class DeleteTaxonomicTreeOperation extends AbstractPersistentPostOperation {
36
37 private static final Logger logger = Logger
38 .getLogger(DeleteTaxonomicTreeOperation.class);
39
40 private TaxonomicTree taxonomicTree;
41
42
43 /**
44 * @param label
45 * @param undoContext
46 * @param taxonNode
47 * @param postOperationEnabled
48 */
49 public DeleteTaxonomicTreeOperation(String label, IUndoContext undoContext,
50 TaxonomicTree taxonomicTree, IPostOperationEnabled postOperationEnabled,
51 IConversationEnabled conversationEnabled) {
52 super(label, undoContext, postOperationEnabled, conversationEnabled);
53
54 this.taxonomicTree = taxonomicTree;
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 */
60 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61 throws ExecutionException {
62
63 // Prompt user for confirmation
64 if(! MessageDialog.openConfirm((Shell) info.getAdapter(Shell.class), "Confirm Deletion", "Are you sure you want to delete the taxonomic view '" + taxonomicTree.getTitleCache() + "'?")){
65 monitor.done();
66 return Status.CANCEL_STATUS;
67 }
68
69 // If the taxonomic tree has child nodes, cancel operation
70 // TODO add option to continue, and delete children
71 if (taxonomicTree.getRootNodes().size() > 0) {
72 MessageDialog.openInformation((Shell) info.getAdapter(Shell.class), "Cannot delete taxon",
73 "'" + taxonomicTree.getTitleCache() + "' has taxonomic children. " +
74 "These must be manually deleted before their parent.");
75 monitor.done();
76 return Status.CANCEL_STATUS;
77 }
78
79 CdmStore.getTaxonTreeService().delete(taxonomicTree);
80
81 return postExecute(null);
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.core.commands.operations.IUndoableOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 */
87 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
88 throws ExecutionException {
89 // TODO Auto-generated method stub
90 return null;
91 }
92
93
94 /* (non-Javadoc)
95 * @see org.eclipse.core.commands.operations.IUndoableOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96 */
97 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
98 throws ExecutionException {
99 // TODO Auto-generated method stub
100 return null;
101 }
102 }