Project

General

Profile

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

    
3

    
4

    
5
import org.eclipse.jface.viewers.ColumnLabelProvider;
6
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
7
import org.eclipse.jface.viewers.StyledString;
8

    
9
import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder;
10
import eu.etaxonomy.cdm.api.service.DescriptionBuilder;
11
import eu.etaxonomy.cdm.model.description.CategoricalData;
12
import eu.etaxonomy.cdm.model.description.DescriptionBase;
13
import eu.etaxonomy.cdm.model.description.Modifier;
14
import eu.etaxonomy.cdm.model.description.StateData;
15
import eu.etaxonomy.taxeditor.store.CdmStore;
16

    
17
/**
18
 * The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
19
 *
20
 * @author a.theys	
21
 * @created mar 13, 2012
22
 * @version 1.0
23
 */
24
public class UsesLabelProvider extends ColumnLabelProvider implements
25
		IStyledLabelProvider {
26
	
27
	public String getText(Object element) {
28
		String text = "";
29

    
30
		if (element instanceof DescriptionBase) {
31
			text = ((DescriptionBase) element).getTitleCache();
32
			if (text == null || text.length() == 0) {
33
				text = "Use: No label provided";
34
			}
35
			else {
36
				text = "Use: " + text;
37
			}
38
		}
39
		else if (element instanceof CategoricalData) {
40
			if (!((CategoricalData) element).getStates().isEmpty()) {
41
				for (StateData statedata : ((CategoricalData) element).getStates()) {
42
					if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals("Use Category")) {
43
						text = text + statedata.getState().getTitleCache() + ";";
44
					}
45
				}
46
				for (StateData statedata : ((CategoricalData) element).getStates()) {
47
					if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals("Use SubCategory")) {
48
						text = text + statedata.getState().getTitleCache() + ";";
49
					}
50
				}
51
			}
52
			if (!((CategoricalData) element).getModifiers().isEmpty()) {
53
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
54
					modifier.getPartOf();
55
					modifier.getVocabulary();
56
				}
57
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
58
					if(GetVocabularyType(modifier, "Plant Part")) {
59
						text = text +  modifier.getTitleCache()+ ";";
60
					}
61
					
62
				}
63
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
64
					if(GetVocabularyType(modifier, "Human Group")) {
65
						text = text +  modifier.getTitleCache()+ ";";
66
					}
67
					
68
				}
69
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
70
					if(GetVocabularyType(modifier, "Ethnic Group")) {
71
						text = text +  modifier.getTitleCache()+ ";";
72
					}
73
					
74
				}
75
				for (Modifier modifier: ((CategoricalData) element).getModifiers()){
76
					if(GetVocabularyType(modifier, "Country")) {
77
						text = text +  modifier.getTitleCache()+ ";";
78
					}
79
					
80
				}
81
			}
82
		
83
			if (text == null || text.length() == 0) {
84
				text = "No data provided";
85
			}
86
			else {
87
				((CategoricalData)element).putModifyingText(CdmStore.getDefaultLanguage(), text);
88
			}
89
			return text;
90
		}
91

    
92
		else{
93
			text = "Use Record";
94
		}
95

    
96
		return  text;
97
	}
98

    
99
	
100
	private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {
101
		if ((term.getPartOf() != null)  && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
102
			return true;
103
		}
104
		else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
105
			return true;
106
		}
107
		else if ((vocabularyExpected.equals("Ethnic Group"))  && (term.getVocabulary() != null) && ((term.getPartOf() != null))) {
108
			return true;
109
		}
110
	return false;
111
	}
112
	@Override
113
	public StyledString getStyledText(Object element) {
114
		return new StyledString(this.getText(element),
115
				StyledString.QUALIFIER_STYLER);
116
	}
117
	
118
	
119

    
120
}
(2-2/3)