Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / operation / CreateTermVocabularyOperation.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
17 import eu.etaxonomy.cdm.api.service.IVocabularyService;
18 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19 import eu.etaxonomy.cdm.model.common.OrderedTermBase;
20 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
21 import eu.etaxonomy.cdm.model.common.TermType;
22 import eu.etaxonomy.cdm.model.common.TermVocabulary;
23 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
24 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
25 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27
28 /**
29 * @author l.morris
30 * @date 21 Dec 2011
31 *
32 */
33 public class CreateTermVocabularyOperation extends AbstractPostTaxonOperation {
34
35 private final TermEditorInput definedEditorInput;
36
37 /**
38 * @param label
39 * @param undoContext
40 * @param postOperationEnabled
41 */
42 public CreateTermVocabularyOperation(String label,
43 IUndoContext undoContext,
44 TermEditorInput definedEditorInput,
45 IPostOperationEnabled postOperationEnabled) {
46 super(label, undoContext, postOperationEnabled);
47 this.definedEditorInput = definedEditorInput;
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
52 */
53 @Override
54 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55 throws ExecutionException {
56
57 TermType type= definedEditorInput.getTermType();
58 DefinedTermBase test = type.getEmptyDefinedTermBase();
59 TermVocabulary termVocabulary = null;
60 if (test instanceof OrderedTermBase){
61 termVocabulary = OrderedTermVocabulary.NewInstance(definedEditorInput.getTermType(),
62 null,
63 "Untitled",
64 null,
65 null);
66 }
67
68 if (termVocabulary == null){
69 termVocabulary =
70 TermVocabulary.NewInstance(definedEditorInput.getTermType(),
71 null,
72 "Untitled",
73 null,
74 null);
75 }
76
77 termVocabulary = CdmStore.getService(IVocabularyService.class).save(termVocabulary);
78 definedEditorInput.getVocabularies().add(termVocabulary);
79
80 return postExecute(termVocabulary);
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
85 */
86 @Override
87 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
88 throws ExecutionException {
89 // TODO Auto-generated method stub
90 return null;
91 }
92
93 /* (non-Javadoc)
94 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95 */
96 @Override
97 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
98 throws ExecutionException {
99 // TODO Auto-generated method stub
100 return null;
101 }
102
103 }