adapt to new factory method
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / operation / CreateTermVocabularyOperation.java
index 7911410a71c708154a8a57aae37894b852b5440e..febdb92637447ce85de335254475fdaecef0f003 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$\r
 /**\r
 * Copyright (C) 2009 EDIT\r
 * European Distributed Institute of Taxonomy\r
@@ -16,10 +15,16 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;\r
 \r
 import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
-import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;\r
+import eu.etaxonomy.cdm.model.term.OrderedTermBase;\r
+import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;\r
+import eu.etaxonomy.cdm.model.term.TermType;\r
+import eu.etaxonomy.cdm.model.term.TermVocabulary;\r
+import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;\r
 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;\r
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;\r
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;\r
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
 import eu.etaxonomy.taxeditor.store.CdmStore;\r
 \r
 /**\r
@@ -31,11 +36,6 @@ public class CreateTermVocabularyOperation extends AbstractPostTaxonOperation {
 \r
        private final TermEditorInput definedEditorInput;\r
 \r
-       /**\r
-        * @param label\r
-        * @param undoContext\r
-        * @param postOperationEnabled\r
-        */\r
        public CreateTermVocabularyOperation(String label,\r
                        IUndoContext undoContext,\r
                        TermEditorInput definedEditorInput,\r
@@ -44,43 +44,42 @@ public class CreateTermVocabularyOperation extends AbstractPostTaxonOperation {
                this.definedEditorInput = definedEditorInput;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
-        */\r
        @Override\r
        public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r
 \r
-               TermVocabulary termVocabulary =\r
-                                       TermVocabulary.NewInstance(definedEditorInput.getTermType(),\r
-                                               null,\r
-                                               "Untitled",\r
-                                               null,\r
-                                               null);\r
+          TermType type= definedEditorInput.getTermType();\r
+          DefinedTermBase test = type.getEmptyDefinedTermBase(PreferencesUtil.getGlobalLanguage());\r
+          TermVocabulary termVocabulary = null;\r
+          if (test instanceof OrderedTermBase){\r
+             termVocabulary = OrderedTermVocabulary.NewInstance(definedEditorInput.getTermType(),null, null,"Untitled",null, null, PreferencesUtil.getGlobalLanguage());\r
+          }\r
+\r
+          if (termVocabulary == null){\r
+           termVocabulary =\r
+                TermVocabulary.NewInstance(definedEditorInput.getTermType(),\r
+                    null,null, \r
+                    "Untitled",\r
+                    null,\r
+                    null, PreferencesUtil.getGlobalLanguage());\r
+          }\r
 \r
                termVocabulary = CdmStore.getService(IVocabularyService.class).save(termVocabulary);\r
-               definedEditorInput.getVocabularies().add(termVocabulary);\r
+               //FIXME: implement creation of term vocabularies\r
+//             definedEditorInput.getVocabularies().add(termVocabulary);\r
 \r
-               return postExecute(termVocabulary);\r
+               return postExecute(new TermVocabularyDto(termVocabulary.getUuid(), termVocabulary.getRepresentations(), termVocabulary.getTermType(), termVocabulary.getTitleCache(), termVocabulary.isAllowDuplicates(), termVocabulary.isOrderRelevant(), termVocabulary.isFlat()));\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
-        */\r
        @Override\r
        public IStatus redo(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r
-               // TODO Auto-generated method stub\r
                return null;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r
-        */\r
        @Override\r
        public IStatus undo(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r
-               // TODO Auto-generated method stub\r
                return null;\r
        }\r
 \r