Merge branch 'release/3.12.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / input / TermEditorInput.java
index aef64fe08ab79c6fd90b3fc315b194532f2b94c1..518382f1f1f494a3b3f6e4c211807f0e4e9db7c5 100644 (file)
@@ -1,14 +1,15 @@
 // $Id$
 /**
 * Copyright (C) 2009 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 package eu.etaxonomy.taxeditor.editor.definedterm.input;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
@@ -19,7 +20,10 @@ import eu.etaxonomy.cdm.model.common.DefinedTerm;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.TermStore;
 
 
 
@@ -32,10 +36,15 @@ public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm>
 
        private TermType termType;
        private Set<TermVocabulary<DefinedTermBase>> vocabularies;
+
+       // FIXME: the default feature should be move to CdmApplicationState
+       //        where it is a singleton instance variable
+       private static FeatureTree defaultFeatureTree = null;
+
        private List<String> termClasses = Arrays.asList(new String[]{
                        DefinedTerm.class.getName()
        });
-       
+
        public TermEditorInput(TermType termType) {
                this.termType = termType;
                vocabularies = new HashSet<TermVocabulary<DefinedTermBase>>();
@@ -56,21 +65,52 @@ public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm>
        public List<String> getTermClasses() {
                return termClasses;
        }
-       
+
        public TermType getTermType() {
                return termType;
        }
-       
+
        public void initialiseVocabularies() {
                if(vocabularies != null) {
                        vocabularies.clear();
-               } 
+               }
                List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(termType);
-               vocabularies.addAll(vocs);                      
+               vocabularies.addAll(vocs);
        }
-       
+
        public Set<TermVocabulary<DefinedTermBase>> getVocabularies() {
                return vocabularies;
        }
 
+       public void updateDefaultFeatureTree() {
+           for(TermVocabulary vocab : getVocabularies()) {
+               if(vocab != null && TermType.Feature.equals(vocab.getTermType())) {
+                   defaultFeatureTree = null;
+               }
+           }
+       }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Set<TermVocabulary<DefinedTermBase>>  getRootEntities() {
+        return getVocabularies();
+    }
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void merge() {
+        if(CdmStore.getCurrentSessionManager().isRemoting()) {
+            CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()), true);
+            updateDefaultFeatureTree();
+        }
+    }
+
+    public static FeatureTree getDefaultFeatureTree() {
+        if(defaultFeatureTree == null) {
+            defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
+        }
+        return defaultFeatureTree;
+    }
 }
\ No newline at end of file