seedsTableViewer, SWT.NONE);
tvcSeedNumber.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Seed s = (Seed) element;
return Integer.toString(s.getIndex());
}
});
TableColumn tblclmnSeedNumber = tvcSeedNumber.getColumn();
tblclmnSeedNumber.setWidth(90);
tblclmnSeedNumber.setText("Seed Number");
tcLayout.setColumnData(tblclmnSeedNumber, new ColumnWeightData(40, 100, false));
TableViewerColumn tvcSeedValue = new TableViewerColumn(
seedsTableViewer, SWT.NONE);
tvcSeedValue.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Seed s = (Seed) element;
return s.toString();
}
});
TableColumn tblclmnSeedValue = tvcSeedValue.getColumn();
tblclmnSeedValue.setResizable(false);
tblclmnSeedValue.setWidth(120);
tblclmnSeedValue.setText("Seed Value");
tcLayout.setColumnData(tblclmnSeedValue, new ColumnWeightData(60, 120, false));
CellEditor[] editors = new CellEditor[] {
new TextCellEditor(t, SWT.READ_ONLY),
new TextCellEditor(t)
};
seedsTableViewer.setColumnProperties(new String[] { "index", "value" });
seedsTableViewer.setCellEditors(editors);
seedsTableViewer.setCellModifier(new ICellModifier() {
@Override
public boolean canModify(Object element, String property) {
return "value".equals(property);
}
@Override
public Object getValue(Object element, String property) {
Seed s = (Seed) element;
if ("value".equals(property)) {
return Integer.toString(s.getValue());
}
return null;
}
@Override
public void modify(Object element, String property, Object value) {
Seed s = (Seed) ((Item) element).getData();
if ("value".equals(property)) {
try {
s.setValue(Integer.parseInt((String) value));
seedsTableViewer.refresh();
} catch (NumberFormatException e) {
// Leave value unchanged.
}
}