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