Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

(2c) optionally override createTableModel() to provide specify custom cell formatters / comparators. The following example sets both a formatter and a comparator for the "code" column:

...

(2d) implement populateTable() by adding to add rows to the supplied table model:

Code Block
languagejava
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
    // ...

    // fake data for demonstration purposes...
    List<Item> items = getItems();
    for (Item item: items) {
        populateRow(tm.addRow(), item);
    }
}
 
private void populateRow(TableModel.Row row, Item item) {
    row.cell(ID, item.id())
            .cell(LABEL, item.label())
            .cell(CODE, item.code());
}

The example sample template uses fake data for demonstration purposes. A more realistic implementation would use one or more services to obtain the required data. For exampleThe device table, for example, has an implementation something like this:

Code Block
languagejava
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
    DeviceService ds = get(DeviceService.class);
    MastershipService ms = get(MastershipService.class);
    for (Device dev : ds.getDevices()) {
        populateRow(tm.addRow(), dev, ds, ms);
    }
}

private void populateRow(TableModel.Row row, Device dev,
                         DeviceService ds, MastershipService ms) {
    DeviceId id = dev.id();
    String protocol = dev.annotations().value(PROTOCOL);

    row.cell(ID, id)
        .cell(MFR, dev.manufacturer())
        .cell(HW, dev.hwVersion())
        .cell(SW, dev.swVersion())
        .cell(PROTOCOL, protocol != null ? protocol : "")
        .cell(NUM_PORTS, ds.getPorts(id).size())
        .cell(MASTER_ID, ms.getMasterFor(id));
    }
}