Revision ad4930a1
Added by Niels Hoffmann about 13 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java | ||
---|---|---|
11 | 11 |
package eu.etaxonomy.taxeditor.editor.key.polytomous; |
12 | 12 |
|
13 | 13 |
import org.eclipse.core.runtime.IProgressMonitor; |
14 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
15 |
import org.eclipse.jface.viewers.TableViewer; |
|
16 |
import org.eclipse.jface.viewers.TableViewerColumn; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.swt.events.MouseAdapter; |
|
19 |
import org.eclipse.swt.events.MouseEvent; |
|
20 |
import org.eclipse.swt.graphics.Point; |
|
21 |
import org.eclipse.swt.graphics.Rectangle; |
|
22 |
import org.eclipse.swt.layout.FillLayout; |
|
14 | 23 |
import org.eclipse.swt.widgets.Composite; |
24 |
import org.eclipse.swt.widgets.Table; |
|
25 |
import org.eclipse.swt.widgets.TableItem; |
|
15 | 26 |
import org.eclipse.ui.IEditorInput; |
16 | 27 |
import org.eclipse.ui.IEditorSite; |
17 | 28 |
import org.eclipse.ui.PartInitException; |
... | ... | |
20 | 31 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
21 | 32 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
22 | 33 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
34 |
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; |
|
35 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
23 | 36 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
37 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
24 | 38 |
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory; |
25 | 39 |
|
26 | 40 |
/** |
... | ... | |
31 | 45 |
public class PolytomousKeyListEditor extends EditorPart implements |
32 | 46 |
IConversationEnabled { |
33 | 47 |
|
48 |
private class LinkListener extends MouseAdapter { |
|
49 |
/* |
|
50 |
* (non-Javadoc) |
|
51 |
* |
|
52 |
* @see |
|
53 |
* org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events |
|
54 |
* .MouseEvent) |
|
55 |
*/ |
|
56 |
@Override |
|
57 |
public void mouseUp(MouseEvent event) { |
|
58 |
|
|
59 |
Table table = (Table) event.widget; |
|
60 |
// Determine where the mouse was clicked |
|
61 |
Point pt = new Point(event.x, event.y); |
|
62 |
|
|
63 |
final TableItem item = table.getItem(pt); |
|
64 |
if (item != null) { |
|
65 |
// Determine which column was selected |
|
66 |
int column = -1; |
|
67 |
for (int i = 0, n = table.getColumnCount(); i < n; i++) { |
|
68 |
Rectangle rect = item.getBounds(i); |
|
69 |
if (rect.contains(pt)) { |
|
70 |
// This is the selected column |
|
71 |
column = i; |
|
72 |
break; |
|
73 |
} |
|
74 |
} |
|
75 |
if (column == 3) { |
|
76 |
PolytomousKeyNode node = (PolytomousKeyNode) item.getData(); |
|
77 |
Object linkData = getItemLinkData(node); |
|
78 |
if (linkData instanceof PolytomousKeyNode) { |
|
79 |
viewer.setSelection(new StructuredSelection(linkData), |
|
80 |
true); |
|
81 |
} else if (linkData instanceof Taxon) { |
|
82 |
try { |
|
83 |
EditorUtil.openTaxonBase(((Taxon) linkData) |
|
84 |
.getUuid()); |
|
85 |
} catch (PartInitException e) { |
|
86 |
EditorUtil.error(getClass(), e); |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* @return |
|
95 |
*/ |
|
96 |
private Object getItemLinkData(PolytomousKeyNode node) { |
|
97 |
return node.getChildren().isEmpty() ? node.getTaxon() : node |
|
98 |
.getChildAt(0); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
34 | 102 |
public static final String ID = "eu.etaxonomy.taxeditor.editor.key.polytomous.list"; |
35 | 103 |
|
36 | 104 |
private CdmFormFactory formFactory; |
37 | 105 |
private Composite container; |
38 | 106 |
|
39 |
private PolytomousKeyListViewer viewer;
|
|
107 |
private TableViewer viewer;
|
|
40 | 108 |
|
41 | 109 |
/* |
42 | 110 |
* (non-Javadoc) |
... | ... | |
127 | 195 |
*/ |
128 | 196 |
@Override |
129 | 197 |
public void createPartControl(Composite parent) { |
130 |
container = formFactory.createComposite(parent); |
|
131 | 198 |
|
132 |
viewer = new PolytomousKeyListViewer(container); |
|
199 |
FillLayout fillLayout = new FillLayout(); |
|
200 |
fillLayout.marginWidth = 0; |
|
201 |
fillLayout.marginHeight = 0; |
|
202 |
fillLayout.type = SWT.VERTICAL; |
|
203 |
parent.setLayout(fillLayout); |
|
204 |
|
|
205 |
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
|
206 |
| SWT.V_SCROLL | SWT.FULL_SELECTION); |
|
207 |
getSite().setSelectionProvider(viewer); |
|
208 |
|
|
209 |
createColumns(viewer); |
|
210 |
viewer.getControl().addMouseListener(new LinkListener()); |
|
211 |
viewer.setContentProvider(new PolytomousKeyListContentProvider()); |
|
212 |
viewer.setLabelProvider(new PolytomousKeyListLabelProvider()); |
|
213 |
|
|
214 |
// viewer.getControl().setLayoutData(CdmFormFactory.FILL()); |
|
215 |
|
|
133 | 216 |
PolytomousKey key = ((PolytomousKeyEditorInput) getEditorInput()) |
134 | 217 |
.getKey(); |
218 |
|
|
135 | 219 |
viewer.setInput(key); |
136 | 220 |
} |
137 | 221 |
|
222 |
// This will create the columns for the table |
|
223 |
private void createColumns(TableViewer viewer) { |
|
224 |
Table table = viewer.getTable(); |
|
225 |
String[] titles = { "Node Number", "Question", "Statement", "Link" }; |
|
226 |
int[] bounds = { 50, 200, 200, 100 }; |
|
227 |
|
|
228 |
for (int i = 0; i < titles.length; i++) { |
|
229 |
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); |
|
230 |
column.getColumn().setText(titles[i]); |
|
231 |
column.getColumn().setWidth(bounds[i]); |
|
232 |
column.getColumn().setResizable(true); |
|
233 |
column.getColumn().setMoveable(true); |
|
234 |
} |
|
235 |
table.setHeaderVisible(true); |
|
236 |
table.setLinesVisible(false); |
|
237 |
|
|
238 |
} |
|
239 |
|
|
138 | 240 |
/* |
139 | 241 |
* (non-Javadoc) |
140 | 242 |
* |
Also available in: Unified diff
Polytomous keys may be viewed as list as well