new RegionStyles(BorderFactory.createSimpleBorder(new XYEdges(
1, 1, 1, 1), Border.STYLE_SOLID), null, null, null,
RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_TOP);
// Create the view and controller
final TableView tableView = new TableView(_tableModel);
final TableController tableController =
new TableController(_tableModel, tableView);
// Set the controller focus policy to highlight rows
tableController.setFocusPolicy(TableController.ROW_FOCUS);
// Set the behaviour of the controller when a table item is clicked
tableController.setCommand(new Command(new CommandHandler() {
/**
* @see CommandHandler#execute(ReadOnlyCommandMetadata, Object)
*/
public void execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
Dialog.alert("Command Executed");
}
}));
tableView.setController(tableController);
// Create a DataTemplate that suppresses the third column
final DataTemplate dataTemplate = new DataTemplate(tableView, 2, 3) {
/**
* @see DataTemplate#getDataFields(int)
*/
public Field[] getDataFields(final int modelRowIndex) {
final Object[] data =
(Object[]) ((TableModel) getView().getModel())
.getRow(modelRowIndex);
final Field[] fields = new Field[4];
fields[0] = new BitmapField((Bitmap) data[0]);
fields[1] =
new LabelField(data[1], Field.FOCUSABLE
| DrawStyle.HCENTER);
fields[2] = new LabelField(data[3], Field.FOCUSABLE);
fields[3] = new LabelField(data[4], Field.FOCUSABLE);
return fields;
}
};
// Set up regions
dataTemplate.createRegion(new XYRect(0, 0, 1, 2), style);
dataTemplate.createRegion(new XYRect(1, 0, 2, 1), style);
dataTemplate.createRegion(new XYRect(1, 1, 1, 1), style);
dataTemplate.createRegion(new XYRect(2, 1, 1, 1), style);
// Specify the size of each column by percentage, and the height of a
// row
dataTemplate.setColumnProperties(0, new TemplateColumnProperties(15,
TemplateColumnProperties.PERCENTAGE_WIDTH));
dataTemplate.setColumnProperties(1, new TemplateColumnProperties(15,
TemplateColumnProperties.PERCENTAGE_WIDTH));
dataTemplate.setColumnProperties(2, new TemplateColumnProperties(70,
TemplateColumnProperties.PERCENTAGE_WIDTH));
dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));
dataTemplate.setRowProperties(1, new TemplateRowProperties(ROW_HEIGHT));
// Apply the template to the view
tableView.setDataTemplate(dataTemplate);
dataTemplate.useFixedHeight(true);
add(tableView);
}