...
Assuming that you have ONOS running on your local machine, you can install the app from the command line:
Code Block | ||
---|---|---|
| ||
$ onos-app localhost install! target/meowster-app-1.0-SNAPSHOT.oar |
...
(1) implement createRequestHandlers() to provide request handler implementations for specific event types from our view.
Code Block | ||||
---|---|---|---|---|
| ||||
@Override protected Collection<RequestHandler> createRequestHandlers() { return ImmutableSet.of( new SampleDataRequestHandler(), new SampleDetailRequestHandler() ); } |
...
(2) define SampleDataRequestHandler class to handle "sampleDataRequest" events from the client. Note that this class extends TableRequestHandler, which implements most of the functionality required to support the table data model:
Code Block | ||||
---|---|---|---|---|
| ||||
private static final String SAMPLE_DATA_REQ = "sampleDataRequest"; private static final String SAMPLE_DATA_RESP = "sampleDataResponse"; private static final String SAMPLES = "samples"; ... private final class SampleDataRequestHandler extends TableRequestHandler { private SampleDataRequestHandler() { super(SAMPLE_DATA_REQ, SAMPLE_DATA_RESP, SAMPLES); } ... } |
...
Typically, table rows have a unique value (row key) to identify the row (for example, in the Devices table it is the value of the Device.id() property). The default identifier for the column holding the row key is "id". If you want to use a different column identifier for the row key, your class should override defaultColumnId(). For example:
Code Block | ||||
---|---|---|---|---|
| ||||
private static final String MAC = "mac"; ... @Override protected String defaultColumnId() { return MAC; } |
...
(2b) define column identifiers:
Code Block | ||||
---|---|---|---|---|
| ||||
private static final String ID = "id"; private static final String LABEL = "label"; private static final String CODE = "code"; private static final String[] COLUMN_IDS = { ID, LABEL, CODE }; ... @Override protected String[] getColumnIds() { return COLUMN_IDS; } |
...
(2c) optionally override createTableModel() to specify custom cell formatters / comparators. The following example sets both a formatter and a comparator for the "code" column:
Code Block | ||||
---|---|---|---|---|
| ||||
@Override protected TableModel createTableModel() { TableModel tm = super.createTableModel(); tm.setFormatter(CODE, CodeFormatter.INSTANCE); tm.setComparator(CODE, CodeComparator.INSTANCE); return tm; } |
...
(2d) implement populateTable() to add rows to the supplied table model:
Code Block | ||||
---|---|---|---|---|
| ||||
@Override protected void populateTable(TableModel tm, ObjectNode payload) { // ... 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()); } |
...