Project

General

Profile

Download (4.44 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.view.uses;
2

    
3
import java.util.Arrays;
4
import java.util.List;
5
import java.util.Map;
6

    
7
import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
8

    
9
import org.eclipse.jface.viewers.ColumnLabelProvider;
10
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
11
import org.eclipse.jface.viewers.StyledString;
12

    
13
import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder;
14
import eu.etaxonomy.cdm.api.service.DescriptionBuilder;
15
import eu.etaxonomy.cdm.model.common.Language;
16
import eu.etaxonomy.cdm.model.common.LanguageString;
17
import eu.etaxonomy.cdm.model.description.CategoricalData;
18
import eu.etaxonomy.cdm.model.description.DescriptionBase;
19
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20
import eu.etaxonomy.cdm.model.description.Modifier;
21
import eu.etaxonomy.cdm.model.description.State;
22
import eu.etaxonomy.cdm.model.description.StateData;
23
import eu.etaxonomy.cdm.model.description.TextData;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
public class UsesLabelProvider extends ColumnLabelProvider implements
27
		IStyledLabelProvider {
28
	
29
	private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
30
	public String getText(Object element) {
31
		String text = "";
32
		/*
33
		 * return DescriptionHelper.getLabel(element);
34
		 * 
35
		 * for (Marker marker : element.getMarkers()) { if
36
		 * (marker.getMarkerType().getTitleCache().equals("use")) { return
37
		 * "Use: " + text; } }
38
		 */
39
		if (element instanceof DescriptionBase) {
40
			text = ((DescriptionBase) element).getTitleCache();
41
			if (text == null || text.length() == 0) {
42
				text = "Use: No label provided";
43
			}
44
			else {
45
				text = "Use: " + text;
46
			}
47
		}
48
		else if (element instanceof CategoricalData) {
49
			//String text = "";
50
			//TextData textData = categoricalDescriptionBuilder.build((CategoricalData) element, getLanguageList());
51
			if (!((CategoricalData) element).getStates().isEmpty()) {
52
				for (StateData statedata : ((CategoricalData) element).getStates()) {
53
					if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals("Use Category")) {
54
						text = text + statedata.getState().getTitleCache() + "; ";
55
					}
56
				}
57
				for (StateData statedata : ((CategoricalData) element).getStates()) {
58
					if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals("Use SubCategory")) {
59
						text = text + statedata.getState().getTitleCache() + "; ";
60
					}
61
				}
62
			}
63
			if (!((CategoricalData) element).getModifiers().isEmpty()) {
64
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
65
					if(GetVocabularyType(modifier, "Country")) {
66
						text = text +  modifier.getTitleCache()+ "; ";
67
					}
68
					
69
				}
70
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
71
					if(GetVocabularyType(modifier, "Plant Part")) {
72
						text = text +  modifier.getTitleCache()+ "; ";
73
					}
74
					
75
				}
76
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
77
					if(GetVocabularyType(modifier, "Human Group")) {
78
						text = text +  modifier.getTitleCache()+ "; ";
79
					}
80
					
81
				}
82
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
83
					if(GetVocabularyType(modifier, "Ethnic Group")) {
84
						text = text +  modifier.getTitleCache()+ "; ";
85
					}
86
					
87
				}
88
			}
89
		
90
			if (text == null || text.length() == 0) {
91
				text = "No data provided";
92
			}
93
			return text;
94
		}
95

    
96
		else{
97
			text = "Use Record";
98
		}
99

    
100
		return  text;
101
	}
102

    
103
	
104
	private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {
105
		if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
106
			return true;
107
		}
108
		else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
109
			return true;
110
		}
111
		return false;
112
	}
113
	@Override
114
	public StyledString getStyledText(Object element) {
115
		return new StyledString(this.getText(element),
116
				StyledString.QUALIFIER_STYLER);
117
	}
118
	
119
	private static List<Language> getLanguageList(){
120
		return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
121
	}
122

    
123
}
(2-2/3)