Project

General

Profile

Download (4.75 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
					modifier.getPartOf();
66
					modifier.getVocabulary();
67
				}
68
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
69
					if(GetVocabularyType(modifier, "Country")) {
70
						text = text +  modifier.getTitleCache()+ "; ";
71
					}
72
					
73
				}
74
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
75
					if(GetVocabularyType(modifier, "Plant Part")) {
76
						text = text +  modifier.getTitleCache()+ "; ";
77
					}
78
					
79
				}
80
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
81
					if(GetVocabularyType(modifier, "Human Group")) {
82
						text = text +  modifier.getTitleCache()+ "; ";
83
					}
84
					
85
				}
86
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
87
					if(GetVocabularyType(modifier, "Ethnic Group")) {
88
						text = text +  modifier.getTitleCache()+ "; ";
89
					}
90
					
91
				}
92
			}
93
		
94
			if (text == null || text.length() == 0) {
95
				text = "No data provided";
96
			}
97
			return text;
98
		}
99

    
100
		else{
101
			text = "Use Record";
102
		}
103

    
104
		return  text;
105
	}
106

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

    
130
}
(2-2/3)