1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.definedterm.input;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
|
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;
|
27
|
|
28
|
|
29
|
|
30
|
/**
|
31
|
* @author n.hoffmann
|
32
|
* @date Jan 24, 2012
|
33
|
*
|
34
|
*/
|
35
|
public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm> {
|
36
|
|
37
|
private TermType termType;
|
38
|
private Set<TermVocabulary<DefinedTermBase>> vocabularies;
|
39
|
|
40
|
// FIXME: the default feature should be move to CdmApplicationState
|
41
|
// where it is a singleton instance variable
|
42
|
private static FeatureTree defaultFeatureTree = null;
|
43
|
|
44
|
private List<String> termClasses = Arrays.asList(new String[]{
|
45
|
DefinedTerm.class.getName()
|
46
|
});
|
47
|
|
48
|
public TermEditorInput(TermType termType) {
|
49
|
this.termType = termType;
|
50
|
vocabularies = new HashSet<TermVocabulary<DefinedTermBase>>();
|
51
|
initialiseVocabularies();
|
52
|
}
|
53
|
/* (non-Javadoc)
|
54
|
* @see org.eclipse.ui.IEditorInput#getName()
|
55
|
*/
|
56
|
@Override
|
57
|
public String getName() {
|
58
|
return termType.getMessage();
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.taxeditor.editor.definedterm.input.AbstractDefinedTermEditorInput#getTermClasses()
|
63
|
*/
|
64
|
@Override
|
65
|
public List<String> getTermClasses() {
|
66
|
return termClasses;
|
67
|
}
|
68
|
|
69
|
public TermType getTermType() {
|
70
|
return termType;
|
71
|
}
|
72
|
|
73
|
public void initialiseVocabularies() {
|
74
|
if(vocabularies != null) {
|
75
|
vocabularies.clear();
|
76
|
}
|
77
|
List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(termType);
|
78
|
vocabularies.addAll(vocs);
|
79
|
}
|
80
|
|
81
|
public Set<TermVocabulary<DefinedTermBase>> getVocabularies() {
|
82
|
return vocabularies;
|
83
|
}
|
84
|
|
85
|
public void updateDefaultFeatureTree() {
|
86
|
for(TermVocabulary vocab : getVocabularies()) {
|
87
|
if(vocab != null && TermType.Feature.equals(vocab.getTermType())) {
|
88
|
defaultFeatureTree = null;
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
/**
|
93
|
* {@inheritDoc}
|
94
|
*/
|
95
|
@Override
|
96
|
public Set<TermVocabulary<DefinedTermBase>> getRootEntities() {
|
97
|
return getVocabularies();
|
98
|
}
|
99
|
/**
|
100
|
* {@inheritDoc}
|
101
|
*/
|
102
|
@Override
|
103
|
public void merge() {
|
104
|
if(CdmStore.getCurrentSessionManager().isRemoting()) {
|
105
|
CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()), true);
|
106
|
updateDefaultFeatureTree();
|
107
|
}
|
108
|
}
|
109
|
|
110
|
public static FeatureTree getDefaultFeatureTree() {
|
111
|
if(defaultFeatureTree == null) {
|
112
|
defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
|
113
|
}
|
114
|
return defaultFeatureTree;
|
115
|
}
|
116
|
}
|