31c40329203ad7811982eaf0387899aec2033ac0
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / operations / CreateTaxonomicTreeOperation.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 org.apache.log4j.Logger;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.AbstractOperation;
16 import org.eclipse.core.commands.operations.IUndoContext;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21
22 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
23 import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
24 import eu.etaxonomy.taxeditor.model.TaxonUtil;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27 /**
28 * @author n.hoffmann
29 * @created 23.06.2009
30 * @version 1.0
31 */
32 public class CreateTaxonomicTreeOperation extends AbstractOperation {
33
34 private static final Logger logger = Logger
35 .getLogger(CreateTaxonomicTreeOperation.class);
36 private String treeLabel;
37
38 /**
39 * @param label
40 * @param undoContext
41 */
42 public CreateTaxonomicTreeOperation(String label, IUndoContext undoContext, String treeLabel) {
43 super(label);
44 addContext(undoContext);
45
46 this.treeLabel = treeLabel;
47 }
48
49 /* (non-Javadoc)
50 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
51 */
52 @Override
53 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
54 throws ExecutionException {
55
56 if(treeLabel.trim().length() == 0){
57 return Status.CANCEL_STATUS;
58 }
59
60 // get a new conversation
61 ConversationHolder conversation = CdmStore.NewTransactionalConversation();
62
63 TaxonomicTree tree = TaxonomicTree.NewInstance(treeLabel);
64
65 CdmStore.getTaxonService().saveTaxonomicTree(tree);
66
67 conversation.commit(true);
68
69 return Status.OK_STATUS;
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 */
75 @Override
76 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
77 throws ExecutionException {
78 // TODO Auto-generated method stub
79 return null;
80 }
81
82 /* (non-Javadoc)
83 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
84 */
85 @Override
86 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
87 throws ExecutionException {
88 // TODO Auto-generated method stub
89 return null;
90 }
91 }