1 |
729887cf
|
n.hoffmann
|
|
2 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.element;
|
3 |
729887cf
|
n.hoffmann
|
|
4 |
|
|
import java.util.Map;
|
5 |
|
|
import java.util.Map.Entry;
|
6 |
|
|
|
7 |
|
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
8 |
|
|
import org.eclipse.jface.viewers.ITableLabelProvider;
|
9 |
|
|
import org.eclipse.jface.viewers.LabelProvider;
|
10 |
|
|
import org.eclipse.jface.viewers.TableViewer;
|
11 |
|
|
import org.eclipse.jface.viewers.TableViewerColumn;
|
12 |
|
|
import org.eclipse.jface.viewers.Viewer;
|
13 |
|
|
import org.eclipse.swt.SWT;
|
14 |
|
|
import org.eclipse.swt.graphics.Image;
|
15 |
|
|
import org.eclipse.swt.widgets.Label;
|
16 |
|
|
import org.eclipse.swt.widgets.Table;
|
17 |
|
|
import org.eclipse.ui.forms.widgets.TableWrapData;
|
18 |
|
|
|
19 |
78222507
|
n.hoffmann
|
|
20 |
3be6ef3e
|
n.hoffmann
|
/**
|
21 |
|
|
* <p>KeyValueViewerElement class.</p>
|
22 |
|
|
*
|
23 |
|
|
* @author n.hoffmann
|
24 |
|
|
* @version $Id: $
|
25 |
|
|
*/
|
26 |
729887cf
|
n.hoffmann
|
public class KeyValueViewerElement extends AbstractCdmFormElement {
|
27 |
|
|
|
28 |
|
|
private TableViewer tableViewer;
|
29 |
|
|
|
30 |
|
|
private Label label;
|
31 |
|
|
|
32 |
3be6ef3e
|
n.hoffmann
|
/**
|
33 |
|
|
* <p>Constructor for KeyValueViewerElement.</p>
|
34 |
|
|
*
|
35 |
78222507
|
n.hoffmann
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
36 |
|
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
37 |
3be6ef3e
|
n.hoffmann
|
* @param keyHeading a {@link java.lang.String} object.
|
38 |
|
|
* @param valueHeading a {@link java.lang.String} object.
|
39 |
|
|
* @param map a {@link java.util.Map} object.
|
40 |
|
|
*/
|
41 |
729887cf
|
n.hoffmann
|
public KeyValueViewerElement(CdmFormFactory formFactory,
|
42 |
|
|
ICdmFormElement formElement, String keyHeading, String valueHeading, Map<Object, Object> map) {
|
43 |
|
|
super(formFactory, formElement);
|
44 |
|
|
|
45 |
|
|
label = formFactory.createLabel(getLayoutComposite(), "Meta Data");
|
46 |
23783f7a
|
n.hoffmann
|
label.setLayoutData(LayoutConstants.FILL(2, 1));
|
47 |
729887cf
|
n.hoffmann
|
addControl(label);
|
48 |
|
|
|
49 |
|
|
tableViewer = new TableViewer(formElement.getLayoutComposite(), SWT.MULTI | SWT.H_SCROLL
|
50 |
|
|
| SWT.V_SCROLL | SWT.FULL_SELECTION);
|
51 |
|
|
addControl(tableViewer.getControl());
|
52 |
|
|
|
53 |
|
|
createColumns(tableViewer, keyHeading, valueHeading);
|
54 |
|
|
|
55 |
23783f7a
|
n.hoffmann
|
TableWrapData layoutData = LayoutConstants.FILL(2, 1);
|
56 |
729887cf
|
n.hoffmann
|
layoutData.heightHint = 100;
|
57 |
|
|
|
58 |
|
|
tableViewer.getControl().setLayoutData(layoutData);
|
59 |
|
|
|
60 |
|
|
tableViewer.setContentProvider(new KeyValueContentProvider());
|
61 |
|
|
tableViewer.setLabelProvider(new KeyValueLabelProvider());
|
62 |
|
|
|
63 |
|
|
if(map != null){
|
64 |
|
|
setInput(map);
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
// This will create the columns for the table
|
70 |
|
|
private void createColumns(TableViewer viewer, String keyHeading, String valueHeading) {
|
71 |
|
|
Table table = viewer.getTable();
|
72 |
|
|
String[] titles = {keyHeading, valueHeading};
|
73 |
|
|
int[] bounds = { 100, 100};
|
74 |
|
|
|
75 |
|
|
for (int i = 0; i < titles.length; i++) {
|
76 |
|
|
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
|
77 |
|
|
column.getColumn().setText(titles[i]);
|
78 |
|
|
column.getColumn().setWidth(bounds[i]);
|
79 |
|
|
column.getColumn().setResizable(true);
|
80 |
|
|
column.getColumn().setMoveable(true);
|
81 |
|
|
}
|
82 |
|
|
table.setHeaderVisible(true);
|
83 |
|
|
table.setLinesVisible(true);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
|
87 |
3be6ef3e
|
n.hoffmann
|
/**
|
88 |
|
|
* <p>setInput</p>
|
89 |
|
|
*
|
90 |
|
|
* @param map a {@link java.util.Map} object.
|
91 |
|
|
*/
|
92 |
729887cf
|
n.hoffmann
|
public void setInput(Map<? extends Object, ? extends Object> map) {
|
93 |
|
|
tableViewer.setInput(map);
|
94 |
|
|
tableViewer.refresh();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
private class KeyValueContentProvider implements IStructuredContentProvider{
|
98 |
|
|
|
99 |
|
|
public Object[] getElements(Object inputElement) {
|
100 |
|
|
if(inputElement instanceof Map){
|
101 |
|
|
return ((Map) inputElement).entrySet().toArray();
|
102 |
|
|
}
|
103 |
|
|
return null;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
public void dispose() {}
|
107 |
|
|
|
108 |
|
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
109 |
|
|
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
private class KeyValueLabelProvider extends LabelProvider implements ITableLabelProvider{
|
113 |
|
|
|
114 |
|
|
public Image getColumnImage(Object element, int columnIndex) {
|
115 |
|
|
return null;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
public String getColumnText(Object element, int columnIndex) {
|
119 |
|
|
if(element instanceof Entry){
|
120 |
|
|
|
121 |
|
|
Entry entry = (Entry) element;
|
122 |
|
|
|
123 |
|
|
switch(columnIndex){
|
124 |
|
|
case 0:
|
125 |
|
|
return entry.getKey().toString();
|
126 |
|
|
case 1:
|
127 |
|
|
return entry.getValue().toString();
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
return element.toString();
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
}
|