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