ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / operation / CreateDefinedTermOperation.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.editor.definedterm.operation;
10
11 import org.eclipse.core.commands.ExecutionException;
12 import org.eclipse.core.commands.operations.IUndoContext;
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17
18 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19 import eu.etaxonomy.cdm.model.common.TermBase;
20 import eu.etaxonomy.cdm.model.common.TermVocabulary;
21 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
22 import eu.etaxonomy.taxeditor.model.MessagingUtils;
23 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
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 final TermBase parentTermBase;
38 private final 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 newTerm = CdmStore.getCurrentApplicationConfiguration().getTermService().save(newTerm);
72
73 if (parentTermBase instanceof TermVocabulary){
74 TermVocabulary vocabulary = (TermVocabulary) parentTermBase;
75 vocabulary.addTerm(newTerm);
76 } else if (parentTermBase instanceof DefinedTermBase) {
77 DefinedTermBase parent = (DefinedTermBase) parentTermBase;
78 parent.addIncludes(newTerm);
79 TermVocabulary vocabulary = parent.getVocabulary();
80 vocabulary.addTerm(newTerm);
81 }
82
83 return postExecute(newTerm);
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88 */
89 @Override
90 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91 throws ExecutionException {
92 // TODO Auto-generated method stub
93 return null;
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 */
99 @Override
100 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
101 throws ExecutionException {
102 // TODO Auto-generated method stub
103 return null;
104 }
105
106 }