Project

General

Profile

Download (4.53 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.editor.key.polytomous;
11

    
12
import org.apache.commons.lang.StringUtils;
13
import org.eclipse.draw2d.IFigure;
14
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.swt.graphics.Color;
16
import org.eclipse.zest.core.viewers.IEntityStyleProvider;
17

    
18
import eu.etaxonomy.cdm.model.common.Language;
19
import eu.etaxonomy.cdm.model.description.KeyStatement;
20
import eu.etaxonomy.cdm.model.description.PolytomousKey;
21
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
22
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 * 
27
 * @author n.hoffmann
28
 * @created Mar 30, 2011
29
 * @version 1.0
30
 */
31
class PolytomousKeyLabelProvider extends LabelProvider implements
32
		IEntityStyleProvider {
33

    
34
	public static final String LEAF_BUT_NO_TAXON = "leaf but no taxon";
35
	public static final String NO_NODE_NUMBER = "No node number set";
36
	public static final String EMPTY = "";
37

    
38
	@Override
39
	public String getText(Object element) {
40
		if (element instanceof PolytomousKey) {
41
			return ((PolytomousKey) element).getTitleCache();
42
		} else if (element instanceof PolytomousKeyNode) {
43
			PolytomousKeyNode keyNode = (PolytomousKeyNode) element;
44

    
45
			if (keyNode.isLeaf()) {
46
				if (keyNode.getTaxon() != null) {
47
					return keyNode.getTaxon().getName().getTitleCache();
48
				}
49
				return LEAF_BUT_NO_TAXON;
50
			}
51

    
52
			if (keyNode.getNodeNumber() != null) {
53
				String statementLabel = "";
54
				String nodeNumber = keyNode.getNodeNumber().toString();
55

    
56
				KeyStatement question = keyNode.getQuestion();
57

    
58
				if (question != null) {
59
					statementLabel += " "
60
							+ question.getLabelText(CdmStore
61
									.getDefaultLanguage());
62
				}
63

    
64
				return String.format("%s. %s", nodeNumber, statementLabel);
65
			} else {
66
				return NO_NODE_NUMBER;
67
			}
68
		} else if (element instanceof PolytomousKeyRelationship) {
69
			PolytomousKeyRelationship relationship = (PolytomousKeyRelationship) element;
70
			if (relationship.getSource() instanceof PolytomousKeyNode) {
71
				PolytomousKeyNode destinationNode = (PolytomousKeyNode) relationship
72
						.getDestination();
73

    
74
				KeyStatement statement = destinationNode.getStatement();
75

    
76
				if (statement != null) {
77
					Language language = CdmStore.getDefaultLanguage();
78
					String statementLabel = statement.getLabelText(language);
79

    
80
					return StringUtils.isEmpty(statementLabel) ? EMPTY
81
							: statementLabel;
82
				}
83
			}
84
		}
85
		return EMPTY;
86
	}
87

    
88
	/*
89
	 * (non-Javadoc)
90
	 * 
91
	 * @see
92
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#fisheyeNode(java.lang
93
	 * .Object)
94
	 */
95
	@Override
96
	public boolean fisheyeNode(Object arg0) {
97
		// TODO Auto-generated method stub
98
		return false;
99
	}
100

    
101
	/*
102
	 * (non-Javadoc)
103
	 * 
104
	 * @see
105
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getBackgroundColour
106
	 * (java.lang.Object)
107
	 */
108
	@Override
109
	public Color getBackgroundColour(Object arg0) {
110
		// TODO Auto-generated method stub
111
		return null;
112
	}
113

    
114
	/*
115
	 * (non-Javadoc)
116
	 * 
117
	 * @see
118
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderColor(java
119
	 * .lang.Object)
120
	 */
121
	@Override
122
	public Color getBorderColor(Object arg0) {
123
		// TODO Auto-generated method stub
124
		return null;
125
	}
126

    
127
	/*
128
	 * (non-Javadoc)
129
	 * 
130
	 * @see
131
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderHighlightColor
132
	 * (java.lang.Object)
133
	 */
134
	@Override
135
	public Color getBorderHighlightColor(Object arg0) {
136
		// TODO Auto-generated method stub
137
		return null;
138
	}
139

    
140
	/*
141
	 * (non-Javadoc)
142
	 * 
143
	 * @see
144
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderWidth(java
145
	 * .lang.Object)
146
	 */
147
	@Override
148
	public int getBorderWidth(Object arg0) {
149
		return 0;
150
	}
151

    
152
	/*
153
	 * (non-Javadoc)
154
	 * 
155
	 * @see
156
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getForegroundColour
157
	 * (java.lang.Object)
158
	 */
159
	@Override
160
	public Color getForegroundColour(Object arg0) {
161
		// TODO Auto-generated method stub
162
		return null;
163
	}
164

    
165
	/*
166
	 * (non-Javadoc)
167
	 * 
168
	 * @see
169
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getNodeHighlightColor
170
	 * (java.lang.Object)
171
	 */
172
	@Override
173
	public Color getNodeHighlightColor(Object arg0) {
174
		// TODO Auto-generated method stub
175
		return null;
176
	}
177

    
178
	/*
179
	 * (non-Javadoc)
180
	 * 
181
	 * @see
182
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getTooltip(java.lang
183
	 * .Object)
184
	 */
185
	@Override
186
	public IFigure getTooltip(Object arg0) {
187
		return null;
188
	}
189
}
(6-6/11)