1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.key.polytomous;
|
12
|
|
13
|
import org.apache.commons.lang.StringUtils;
|
14
|
import org.eclipse.draw2d.IFigure;
|
15
|
import org.eclipse.jface.viewers.LabelProvider;
|
16
|
import org.eclipse.swt.graphics.Color;
|
17
|
import org.eclipse.zest.core.viewers.IEntityStyleProvider;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.common.Language;
|
20
|
import eu.etaxonomy.cdm.model.description.KeyStatement;
|
21
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
22
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
23
|
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
|
26
|
/**
|
27
|
*
|
28
|
* @author n.hoffmann
|
29
|
* @created Mar 30, 2011
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
class PolytomousKeyLabelProvider extends LabelProvider implements
|
33
|
IEntityStyleProvider {
|
34
|
|
35
|
public static final String LEAF_BUT_NO_TAXON = "leaf but no taxon";
|
36
|
public static final String NO_NODE_NUMBER = "No node number set";
|
37
|
public static final String EMPTY = "";
|
38
|
|
39
|
@Override
|
40
|
public String getText(Object element) {
|
41
|
if (element instanceof PolytomousKey) {
|
42
|
return ((PolytomousKey) element).getTitleCache();
|
43
|
} else if (element instanceof PolytomousKeyNode) {
|
44
|
PolytomousKeyNode keyNode = (PolytomousKeyNode) element;
|
45
|
|
46
|
if (keyNode.isLeaf()) {
|
47
|
if (keyNode.getTaxon() != null) {
|
48
|
return keyNode.getTaxon().getName().getTitleCache();
|
49
|
}
|
50
|
return LEAF_BUT_NO_TAXON;
|
51
|
}
|
52
|
|
53
|
if (keyNode.getNodeNumber() != null) {
|
54
|
String statementLabel = "";
|
55
|
String nodeNumber = keyNode.getNodeNumber().toString();
|
56
|
|
57
|
KeyStatement question = keyNode.getQuestion();
|
58
|
|
59
|
if (question != null) {
|
60
|
statementLabel += " "
|
61
|
+ question.getLabelText(CdmStore
|
62
|
.getDefaultLanguage());
|
63
|
}
|
64
|
|
65
|
return String.format("%s. %s", nodeNumber, statementLabel);
|
66
|
} else {
|
67
|
return NO_NODE_NUMBER;
|
68
|
}
|
69
|
} else if (element instanceof PolytomousKeyRelationship) {
|
70
|
PolytomousKeyRelationship relationship = (PolytomousKeyRelationship) element;
|
71
|
if (relationship.getSource() instanceof PolytomousKeyNode) {
|
72
|
PolytomousKeyNode destinationNode = (PolytomousKeyNode) relationship
|
73
|
.getDestination();
|
74
|
|
75
|
KeyStatement statement = destinationNode.getStatement();
|
76
|
|
77
|
if (statement != null) {
|
78
|
Language language = CdmStore.getDefaultLanguage();
|
79
|
String statementLabel = statement.getLabelText(language);
|
80
|
|
81
|
return StringUtils.isEmpty(statementLabel) ? EMPTY
|
82
|
: statementLabel;
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
return EMPTY;
|
87
|
}
|
88
|
|
89
|
/*
|
90
|
* (non-Javadoc)
|
91
|
*
|
92
|
* @see
|
93
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#fisheyeNode(java.lang
|
94
|
* .Object)
|
95
|
*/
|
96
|
@Override
|
97
|
public boolean fisheyeNode(Object arg0) {
|
98
|
// TODO Auto-generated method stub
|
99
|
return false;
|
100
|
}
|
101
|
|
102
|
/*
|
103
|
* (non-Javadoc)
|
104
|
*
|
105
|
* @see
|
106
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getBackgroundColour
|
107
|
* (java.lang.Object)
|
108
|
*/
|
109
|
@Override
|
110
|
public Color getBackgroundColour(Object arg0) {
|
111
|
// TODO Auto-generated method stub
|
112
|
return null;
|
113
|
}
|
114
|
|
115
|
/*
|
116
|
* (non-Javadoc)
|
117
|
*
|
118
|
* @see
|
119
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderColor(java
|
120
|
* .lang.Object)
|
121
|
*/
|
122
|
@Override
|
123
|
public Color getBorderColor(Object arg0) {
|
124
|
// TODO Auto-generated method stub
|
125
|
return null;
|
126
|
}
|
127
|
|
128
|
/*
|
129
|
* (non-Javadoc)
|
130
|
*
|
131
|
* @see
|
132
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderHighlightColor
|
133
|
* (java.lang.Object)
|
134
|
*/
|
135
|
@Override
|
136
|
public Color getBorderHighlightColor(Object arg0) {
|
137
|
// TODO Auto-generated method stub
|
138
|
return null;
|
139
|
}
|
140
|
|
141
|
/*
|
142
|
* (non-Javadoc)
|
143
|
*
|
144
|
* @see
|
145
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderWidth(java
|
146
|
* .lang.Object)
|
147
|
*/
|
148
|
@Override
|
149
|
public int getBorderWidth(Object arg0) {
|
150
|
return 0;
|
151
|
}
|
152
|
|
153
|
/*
|
154
|
* (non-Javadoc)
|
155
|
*
|
156
|
* @see
|
157
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getForegroundColour
|
158
|
* (java.lang.Object)
|
159
|
*/
|
160
|
@Override
|
161
|
public Color getForegroundColour(Object arg0) {
|
162
|
// TODO Auto-generated method stub
|
163
|
return null;
|
164
|
}
|
165
|
|
166
|
/*
|
167
|
* (non-Javadoc)
|
168
|
*
|
169
|
* @see
|
170
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getNodeHighlightColor
|
171
|
* (java.lang.Object)
|
172
|
*/
|
173
|
@Override
|
174
|
public Color getNodeHighlightColor(Object arg0) {
|
175
|
// TODO Auto-generated method stub
|
176
|
return null;
|
177
|
}
|
178
|
|
179
|
/*
|
180
|
* (non-Javadoc)
|
181
|
*
|
182
|
* @see
|
183
|
* org.eclipse.zest.core.viewers.IEntityStyleProvider#getTooltip(java.lang
|
184
|
* .Object)
|
185
|
*/
|
186
|
@Override
|
187
|
public IFigure getTooltip(Object arg0) {
|
188
|
return null;
|
189
|
}
|
190
|
}
|