Added a bunch of functionality that will be needed when opening the editor with an...
[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
22 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
23 import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * @author n.hoffmann
28 * @created 23.06.2009
29 * @version 1.0
30 */
31 public class DeleteTaxonomicTreeOperation extends AbstractPostOperation {
32
33 private static final Logger logger = Logger
34 .getLogger(DeleteTaxonomicTreeOperation.class);
35
36 private TaxonomicTree taxonomicTree;
37
38
39 /**
40 * @param label
41 * @param undoContext
42 * @param taxonNode
43 * @param postOperationEnabled
44 */
45 public DeleteTaxonomicTreeOperation(String label, IUndoContext undoContext,
46 TaxonomicTree taxonomicTree) {
47 super(label, undoContext, null);
48
49 this.taxonomicTree = taxonomicTree;
50
51 }
52
53
54
55 /* (non-Javadoc)
56 * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57 */
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60
61 deleteTaxonomicTreeIsolated(taxonomicTree.getUuid());
62
63 return postExecute(null);
64 }
65
66 /* (non-Javadoc)
67 * @see org.eclipse.core.commands.operations.IUndoableOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68 */
69 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
70 throws ExecutionException {
71 // TODO Auto-generated method stub
72 return null;
73 }
74
75
76 /* (non-Javadoc)
77 * @see org.eclipse.core.commands.operations.IUndoableOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78 */
79 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
80 throws ExecutionException {
81 // TODO Auto-generated method stub
82 return null;
83 }
84
85 /**
86 * @param uuid
87 */
88 private boolean deleteTaxonomicTreeIsolated(UUID uuid) {
89 // get a new conversation
90 ConversationHolder conversation = CdmStore.NewTransactionalConversation();
91
92 TaxonomicTree taxonomicTree = CdmStore.getTaxonService().getTaxonomicTreeByUuid(uuid);
93 CdmStore.getTaxonService().removeTaxonomicTree(taxonomicTree);
94
95 // commit the conversation
96 conversation.commit(true);
97 return true;
98 }
99 }