Project

General

Profile

Download (5.03 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 java.util.Map;
13

    
14
import org.apache.commons.lang3.StringUtils;
15
import org.eclipse.draw2d.IFigure;
16
import org.eclipse.jface.viewers.LabelProvider;
17
import org.eclipse.swt.graphics.Color;
18
import org.eclipse.zest.core.viewers.IEntityStyleProvider;
19

    
20
import eu.etaxonomy.cdm.model.common.Language;
21
import eu.etaxonomy.cdm.model.common.LanguageString;
22
import eu.etaxonomy.cdm.model.description.KeyStatement;
23
import eu.etaxonomy.cdm.model.description.PolytomousKey;
24
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
25
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
26
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 *
31
 * @author n.hoffmann
32
 * @created Mar 30, 2011
33
 * @version 1.0
34
 */
35
public class PolytomousKeyLabelProvider extends LabelProvider implements
36
		IEntityStyleProvider {
37

    
38
	public static final String LEAF_BUT_NO_TAXON = Messages.PolytomousKeyLabelProvider_LEAF_BUT_NO_TAXON;
39
	public static final String NO_NODE_NUMBER = Messages.PolytomousKeyLabelProvider_NO_NODE_NUMBER_SET;
40
	public static final String EMPTY = ""; //$NON-NLS-1$
41

    
42
	@Override
43
	public String getText(Object element) {
44
		if (element instanceof PolytomousKey) {
45
			return ((PolytomousKey) element).getTitleCache();
46
		} else if (element instanceof PolytomousKeyNode) {
47
			PolytomousKeyNode keyNode = (PolytomousKeyNode) element;
48

    
49
			if (keyNode.isLeaf()) {
50
				if (keyNode.getTaxon() != null) {
51
					return keyNode.getTaxon().getName().getTitleCache();
52
				}
53
				return LEAF_BUT_NO_TAXON;
54
			}
55

    
56
			if (keyNode.getNodeNumber() != null) {
57
				String statementLabel = ""; //$NON-NLS-1$
58
				String nodeNumber = keyNode.getNodeNumber().toString();
59

    
60
				KeyStatement question = keyNode.getQuestion();
61

    
62
				if (question != null) {
63
					statementLabel += " " //$NON-NLS-1$
64
							+ question.getLabelText(CdmStore
65
									.getDefaultLanguage());
66
				}
67

    
68
				return String.format("%s. %s", nodeNumber, statementLabel); //$NON-NLS-1$
69
			} else {
70
				return NO_NODE_NUMBER;
71
			}
72
		} else if (element instanceof PolytomousKeyRelationship) {
73
			PolytomousKeyRelationship relationship = (PolytomousKeyRelationship) element;
74
			if (relationship.getSource() instanceof PolytomousKeyNode) {
75
				PolytomousKeyNode destinationNode = (PolytomousKeyNode) relationship
76
						.getDestination();
77

    
78
				KeyStatement statement = destinationNode.getStatement();
79

    
80
				if (statement != null) {
81
					Language language = CdmStore.getDefaultLanguage();
82
					String statementLabel = statement.getLabelText(language);
83
					if (StringUtils.isBlank(statementLabel)){
84
					    Map<Language, LanguageString> labels = statement.getLabel();
85
					    if (labels != null && !labels.isEmpty()){
86
					        statementLabel = labels.values().iterator().next().getText();
87
					    }
88
					}
89

    
90
					return StringUtils.isEmpty(statementLabel) ? EMPTY
91
							: statementLabel;
92
				}
93
			}
94
		}
95
		return EMPTY;
96
	}
97

    
98
	/*
99
	 * (non-Javadoc)
100
	 *
101
	 * @see
102
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#fisheyeNode(java.lang
103
	 * .Object)
104
	 */
105
	@Override
106
	public boolean fisheyeNode(Object arg0) {
107
		// TODO Auto-generated method stub
108
		return false;
109
	}
110

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

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

    
137
	/*
138
	 * (non-Javadoc)
139
	 *
140
	 * @see
141
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderHighlightColor
142
	 * (java.lang.Object)
143
	 */
144
	@Override
145
	public Color getBorderHighlightColor(Object arg0) {
146
		// TODO Auto-generated method stub
147
		return null;
148
	}
149

    
150
	/*
151
	 * (non-Javadoc)
152
	 *
153
	 * @see
154
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getBorderWidth(java
155
	 * .lang.Object)
156
	 */
157
	@Override
158
	public int getBorderWidth(Object arg0) {
159
		return 0;
160
	}
161

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

    
175
	/*
176
	 * (non-Javadoc)
177
	 *
178
	 * @see
179
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getNodeHighlightColor
180
	 * (java.lang.Object)
181
	 */
182
	@Override
183
	public Color getNodeHighlightColor(Object arg0) {
184
		// TODO Auto-generated method stub
185
		return null;
186
	}
187

    
188
	/*
189
	 * (non-Javadoc)
190
	 *
191
	 * @see
192
	 * org.eclipse.zest.core.viewers.IEntityStyleProvider#getTooltip(java.lang
193
	 * .Object)
194
	 */
195
	@Override
196
	public IFigure getTooltip(Object arg0) {
197
		return null;
198
	}
199
}
(5-5/8)