c1e838a9ca056d89e81d845881838fa00e743fc4
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / operation / CreateDefinedTermOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 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 package eu.etaxonomy.taxeditor.editor.definedterm.operation;
11
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18
19 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20 import eu.etaxonomy.cdm.model.common.TermBase;
21 import eu.etaxonomy.cdm.model.common.TermVocabulary;
22 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
23 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25 import eu.etaxonomy.taxeditor.store.StoreUtil;
26
27 /**
28 * @author l.morris
29 * @date 21 Dec 2011
30 *
31 */
32 public class CreateDefinedTermOperation extends AbstractPostTaxonOperation {
33
34
35
36 private TermBase parentTermBase;
37 private TermEditorInput definedTermInput;
38
39 /**
40 * @param label
41 * @param undoContext
42 * @param postOperationEnabled
43 */
44 public CreateDefinedTermOperation(String label,
45 IUndoContext undoContext,
46 TermBase termBase,
47 TermEditorInput definedTermInput,
48 IPostOperationEnabled postOperationEnabled) {
49 super(label, undoContext, postOperationEnabled);
50 this.parentTermBase = termBase;
51 this.definedTermInput = definedTermInput;
52 }
53
54 /* (non-Javadoc)
55 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56 */
57 @Override
58 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60
61 DefinedTermBase newTerm = definedTermInput.getTermType().getEmptyDefinedTermBase();
62 if (newTerm == null) {
63 IStatus status =
64 new Status(IStatus.CANCEL,
65 StoreUtil.getPluginId(),
66 "Creation of term corresponding to type '" + definedTermInput.getTermType().getMessage() + "' is not yet supported");
67 StoreUtil.warningDialog("Cannot create term", newTerm, status);
68 return status;
69 }
70
71 if (parentTermBase instanceof TermVocabulary){
72 TermVocabulary vocabulary = (TermVocabulary) parentTermBase;
73 vocabulary.addTerm(newTerm);
74 } else if (parentTermBase instanceof DefinedTermBase) {
75 DefinedTermBase parent = (DefinedTermBase) parentTermBase;
76 parent.addIncludes(newTerm);
77 TermVocabulary vocabulary = parent.getVocabulary();
78 vocabulary.addTerm(newTerm);
79 }
80
81 return postExecute(newTerm);
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 */
87 @Override
88 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
89 throws ExecutionException {
90 // TODO Auto-generated method stub
91 return null;
92 }
93
94 /* (non-Javadoc)
95 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96 */
97 @Override
98 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
99 throws ExecutionException {
100 // TODO Auto-generated method stub
101 return null;
102 }
103
104 }