2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
17 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
18 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
19 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
23 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
34 public class TermEditorInput
extends AbstractDefinedTermEditorInput
<DefinedTerm
> {
36 private TermType termType
;
37 private Set
<TermVocabulary
<DefinedTermBase
>> vocabularies
;
39 // FIXME: the default feature should be move to CdmApplicationState
40 // where it is a singleton instance variable
41 private static FeatureTree defaultFeatureTree
= null;
43 private List
<String
> termClasses
= Arrays
.asList(new String
[]{
44 DefinedTerm
.class.getName()
47 public TermEditorInput(TermType termType
) {
48 this.termType
= termType
;
49 vocabularies
= new HashSet
<TermVocabulary
<DefinedTermBase
>>();
50 initialiseVocabularies();
53 * @see org.eclipse.ui.IEditorInput#getName()
56 public String
getName() {
57 return termType
.getMessage();
61 * @see eu.etaxonomy.taxeditor.editor.definedterm.input.AbstractDefinedTermEditorInput#getTermClasses()
64 public List
<String
> getTermClasses() {
68 public TermType
getTermType() {
72 public void initialiseVocabularies() {
73 if(vocabularies
!= null) {
76 List
<TermVocabulary
<DefinedTermBase
>> vocs
= CdmStore
.getService(IVocabularyService
.class).findByTermType(termType
);
77 vocabularies
.addAll(vocs
);
80 public Set
<TermVocabulary
<DefinedTermBase
>> getVocabularies() {
84 public void updateDefaultFeatureTree() {
85 for(TermVocabulary vocab
: getVocabularies()) {
86 if(vocab
!= null && TermType
.Feature
.equals(vocab
.getTermType())) {
87 defaultFeatureTree
= null;
95 public Set
<TermVocabulary
<DefinedTermBase
>> getRootEntities() {
96 return getVocabularies();
102 public void merge() {
103 CdmStore
.getService(IVocabularyService
.class).merge(new ArrayList
<TermVocabulary
>(getRootEntities()), true);
104 updateDefaultFeatureTree();
107 public static FeatureTree
getDefaultFeatureTree() {
108 if(defaultFeatureTree
== null) {
109 defaultFeatureTree
= FeatureTree
.NewInstance(TermStore
.getTerms(Feature
.class));
111 return defaultFeatureTree
;