3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
19 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
20 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
22 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
23 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
24 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
35 public class TermEditorInput
extends AbstractDefinedTermEditorInput
<DefinedTerm
> {
37 private TermType termType
;
38 private Set
<TermVocabulary
<DefinedTermBase
>> vocabularies
;
40 // FIXME: the default feature should be move to CdmApplicationState
41 // where it is a singleton instance variable
42 private static FeatureTree defaultFeatureTree
= null;
44 private List
<String
> termClasses
= Arrays
.asList(new String
[]{
45 DefinedTerm
.class.getName()
48 public TermEditorInput(TermType termType
) {
49 this.termType
= termType
;
50 vocabularies
= new HashSet
<TermVocabulary
<DefinedTermBase
>>();
51 initialiseVocabularies();
54 * @see org.eclipse.ui.IEditorInput#getName()
57 public String
getName() {
58 return termType
.getMessage();
62 * @see eu.etaxonomy.taxeditor.editor.definedterm.input.AbstractDefinedTermEditorInput#getTermClasses()
65 public List
<String
> getTermClasses() {
69 public TermType
getTermType() {
73 public void initialiseVocabularies() {
74 if(vocabularies
!= null) {
77 List
<TermVocabulary
<DefinedTermBase
>> vocs
= CdmStore
.getService(IVocabularyService
.class).findByTermType(termType
);
78 vocabularies
.addAll(vocs
);
81 public Set
<TermVocabulary
<DefinedTermBase
>> getVocabularies() {
85 public void updateDefaultFeatureTree() {
86 for(TermVocabulary vocab
: getVocabularies()) {
87 if(vocab
!= null && TermType
.Feature
.equals(vocab
.getTermType())) {
88 defaultFeatureTree
= null;
96 public Set
<TermVocabulary
<DefinedTermBase
>> getRootEntities() {
97 return getVocabularies();
103 public void merge() {
104 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
105 CdmStore
.getService(IVocabularyService
.class).merge(new ArrayList
<TermVocabulary
>(getRootEntities()), true);
106 updateDefaultFeatureTree();
110 public static FeatureTree
getDefaultFeatureTree() {
111 if(defaultFeatureTree
== null) {
112 defaultFeatureTree
= FeatureTree
.NewInstance(TermStore
.getTerms(Feature
.class));
114 return defaultFeatureTree
;