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.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.events.SelectionAdapter;
|
15
|
import org.eclipse.swt.events.SelectionEvent;
|
16
|
import org.eclipse.swt.events.SelectionListener;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
import org.eclipse.swt.widgets.Label;
|
19
|
import org.eclipse.swt.widgets.Link;
|
20
|
import org.eclipse.ui.PartInitException;
|
21
|
import org.eclipse.ui.forms.IFormPart;
|
22
|
import org.eclipse.ui.forms.IManagedForm;
|
23
|
|
24
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
25
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
26
|
import eu.etaxonomy.cdm.model.description.KeyStatement;
|
27
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
29
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
30
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement;
|
33
|
|
34
|
/**
|
35
|
* @author n.hoffmann
|
36
|
* @created Apr 13, 2011
|
37
|
* @version 1.0
|
38
|
*/
|
39
|
public class PolytomousKeyListItem extends AbstractCdmFormElement implements
|
40
|
IFormPart {
|
41
|
|
42
|
private boolean dirty;
|
43
|
private final PolytomousKeyNode entity;
|
44
|
|
45
|
private SelectionListener linkSelectionListener;
|
46
|
|
47
|
/**
|
48
|
* @param formFactory
|
49
|
* @param layoutComposite
|
50
|
*/
|
51
|
protected PolytomousKeyListItem(CdmFormFactoryFacade formFactory,
|
52
|
Composite layoutComposite, PolytomousKeyNode entity) {
|
53
|
super(formFactory, layoutComposite);
|
54
|
|
55
|
// layoutComposite.setBackground(Display.getDefault().getSystemColor(
|
56
|
// SWT.COLOR_CYAN));
|
57
|
|
58
|
this.entity = (PolytomousKeyNode) HibernateProxyHelper.deproxy(entity);
|
59
|
|
60
|
Label label_nodeNumber = new Label(getLayoutComposite(), SWT.NULL);
|
61
|
label_nodeNumber.setText(getItemNumber());
|
62
|
|
63
|
Label label_question = new Label(getLayoutComposite(), SWT.NULL);
|
64
|
label_question.setText(getItemQuestion());
|
65
|
|
66
|
Label label_statement = new Label(getLayoutComposite(), SWT.NULL);
|
67
|
label_statement.setText(getItemStatement());
|
68
|
label_statement.setLayoutData(CdmFormFactoryFacade.FILL_HORIZONTALLY());
|
69
|
|
70
|
Link link = new Link(getLayoutComposite(), SWT.NONE);
|
71
|
link.setText("<a>" + getItemLink() + "</a>");
|
72
|
link.setData(getItemLinkData());
|
73
|
link.addSelectionListener(getLinkSelectionListener());
|
74
|
|
75
|
// Label label_link = new Label(getLayoutComposite(), SWT.NULL);
|
76
|
// label_link.setText(link);
|
77
|
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* @return
|
82
|
*/
|
83
|
private SelectionListener getLinkSelectionListener() {
|
84
|
if (linkSelectionListener == null) {
|
85
|
linkSelectionListener = new SelectionAdapter() {
|
86
|
/*
|
87
|
* (non-Javadoc)
|
88
|
*
|
89
|
* @see
|
90
|
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org
|
91
|
* .eclipse.swt.events.SelectionEvent)
|
92
|
*/
|
93
|
@Override
|
94
|
public void widgetSelected(SelectionEvent e) {
|
95
|
Object data = e.widget.getData();
|
96
|
|
97
|
if (data instanceof Taxon) {
|
98
|
try {
|
99
|
EditorUtil.openTaxonBase(((Taxon) data).getUuid());
|
100
|
} catch (PartInitException e1) {
|
101
|
// TODO Auto-generated catch block
|
102
|
e1.printStackTrace();
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
};
|
107
|
}
|
108
|
return linkSelectionListener;
|
109
|
}
|
110
|
|
111
|
private String getItemNumber() {
|
112
|
if (isParentRoot()) {
|
113
|
return "root";
|
114
|
} else {
|
115
|
PolytomousKeyNode parent = getParent();
|
116
|
String itemNumber = parent.getNodeNumber() != null ? parent
|
117
|
.getNodeNumber().toString() : "NaN";
|
118
|
|
119
|
int index = parent.getChildren().indexOf(entity);
|
120
|
|
121
|
for (int i = 0; i < index; i++) {
|
122
|
itemNumber += "'";
|
123
|
}
|
124
|
|
125
|
return itemNumber;
|
126
|
}
|
127
|
}
|
128
|
|
129
|
private String getItemQuestion() {
|
130
|
if (isParentRoot()) {
|
131
|
return "";
|
132
|
} else {
|
133
|
KeyStatement question = getParent().getQuestion();
|
134
|
return question != null ? question.getLabelText(CdmStore
|
135
|
.getDefaultLanguage()) : "";
|
136
|
}
|
137
|
|
138
|
}
|
139
|
|
140
|
private String getItemStatement() {
|
141
|
KeyStatement statement = entity.getStatement();
|
142
|
return statement != null ? CdmUtils.Nz(statement.getLabelText(CdmStore
|
143
|
.getDefaultLanguage())) : "No statement";
|
144
|
}
|
145
|
|
146
|
private String getItemLink() {
|
147
|
String taxonString = entity.getTaxon() != null ? entity.getTaxon()
|
148
|
.getName().getTitleCache() : "Taxon empty";
|
149
|
|
150
|
return entity.getChildren().isEmpty() ? taxonString : entity
|
151
|
.getNodeNumber().toString();
|
152
|
}
|
153
|
|
154
|
/**
|
155
|
* @return
|
156
|
*/
|
157
|
private Object getItemLinkData() {
|
158
|
return entity.getChildren().isEmpty() ? entity.getTaxon() : entity
|
159
|
.getChildAt(0);
|
160
|
}
|
161
|
|
162
|
private PolytomousKeyNode getParent() {
|
163
|
return entity.getParent();
|
164
|
}
|
165
|
|
166
|
private boolean isParentRoot() {
|
167
|
return getParent() == null;
|
168
|
}
|
169
|
|
170
|
/*
|
171
|
* (non-Javadoc)
|
172
|
*
|
173
|
* @see
|
174
|
* org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm
|
175
|
* )
|
176
|
*/
|
177
|
@Override
|
178
|
public void initialize(IManagedForm form) {
|
179
|
// TODO Auto-generated method stub
|
180
|
|
181
|
}
|
182
|
|
183
|
/*
|
184
|
* (non-Javadoc)
|
185
|
*
|
186
|
* @see org.eclipse.ui.forms.IFormPart#isDirty()
|
187
|
*/
|
188
|
@Override
|
189
|
public boolean isDirty() {
|
190
|
return dirty;
|
191
|
}
|
192
|
|
193
|
/*
|
194
|
* (non-Javadoc)
|
195
|
*
|
196
|
* @see org.eclipse.ui.forms.IFormPart#commit(boolean)
|
197
|
*/
|
198
|
@Override
|
199
|
public void commit(boolean onSave) {
|
200
|
// TODO Auto-generated method stub
|
201
|
|
202
|
}
|
203
|
|
204
|
/*
|
205
|
* (non-Javadoc)
|
206
|
*
|
207
|
* @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
|
208
|
*/
|
209
|
@Override
|
210
|
public boolean setFormInput(Object input) {
|
211
|
// TODO Auto-generated method stub
|
212
|
return false;
|
213
|
}
|
214
|
|
215
|
/*
|
216
|
* (non-Javadoc)
|
217
|
*
|
218
|
* @see org.eclipse.ui.forms.IFormPart#setFocus()
|
219
|
*/
|
220
|
@Override
|
221
|
public void setFocus() {
|
222
|
// TODO Auto-generated method stub
|
223
|
|
224
|
}
|
225
|
|
226
|
/*
|
227
|
* (non-Javadoc)
|
228
|
*
|
229
|
* @see org.eclipse.ui.forms.IFormPart#isStale()
|
230
|
*/
|
231
|
@Override
|
232
|
public boolean isStale() {
|
233
|
// TODO Auto-generated method stub
|
234
|
return false;
|
235
|
}
|
236
|
|
237
|
/*
|
238
|
* (non-Javadoc)
|
239
|
*
|
240
|
* @see org.eclipse.ui.forms.IFormPart#refresh()
|
241
|
*/
|
242
|
@Override
|
243
|
public void refresh() {
|
244
|
// TODO Auto-generated method stub
|
245
|
|
246
|
}
|
247
|
|
248
|
/*
|
249
|
* (non-Javadoc)
|
250
|
*
|
251
|
* @see eu.etaxonomy.taxeditor.ui.forms.ISelectable#setSelected(boolean)
|
252
|
*/
|
253
|
@Override
|
254
|
public void setSelected(boolean selected) {
|
255
|
// TODO Auto-generated method stub
|
256
|
|
257
|
}
|
258
|
|
259
|
/*
|
260
|
* (non-Javadoc)
|
261
|
*
|
262
|
* @see org.eclipse.ui.forms.IFormPart#dispose()
|
263
|
*/
|
264
|
@Override
|
265
|
public void dispose() {
|
266
|
// TODO Auto-generated method stub
|
267
|
|
268
|
}
|
269
|
|
270
|
/**
|
271
|
* @return the entity
|
272
|
*/
|
273
|
public PolytomousKeyNode getEntity() {
|
274
|
return entity;
|
275
|
}
|
276
|
|
277
|
}
|