1
|
/**
|
2
|
* Copyright (C) 2011 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.view.uses;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
15
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
16
|
import org.eclipse.jface.viewers.StyledString;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
19
|
import eu.etaxonomy.cdm.model.common.Language;
|
20
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
21
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
22
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
23
|
import eu.etaxonomy.cdm.model.description.StateData;
|
24
|
import eu.etaxonomy.cdm.model.description.TextData;
|
25
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
import eu.etaxonomy.taxeditor.store.UsageTermCollection;
|
29
|
|
30
|
/**
|
31
|
* UsesLabelProvider Class
|
32
|
* @author a.theys
|
33
|
* @created mar 13, 2012
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class UsesLabelProvider extends ColumnLabelProvider implements
|
37
|
IStyledLabelProvider {
|
38
|
|
39
|
private static final String USE = Messages.UsesLabelProvider_USE;
|
40
|
private static final String NO_DATA_PROVIDED = Messages.UsesLabelProvider_NO_DATA;
|
41
|
private static final String SEMICOLON = ";"; //$NON-NLS-1$
|
42
|
|
43
|
/** {@inheritDoc} */
|
44
|
@Override
|
45
|
public String getText(Object element) {
|
46
|
String text = ""; //$NON-NLS-1$
|
47
|
|
48
|
if (element instanceof DescriptionBase) {
|
49
|
text = ((DescriptionBase) element).getTitleCache();
|
50
|
if (text == null || text.length() == 0) {
|
51
|
text = USE+Messages.UsesLabelProvider_NO_LABEL;
|
52
|
}
|
53
|
else {
|
54
|
text = USE + text;
|
55
|
}
|
56
|
}
|
57
|
else if (element instanceof CategoricalData) {
|
58
|
if (!((CategoricalData) element).getStateData().isEmpty()) {
|
59
|
boolean isUseCategoryAbsent = true;
|
60
|
for (StateData statedata : ((CategoricalData) element).getStateData()) {
|
61
|
if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
|
62
|
text = text + statedata.getState().getTitleCache() + SEMICOLON;
|
63
|
isUseCategoryAbsent = false;
|
64
|
}
|
65
|
}
|
66
|
if(isUseCategoryAbsent) {
|
67
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
68
|
}
|
69
|
|
70
|
boolean isUseSubCategoryAbsent = true;
|
71
|
for (StateData statedata : ((CategoricalData) element).getStateData()) {
|
72
|
if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
|
73
|
text = text + statedata.getState().getTitleCache() + SEMICOLON;
|
74
|
isUseSubCategoryAbsent = false;
|
75
|
}
|
76
|
}
|
77
|
if(isUseSubCategoryAbsent) {
|
78
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
79
|
}
|
80
|
}
|
81
|
else {
|
82
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
83
|
}
|
84
|
if (!((CategoricalData) element).getModifiers().isEmpty()) {
|
85
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
86
|
modifier.getPartOf();
|
87
|
modifier.getVocabulary();
|
88
|
}
|
89
|
|
90
|
boolean isPlantPartAbsent = true;
|
91
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
92
|
if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) {
|
93
|
text = text + modifier.getTitleCache()+ SEMICOLON;
|
94
|
isPlantPartAbsent = false;
|
95
|
}
|
96
|
|
97
|
}
|
98
|
if (isPlantPartAbsent) {
|
99
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
100
|
}
|
101
|
|
102
|
boolean isHumanGroupAbsent = true;
|
103
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
104
|
if(GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel)) {
|
105
|
text = text + modifier.getTitleCache()+ SEMICOLON;
|
106
|
isHumanGroupAbsent = false;
|
107
|
}
|
108
|
}
|
109
|
if (isHumanGroupAbsent) {
|
110
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
111
|
}
|
112
|
|
113
|
boolean isEthnicGroupAbsent = true;
|
114
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
115
|
if(GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) {
|
116
|
text = text + modifier.getTitleCache()+ SEMICOLON;
|
117
|
isEthnicGroupAbsent = false;
|
118
|
}
|
119
|
}
|
120
|
if (isEthnicGroupAbsent) {
|
121
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
122
|
}
|
123
|
|
124
|
boolean isCountryAbsent = true;
|
125
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
126
|
if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) {
|
127
|
text = text + modifier.getTitleCache()+ SEMICOLON;
|
128
|
isCountryAbsent = false;
|
129
|
}
|
130
|
}
|
131
|
if (isCountryAbsent) {
|
132
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
133
|
}
|
134
|
}
|
135
|
else {
|
136
|
text = text + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON + UsageTermCollection.notAvailableLabel + SEMICOLON;
|
137
|
}
|
138
|
|
139
|
if (text == null || text.length() == 0) {
|
140
|
text = NO_DATA_PROVIDED;
|
141
|
}
|
142
|
else {
|
143
|
String[] textElements = text.split(SEMICOLON);
|
144
|
String dataportalString = textElements[0] + SEMICOLON + textElements[1] + SEMICOLON + textElements[5] + SEMICOLON + textElements[2] + SEMICOLON + textElements[3] + SEMICOLON + textElements[4] + SEMICOLON ;
|
145
|
|
146
|
((CategoricalData)element).putModifyingText(CdmStore.getDefaultLanguage(), dataportalString);
|
147
|
}
|
148
|
return text;
|
149
|
}
|
150
|
|
151
|
else if (element instanceof TextData) {
|
152
|
List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
153
|
LanguageString languageString = ((TextData) element).getPreferredLanguageString(languages);
|
154
|
text = languageString != null ? languageString.getText() : null;
|
155
|
if (text == null || text.length() == 0) {
|
156
|
text = NO_DATA_PROVIDED;
|
157
|
}
|
158
|
}
|
159
|
|
160
|
else if (element instanceof FeatureNodeContainer){
|
161
|
text = ((FeatureNodeContainer)element).getFeature().getTitleCache();
|
162
|
}
|
163
|
|
164
|
return text;
|
165
|
}
|
166
|
|
167
|
/** Function dertmining which vocabulary is the term part of
|
168
|
*
|
169
|
* @param term
|
170
|
* @param vocabularyExpected
|
171
|
* @return
|
172
|
*/
|
173
|
private boolean GetVocabularyType(DefinedTerm term, String vocabularyExpected) {
|
174
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
|
175
|
return true;
|
176
|
}
|
177
|
else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
|
178
|
return true;
|
179
|
}
|
180
|
else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && ((term.getPartOf() != null))) {
|
181
|
return true;
|
182
|
}
|
183
|
return false;
|
184
|
}
|
185
|
|
186
|
/** {@inheritDoc} */
|
187
|
@Override
|
188
|
public StyledString getStyledText(Object element) {
|
189
|
return new StyledString(this.getText(element),
|
190
|
StyledString.QUALIFIER_STYLER);
|
191
|
}
|
192
|
|
193
|
|
194
|
|
195
|
}
|