use of delta.common.ui.swing.tables.GenericTableController in project lotro-companion by dmorcellet.
the class CharacterLogTableController method buildTable.
private GenericTableController<CharacterLogItem> buildTable() {
DataProvider<CharacterLogItem> provider = new DataProvider<CharacterLogItem>() {
@Override
public CharacterLogItem getAt(int index) {
return _log.getLogItem(index);
}
@Override
public int getCount() {
return _log.getNbItems();
}
};
GenericTableController<CharacterLogItem> table = new GenericTableController<CharacterLogItem>(provider);
// Date column
{
CellDataProvider<CharacterLogItem, Date> dateCell = new CellDataProvider<CharacterLogItem, Date>() {
@Override
public Date getData(CharacterLogItem item) {
long timestamp = item.getDate();
return new Date(timestamp);
}
};
TableColumnController<CharacterLogItem, Date> dateColumn = new TableColumnController<CharacterLogItem, Date>("Date", Date.class, dateCell);
dateColumn.setWidthSpecs(100, 100, 50);
dateColumn.setCellRenderer(new DateRenderer(Formats.DATE_PATTERN));
table.addColumnController(dateColumn);
}
// Type column
{
CellDataProvider<CharacterLogItem, LogItemType> typeCell = new CellDataProvider<CharacterLogItem, LogItemType>() {
@Override
public LogItemType getData(CharacterLogItem item) {
return item.getLogItemType();
}
};
TableColumnController<CharacterLogItem, LogItemType> typeColumn = new TableColumnController<CharacterLogItem, LogItemType>("Type", LogItemType.class, typeCell);
typeColumn.setWidthSpecs(100, 100, 50);
typeColumn.setCellRenderer(new LogItemTypeRenderer());
typeColumn.setUseToString(Boolean.TRUE);
table.addColumnController(typeColumn);
}
// Label column
{
CellDataProvider<CharacterLogItem, String> labelCell = new CellDataProvider<CharacterLogItem, String>() {
@Override
public String getData(CharacterLogItem item) {
return item.getLabel();
}
};
TableColumnController<CharacterLogItem, String> labelColumn = new TableColumnController<CharacterLogItem, String>("Label", String.class, labelCell);
labelColumn.setWidthSpecs(150, -1, 150);
table.addColumnController(labelColumn);
}
return table;
}
Aggregations