Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / CreateChildTaxonOperation.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.store.operations;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.IUndoContext;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Status;
20
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
24 import eu.etaxonomy.taxeditor.store.model.TaxonUtil;
25
26 /**
27 * @author n.hoffmann
28 * @created 08.05.2009
29 * @version 1.0
30 */
31 public class CreateChildTaxonOperation extends AbstractPostOperation {
32
33 private static final Logger logger = Logger
34 .getLogger(CreateChildTaxonOperation.class);
35
36 private TaxonNameBase newTaxonName;
37
38 private Taxon childTaxon;
39
40
41 /**
42 * @param label
43 * @param undoContext
44 * @param taxon
45 * @param postOperationEnabled
46 * @param conversationEnabled
47 */
48 public CreateChildTaxonOperation(String label, IUndoContext undoContext,
49 Taxon taxon, TaxonNameBase name, IPostOperationEnabled postOperationEnabled) {
50 super(label, undoContext, taxon, postOperationEnabled);
51
52 this.newTaxonName = name;
53 }
54
55
56 /* (non-Javadoc)
57 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 */
59 @Override
60 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61 throws ExecutionException {
62
63 childTaxon = TaxonUtil.addChildTaxonBaseIsolated(taxon.getUuid(), newTaxonName);
64
65 if(childTaxon != null){
66 return postExecute(childTaxon);
67 }else{
68 return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, TaxeditorStorePlugin.ERROR_SAVING_ZERO_NAME, "Attempt to save taxon with zero length name", null);
69 }
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 return execute(monitor, info);
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 */
84 @Override
85 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
86 throws ExecutionException {
87
88 logger.warn("Not yet implemented.");
89 return null;
90 }
91 }