use of org.eclipse.nebula.widgets.nattable.dataset.person.SimplePerson in project nebula.widgets.nattable by eclipse.
the class _001_Custom_styling_of_specific_cells method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
List<SimplePerson> myList = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
myList.add(new SimplePerson(i, "Joe" + i, new Date()));
}
String[] propertyNames = { "id", "name", "birthDate" };
IColumnPropertyAccessor<SimplePerson> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
ListDataProvider<SimplePerson> listDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
DefaultGridLayer gridLayer = new DefaultGridLayer(listDataProvider, new DummyColumnHeaderDataProvider(listDataProvider));
final DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
// Custom label "FOO" for cell at column, row index (1, 5)
IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
int columnIndex = bodyLayer.getColumnIndexByPosition(columnPosition);
int rowIndex = bodyLayer.getRowIndexByPosition(rowPosition);
if (columnIndex == 1 && rowIndex == 5) {
configLabels.addLabel(FOO_LABEL);
}
if (columnIndex == 1 && rowIndex == 10) {
configLabels.addLabel(BAR_LABEL);
}
// add labels for surrounding borders
if (rowIndex == 13) {
configLabels.addLabel(CustomLineBorderDecorator.TOP_LINE_BORDER_LABEL);
configLabels.addLabel(CustomLineBorderDecorator.BOTTOM_LINE_BORDER_LABEL);
if (columnIndex == 0) {
configLabels.addLabel(CustomLineBorderDecorator.LEFT_LINE_BORDER_LABEL);
}
if (columnIndex == 2) {
configLabels.addLabel(CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
}
}
}
};
bodyLayer.setConfigLabelAccumulator(cellLabelAccumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
// override the LineBorderDecorator here to show how to paint
// borders on single sides of a cell
this.cellPainter = new CustomLineBorderDecorator(new TextPainter());
// set a border style
this.borderStyle = new BorderStyle(2, GUIHelper.COLOR_BLUE, LineStyleEnum.DASHDOT);
}
});
// Custom style for label "FOO"
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_GREEN);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, FOO_LABEL);
cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE_STRIKETHROUGH);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, BAR_LABEL);
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.dataset.person.SimplePerson in project nebula.widgets.nattable by eclipse.
the class _001_Getting_Started method setupBodyDataProvider.
private IDataProvider setupBodyDataProvider() {
final List<SimplePerson> people = Arrays.asList(new SimplePerson(100, "Mickey Mouse", new Date(1000000)), new SimplePerson(110, "Batman", new Date(2000000)), new SimplePerson(120, "Bender", new Date(3000000)), new SimplePerson(130, "Cartman", new Date(4000000)), new SimplePerson(140, "Dogbert", new Date(5000000)));
this.propertyToLabels = new HashMap<>();
this.propertyToLabels.put("id", "ID");
this.propertyToLabels.put("name", "First Name");
this.propertyToLabels.put("birthDate", "DOB");
this.propertyNames = new String[] { "id", "name", "birthDate" };
return new ListDataProvider<>(people, new ReflectiveColumnPropertyAccessor<SimplePerson>(this.propertyNames));
}
Aggregations