fixes #727
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.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.model.TaxonUtil;
24 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
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.getLogger(CreateChildTaxonOperation.class);
34
35 private TaxonNameBase<?, ?> newTaxonName;
36
37 private Taxon childTaxon;
38
39
40 /**
41 * @param label
42 * @param undoContext
43 * @param taxon
44 * @param postOperationEnabled
45 * @param conversationEnabled
46 */
47 public CreateChildTaxonOperation(String label, IUndoContext undoContext,
48 Taxon taxon, TaxonNameBase<?, ?> name, IPostOperationEnabled postOperationEnabled) {
49 super(label, undoContext, taxon, postOperationEnabled);
50
51 this.newTaxonName = name;
52 }
53
54
55 /* (non-Javadoc)
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57 */
58 @Override
59 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60 throws ExecutionException {
61
62 childTaxon = TaxonUtil.addChildTaxonBaseIsolated(taxon.getUuid(), newTaxonName);
63
64 if(childTaxon != null){
65 return postExecute(childTaxon);
66 }else{
67 return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, TaxeditorStorePlugin.ERROR_SAVING_ZERO_NAME, "Attempt to save taxon with zero length name", null);
68 }
69 }
70
71 /* (non-Javadoc)
72 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
73 */
74 @Override
75 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
76 throws ExecutionException {
77 return execute(monitor, info);
78 }
79
80 /* (non-Javadoc)
81 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 */
83 @Override
84 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86
87 logger.warn("Not yet implemented.");
88 return null;
89 }
90 }