implemented user management, fixes #803. Minor refactorings.
[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.model.taxon.TaxonomicTree;
27 import eu.etaxonomy.taxeditor.store.CdmStore;
28
29 /**
30 * @author n.hoffmann
31 * @created 23.06.2009
32 * @version 1.0
33 */
34 public class DeleteTaxonomicTreeOperation extends AbstractPostOperation {
35
36 private static final Logger logger = Logger
37 .getLogger(DeleteTaxonomicTreeOperation.class);
38
39 private TaxonomicTree taxonomicTree;
40
41
42 /**
43 * @param label
44 * @param undoContext
45 * @param taxonNode
46 * @param postOperationEnabled
47 */
48 public DeleteTaxonomicTreeOperation(String label, IUndoContext undoContext,
49 TaxonomicTree taxonomicTree) {
50 super(label, undoContext);
51
52 this.taxonomicTree = taxonomicTree;
53
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 */
59 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60 throws ExecutionException {
61
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() + "'?")){
64 monitor.done();
65 return Status.CANCEL_STATUS;
66 }
67
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.");
74 monitor.done();
75 return Status.CANCEL_STATUS;
76 }
77
78 deleteTaxonomicTreeIsolated(taxonomicTree.getUuid());
79
80 return postExecute(null);
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.core.commands.operations.IUndoableOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 */
86 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
87 throws ExecutionException {
88 // TODO Auto-generated method stub
89 return null;
90 }
91
92
93 /* (non-Javadoc)
94 * @see org.eclipse.core.commands.operations.IUndoableOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95 */
96 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
97 throws ExecutionException {
98 // TODO Auto-generated method stub
99 return null;
100 }
101
102 /**
103 * @param uuid
104 */
105 private boolean deleteTaxonomicTreeIsolated(UUID uuid) {
106 // get a new conversation
107 ConversationHolder conversation = CdmStore.NewTransactionalConversation();
108
109 TaxonomicTree taxonomicTree = CdmStore.getTaxonService().getTaxonomicTreeByUuid(uuid);
110 CdmStore.getTaxonService().removeTaxonomicTree(taxonomicTree);
111
112 // commit the conversation
113 conversation.commit(true);
114 return true;
115 }
116 }