reintegrated 3.2.4 SNAPSHOT
[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.ui.IEditorInput;
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.cdm.model.location.NamedArea;
23 import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
24 import eu.etaxonomy.taxeditor.editor.definedterm.input.AbstractDefinedTermEditorInput;
25 import eu.etaxonomy.taxeditor.editor.definedterm.input.NamedAreaEditorInput;
26 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
27 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
28
29 /**
30 * @author l.morris
31 * @date 21 Dec 2011
32 *
33 */
34 public class CreateDefinedTermOperation extends AbstractPostOperation {
35
36
37
38 private TermBase parentTermBase;
39 private AbstractDefinedTermEditorInput editorInput;
40
41 /**
42 * @param label
43 * @param undoContext
44 * @param postOperationEnabled
45 */
46 public CreateDefinedTermOperation(String label,
47 IUndoContext undoContext, TermBase termBase, IPostOperationEnabled postOperationEnabled) {
48 super(label, undoContext, postOperationEnabled);
49 this.parentTermBase = termBase;
50 editorInput = ((DefinedTermEditor)postOperationEnabled).getDefinedTermEditorInput();
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55 */
56 @Override
57 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58 throws ExecutionException {
59
60 DefinedTermBase newTerm = editorInput.createTermInstance();
61
62 newTerm.setLabel("Untitled");
63
64 if (parentTermBase instanceof TermVocabulary){
65 TermVocabulary vocabulary = (TermVocabulary) parentTermBase;
66 vocabulary.addTerm(newTerm);
67 } else if (parentTermBase instanceof DefinedTermBase) {
68 DefinedTermBase parent = (DefinedTermBase) parentTermBase;
69 parent.addIncludes(newTerm);
70 TermVocabulary vocabulary = parent.getVocabulary();
71 vocabulary.addTerm(newTerm);
72 }
73
74 return postExecute(newTerm);
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79 */
80 @Override
81 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
82 throws ExecutionException {
83 // TODO Auto-generated method stub
84 return null;
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 */
90 @Override
91 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
92 throws ExecutionException {
93 // TODO Auto-generated method stub
94 return null;
95 }
96
97 }