tableDefinition.addColumnDefinition(columnDef);
// Setup the cellEditor
RadioCellEditor<Boolean> cellEditor = new RadioCellEditor<Boolean>();
cellEditor.setLabel("Select a gender:");
cellEditor.addRadioButton(new RadioButton("editorGender", "male"), true);
cellEditor.addRadioButton(new RadioButton("editorGender", "female"),
false);
columnDef.setCellEditor(cellEditor);
}
// Race
{
StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>(
"Race", Group.GENERAL) {
@Override
public String getCellValue(Student rowValue) {
return rowValue.getRace();
}
@Override
public void setCellValue(Student rowValue, String cellValue) {
rowValue.setRace(cellValue);
}
};
columnDef.setMinimumColumnWidth(45);
columnDef.setPreferredColumnWidth(55);
columnDef.setMaximumColumnWidth(70);
columnDef.setColumnSortable(true);
tableDefinition.addColumnDefinition(columnDef);
// Setup the cell editor
ListCellEditor<String> cellEditor = new ListCellEditor<String>();
for (int i = 0; i < StudentGenerator.races.length; i++) {
String race = StudentGenerator.races[i];
cellEditor.addItem(race, race);
}
columnDef.setCellEditor(cellEditor);
}
// Favorite color
{
StudentColumnDefinition<String> columnDef = new StudentColumnDefinition<String>(
"Favorite Color", null) {
@Override
public String getCellValue(Student rowValue) {
return rowValue.getFavoriteColor();
}
@Override
public void setCellValue(Student rowValue, String cellValue) {
rowValue.setFavoriteColor(cellValue);
}
};
columnDef.setCellRenderer(new CellRenderer<Student, String>() {
public void renderRowValue(Student rowValue,
ColumnDefinition<Student, String> columnDef,
AbstractCellView<Student> view) {
String color = rowValue.getFavoriteColor();
view.setStyleAttribute("color", color);
view.setHTML(color);
}
});
columnDef.setPreferredColumnWidth(80);
columnDef.setColumnSortable(true);
columnDef.setHeaderTruncatable(false);
tableDefinition.addColumnDefinition(columnDef);
// Setup the cell editor
RadioCellEditor<String> cellEditor = new RadioCellEditor<String>();
cellEditor.setLabel("Select a color:");
for (int i = 0; i < StudentGenerator.colors.length; i++) {
String color = StudentGenerator.colors[i];
String text = "<FONT color=\"" + color + "\">" + color + "</FONT>";
cellEditor.addRadioButton(new RadioButton("editorColor", text, true),
color);
}
columnDef.setCellEditor(cellEditor);
}