// Grid
GridLayer gridLayer = new GridLayer(viewportLayer,
// columnHeaderLayer,
sortHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
// Uncomment to see the native tree list printed to stout.
// printTree(treeList, treeData);
columnHeaderDataLayer
.setConfigLabelAccumulator(new ColumnLabelAccumulator());
final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter = new ColumnHeaderCheckBoxPainter(
bodyDataLayer) {
@Override
protected Boolean convertDataType(ILayerCell cell,
IConfigRegistry configRegistry) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.isOn();
}
};
final ICellPainter checkBoxPainter = new TreeCheckBoxPainter() {
@Override
protected CheckBoxStateEnum getCheckBoxState(ILayerCell cell) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.getCheckBoxState();
}
};
natTable.addConfiguration(new AbstractRegistryConfiguration() {
public void configureRegistry(IConfigRegistry configRegistry) {
// Column header
configRegistry
.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new BeveledBorderDecorator(
new CellPainterDecorator(
new SortableHeaderTextPainter(),
CellEdgeEnum.LEFT,
columnHeaderCheckBoxPainter)),
DisplayMode.NORMAL,
ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 0);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new BackgroundPainter(new CellPainterDecorator(
new TextPainter() {
@Override
protected String convertDataType(
ILayerCell cell,
IConfigRegistry configRegistry) {
Datum dataValue = (Datum) cell
.getDataValue();
return dataValue.getName();
}
}, CellEdgeEnum.LEFT, checkBoxPainter)),
DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER,
new DefaultBooleanDisplayConverter(),
DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE,
IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT,
TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR,
new CheckBoxCellEditor() {
@Override
public void setCanonicalValue(Object canonicalValue) {
Datum value = (Datum) canonicalValue;
super.setCanonicalValue(value.isOn());
}
}, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
}
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstSingleClickBinding(
new CellPainterMouseEventMatcher(
GridRegion.COLUMN_HEADER,
MouseEventMatcher.LEFT_BUTTON,
columnHeaderCheckBoxPainter),
new ToggleCheckBoxColumnAction(
columnHeaderCheckBoxPainter, bodyDataLayer));
uiBindingRegistry
.registerFirstSingleClickBinding(
new CellPainterMouseEventMatcher(
GridRegion.BODY,
MouseEventMatcher.LEFT_BUTTON,
checkBoxPainter), new MouseEditAction());
uiBindingRegistry
.registerFirstMouseDragMode(
new CellPainterMouseEventMatcher(
GridRegion.BODY,
MouseEventMatcher.LEFT_BUTTON,
checkBoxPainter),
new CellEditDragMode());
}
});
natTable.configure();
return natTable;
}