// $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;
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;
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>>();
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