Committed by
Gerrit Code Review
[WIP][ONOS-3722] Augment TableModel with Annotations Mechanism
Change-Id: I815ce0b0fde254dd730153c34905d9454f019d9a
Showing
21 changed files
with
309 additions
and
9 deletions
... | @@ -57,6 +57,8 @@ public class DhcpViewMessageHandler extends UiMessageHandler { | ... | @@ -57,6 +57,8 @@ public class DhcpViewMessageHandler extends UiMessageHandler { |
57 | // handler for dhcp table requests | 57 | // handler for dhcp table requests |
58 | private final class DataRequestHandler extends TableRequestHandler { | 58 | private final class DataRequestHandler extends TableRequestHandler { |
59 | 59 | ||
60 | + private static final String NO_ROWS_MESSAGE = "No mappings found"; | ||
61 | + | ||
60 | private DataRequestHandler() { | 62 | private DataRequestHandler() { |
61 | super(DHCP_DATA_REQ, DHCP_DATA_RESP, DHCP); | 63 | super(DHCP_DATA_REQ, DHCP_DATA_RESP, DHCP); |
62 | } | 64 | } |
... | @@ -72,6 +74,11 @@ public class DhcpViewMessageHandler extends UiMessageHandler { | ... | @@ -72,6 +74,11 @@ public class DhcpViewMessageHandler extends UiMessageHandler { |
72 | } | 74 | } |
73 | 75 | ||
74 | @Override | 76 | @Override |
77 | + protected String noRowsMessage() { | ||
78 | + return NO_ROWS_MESSAGE; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
75 | protected void populateTable(TableModel tm, ObjectNode payload) { | 82 | protected void populateTable(TableModel tm, ObjectNode payload) { |
76 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); | 83 | DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class); |
77 | Map<HostId, IpAssignment> allocationMap = dhcpService.listMapping(); | 84 | Map<HostId, IpAssignment> allocationMap = dhcpService.listMapping(); | ... | ... |
... | @@ -63,6 +63,8 @@ public class DriverMatrixMessageHandler extends UiMessageHandler { | ... | @@ -63,6 +63,8 @@ public class DriverMatrixMessageHandler extends UiMessageHandler { |
63 | // handler for sample table requests | 63 | // handler for sample table requests |
64 | private final class SampleTableDataRequestHandler extends TableRequestHandler { | 64 | private final class SampleTableDataRequestHandler extends TableRequestHandler { |
65 | 65 | ||
66 | + private static final String NO_ROWS_MESSAGE = "No data found"; | ||
67 | + | ||
66 | private SampleTableDataRequestHandler() { | 68 | private SampleTableDataRequestHandler() { |
67 | super(SAMPLE_TABLE_DATA_REQ, SAMPLE_TABLE_DATA_RESP, SAMPLE_TABLES); | 69 | super(SAMPLE_TABLE_DATA_REQ, SAMPLE_TABLE_DATA_RESP, SAMPLE_TABLES); |
68 | } | 70 | } |
... | @@ -74,6 +76,11 @@ public class DriverMatrixMessageHandler extends UiMessageHandler { | ... | @@ -74,6 +76,11 @@ public class DriverMatrixMessageHandler extends UiMessageHandler { |
74 | return COLUMN_IDS; | 76 | return COLUMN_IDS; |
75 | } | 77 | } |
76 | 78 | ||
79 | + @Override | ||
80 | + protected String noRowsMessage() { | ||
81 | + return NO_ROWS_MESSAGE; | ||
82 | + } | ||
83 | + | ||
77 | // if required, override createTableModel() to set column formatters / comparators | 84 | // if required, override createTableModel() to set column formatters / comparators |
78 | 85 | ||
79 | @Override | 86 | @Override | ... | ... |
... | @@ -74,6 +74,8 @@ public class AlarmTableMessageHandler extends UiMessageHandler { | ... | @@ -74,6 +74,8 @@ public class AlarmTableMessageHandler extends UiMessageHandler { |
74 | // handler for alarm table requests | 74 | // handler for alarm table requests |
75 | private final class AlarmTableDataRequestHandler extends TableRequestHandler { | 75 | private final class AlarmTableDataRequestHandler extends TableRequestHandler { |
76 | 76 | ||
77 | + private static final String NO_ROWS_MESSAGE = "No alarms found"; | ||
78 | + | ||
77 | private AlarmTableDataRequestHandler() { | 79 | private AlarmTableDataRequestHandler() { |
78 | super(ALARM_TABLE_DATA_REQ, ALARM_TABLE_DATA_RESP, ALARM_TABLES); | 80 | super(ALARM_TABLE_DATA_REQ, ALARM_TABLE_DATA_RESP, ALARM_TABLES); |
79 | } | 81 | } |
... | @@ -90,6 +92,11 @@ public class AlarmTableMessageHandler extends UiMessageHandler { | ... | @@ -90,6 +92,11 @@ public class AlarmTableMessageHandler extends UiMessageHandler { |
90 | } | 92 | } |
91 | 93 | ||
92 | @Override | 94 | @Override |
95 | + protected String noRowsMessage() { | ||
96 | + return NO_ROWS_MESSAGE; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
93 | protected TableModel createTableModel() { | 100 | protected TableModel createTableModel() { |
94 | // if required, override createTableModel() to set column formatters / comparators | 101 | // if required, override createTableModel() to set column formatters / comparators |
95 | TableModel tm = super.createTableModel(); | 102 | TableModel tm = super.createTableModel(); | ... | ... |
... | @@ -22,6 +22,7 @@ import org.onosproject.ui.table.cell.DefaultCellFormatter; | ... | @@ -22,6 +22,7 @@ import org.onosproject.ui.table.cell.DefaultCellFormatter; |
22 | 22 | ||
23 | import java.util.ArrayList; | 23 | import java.util.ArrayList; |
24 | import java.util.Arrays; | 24 | import java.util.Arrays; |
25 | +import java.util.Collection; | ||
25 | import java.util.Collections; | 26 | import java.util.Collections; |
26 | import java.util.Comparator; | 27 | import java.util.Comparator; |
27 | import java.util.HashMap; | 28 | import java.util.HashMap; |
... | @@ -57,7 +58,7 @@ public class TableModel { | ... | @@ -57,7 +58,7 @@ public class TableModel { |
57 | private final Map<String, CellComparator> comparators = new HashMap<>(); | 58 | private final Map<String, CellComparator> comparators = new HashMap<>(); |
58 | private final Map<String, CellFormatter> formatters = new HashMap<>(); | 59 | private final Map<String, CellFormatter> formatters = new HashMap<>(); |
59 | private final List<Row> rows = new ArrayList<>(); | 60 | private final List<Row> rows = new ArrayList<>(); |
60 | - | 61 | + private final Map<String, Annot> annotations = new HashMap<>(); |
61 | 62 | ||
62 | /** | 63 | /** |
63 | * Constructs a table (devoid of data) with the given column IDs. | 64 | * Constructs a table (devoid of data) with the given column IDs. |
... | @@ -124,6 +125,28 @@ public class TableModel { | ... | @@ -124,6 +125,28 @@ public class TableModel { |
124 | } | 125 | } |
125 | 126 | ||
126 | /** | 127 | /** |
128 | + * Inserts a new annotation. | ||
129 | + * | ||
130 | + * @param key key of annotation | ||
131 | + * @param value value of annotation | ||
132 | + */ | ||
133 | + public void addAnnotation(String key, Object value) { | ||
134 | + Annot annot = new Annot(key, value); | ||
135 | + annotations.put(key, annot); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Returns the annotations in this table. | ||
140 | + * | ||
141 | + * @return annotations | ||
142 | + */ | ||
143 | + public Collection<Annot> getAnnotations() { | ||
144 | + Collection<Annot> annots = new ArrayList<>(annotations.size()); | ||
145 | + annotations.forEach((k, v) -> annots.add(v)); | ||
146 | + return annots; | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
127 | * Sets a cell comparator for the specified column. | 150 | * Sets a cell comparator for the specified column. |
128 | * | 151 | * |
129 | * @param columnId column identifier | 152 | * @param columnId column identifier |
... | @@ -233,6 +256,53 @@ public class TableModel { | ... | @@ -233,6 +256,53 @@ public class TableModel { |
233 | } | 256 | } |
234 | 257 | ||
235 | /** | 258 | /** |
259 | + * Model of an annotation. | ||
260 | + */ | ||
261 | + public class Annot { | ||
262 | + private final String key; | ||
263 | + private final Object value; | ||
264 | + | ||
265 | + /** | ||
266 | + * Constructs an annotation with the given key and value. | ||
267 | + * | ||
268 | + * @param key the key | ||
269 | + * @param value the value | ||
270 | + */ | ||
271 | + public Annot(String key, Object value) { | ||
272 | + this.key = key; | ||
273 | + this.value = value; | ||
274 | + } | ||
275 | + | ||
276 | + /** | ||
277 | + * Returns the annotation's key. | ||
278 | + * | ||
279 | + * @return key | ||
280 | + */ | ||
281 | + public String key() { | ||
282 | + return key; | ||
283 | + } | ||
284 | + | ||
285 | + /** | ||
286 | + * Returns the annotation's value. | ||
287 | + * | ||
288 | + * @return value | ||
289 | + */ | ||
290 | + public Object value() { | ||
291 | + return value; | ||
292 | + } | ||
293 | + | ||
294 | + /** | ||
295 | + * Returns the value as a string. | ||
296 | + * This default implementation uses the value's toString() method. | ||
297 | + * | ||
298 | + * @return the value as a string | ||
299 | + */ | ||
300 | + public String valueAsString() { | ||
301 | + return value.toString(); | ||
302 | + } | ||
303 | + } | ||
304 | + | ||
305 | + /** | ||
236 | * Model of a row. | 306 | * Model of a row. |
237 | */ | 307 | */ |
238 | public class Row { | 308 | public class Row { | ... | ... |
... | @@ -25,6 +25,8 @@ import org.onosproject.ui.RequestHandler; | ... | @@ -25,6 +25,8 @@ import org.onosproject.ui.RequestHandler; |
25 | */ | 25 | */ |
26 | public abstract class TableRequestHandler extends RequestHandler { | 26 | public abstract class TableRequestHandler extends RequestHandler { |
27 | 27 | ||
28 | + private static final String ANNOTS = "annots"; | ||
29 | + private static final String NO_ROWS_MSG_KEY = "no_rows_msg"; | ||
28 | private final String respType; | 30 | private final String respType; |
29 | private final String nodeName; | 31 | private final String nodeName; |
30 | 32 | ||
... | @@ -53,8 +55,11 @@ public abstract class TableRequestHandler extends RequestHandler { | ... | @@ -53,8 +55,11 @@ public abstract class TableRequestHandler extends RequestHandler { |
53 | String sortDir = JsonUtils.string(payload, "sortDir", "asc"); | 55 | String sortDir = JsonUtils.string(payload, "sortDir", "asc"); |
54 | tm.sort(sortCol, TableModel.sortDir(sortDir)); | 56 | tm.sort(sortCol, TableModel.sortDir(sortDir)); |
55 | 57 | ||
58 | + addTableConfigAnnotations(tm); | ||
59 | + | ||
56 | ObjectNode rootNode = MAPPER.createObjectNode(); | 60 | ObjectNode rootNode = MAPPER.createObjectNode(); |
57 | - rootNode.set(nodeName, TableUtils.generateArrayNode(tm)); | 61 | + rootNode.set(nodeName, TableUtils.generateRowArrayNode(tm)); |
62 | + rootNode.set(ANNOTS, TableUtils.generateAnnotObjectNode(tm)); | ||
58 | sendMessage(respType, 0, rootNode); | 63 | sendMessage(respType, 0, rootNode); |
59 | } | 64 | } |
60 | 65 | ||
... | @@ -72,6 +77,15 @@ public abstract class TableRequestHandler extends RequestHandler { | ... | @@ -72,6 +77,15 @@ public abstract class TableRequestHandler extends RequestHandler { |
72 | } | 77 | } |
73 | 78 | ||
74 | /** | 79 | /** |
80 | + * Adds all annotations to table model. | ||
81 | + * | ||
82 | + * @param tm a table model | ||
83 | + */ | ||
84 | + protected void addTableConfigAnnotations(TableModel tm) { | ||
85 | + tm.addAnnotation(NO_ROWS_MSG_KEY, noRowsMessage()); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
75 | * Returns the default column ID to be used when one is not supplied in | 89 | * Returns the default column ID to be used when one is not supplied in |
76 | * the payload as the column on which to sort. | 90 | * the payload as the column on which to sort. |
77 | * <p> | 91 | * <p> |
... | @@ -92,6 +106,15 @@ public abstract class TableRequestHandler extends RequestHandler { | ... | @@ -92,6 +106,15 @@ public abstract class TableRequestHandler extends RequestHandler { |
92 | protected abstract String[] getColumnIds(); | 106 | protected abstract String[] getColumnIds(); |
93 | 107 | ||
94 | /** | 108 | /** |
109 | + * Subclasses should return the message to display in the table when there | ||
110 | + * are no rows to display. For example, a host table might return | ||
111 | + * "No hosts found". | ||
112 | + * | ||
113 | + * @return the message | ||
114 | + */ | ||
115 | + protected abstract String noRowsMessage(); | ||
116 | + | ||
117 | + /** | ||
95 | * Subclasses should populate the table model by adding | 118 | * Subclasses should populate the table model by adding |
96 | * {@link TableModel.Row rows}. | 119 | * {@link TableModel.Row rows}. |
97 | * <pre> | 120 | * <pre> |
... | @@ -108,4 +131,4 @@ public abstract class TableRequestHandler extends RequestHandler { | ... | @@ -108,4 +131,4 @@ public abstract class TableRequestHandler extends RequestHandler { |
108 | * @param payload request payload | 131 | * @param payload request payload |
109 | */ | 132 | */ |
110 | protected abstract void populateTable(TableModel tm, ObjectNode payload); | 133 | protected abstract void populateTable(TableModel tm, ObjectNode payload); |
111 | -} | 134 | +} |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -32,12 +32,12 @@ public final class TableUtils { | ... | @@ -32,12 +32,12 @@ public final class TableUtils { |
32 | private TableUtils() { } | 32 | private TableUtils() { } |
33 | 33 | ||
34 | /** | 34 | /** |
35 | - * Generates a JSON array node from a table model. | 35 | + * Generates a JSON array node from the rows of the given table model. |
36 | * | 36 | * |
37 | * @param tm the table model | 37 | * @param tm the table model |
38 | - * @return the array node representation | 38 | + * @return the array node representation of rows |
39 | */ | 39 | */ |
40 | - public static ArrayNode generateArrayNode(TableModel tm) { | 40 | + public static ArrayNode generateRowArrayNode(TableModel tm) { |
41 | ArrayNode array = MAPPER.createArrayNode(); | 41 | ArrayNode array = MAPPER.createArrayNode(); |
42 | for (TableModel.Row r : tm.getRows()) { | 42 | for (TableModel.Row r : tm.getRows()) { |
43 | array.add(toJsonNode(r, tm)); | 43 | array.add(toJsonNode(r, tm)); |
... | @@ -45,6 +45,20 @@ public final class TableUtils { | ... | @@ -45,6 +45,20 @@ public final class TableUtils { |
45 | return array; | 45 | return array; |
46 | } | 46 | } |
47 | 47 | ||
48 | + /** | ||
49 | + * Generates a JSON object node from the annotations of the given table model. | ||
50 | + * | ||
51 | + * @param tm the table model | ||
52 | + * @return the object node representation of the annotations | ||
53 | + */ | ||
54 | + public static ObjectNode generateAnnotObjectNode(TableModel tm) { | ||
55 | + ObjectNode node = MAPPER.createObjectNode(); | ||
56 | + for (TableModel.Annot a : tm.getAnnotations()) { | ||
57 | + node.put(a.key(), a.valueAsString()); | ||
58 | + } | ||
59 | + return node; | ||
60 | + } | ||
61 | + | ||
48 | private static JsonNode toJsonNode(TableModel.Row row, TableModel tm) { | 62 | private static JsonNode toJsonNode(TableModel.Row row, TableModel tm) { |
49 | ObjectNode result = MAPPER.createObjectNode(); | 63 | ObjectNode result = MAPPER.createObjectNode(); |
50 | String[] keys = tm.getColumnIds(); | 64 | String[] keys = tm.getColumnIds(); | ... | ... |
... | @@ -21,6 +21,8 @@ import org.onosproject.ui.table.TableModel.SortDir; | ... | @@ -21,6 +21,8 @@ import org.onosproject.ui.table.TableModel.SortDir; |
21 | import org.onosproject.ui.table.cell.DefaultCellFormatter; | 21 | import org.onosproject.ui.table.cell.DefaultCellFormatter; |
22 | import org.onosproject.ui.table.cell.HexFormatter; | 22 | import org.onosproject.ui.table.cell.HexFormatter; |
23 | 23 | ||
24 | +import java.util.Collection; | ||
25 | + | ||
24 | import static org.junit.Assert.*; | 26 | import static org.junit.Assert.*; |
25 | 27 | ||
26 | /** | 28 | /** |
... | @@ -122,7 +124,6 @@ public class TableModelTest { | ... | @@ -122,7 +124,6 @@ public class TableModelTest { |
122 | assertEquals("bad cell", true, row.get(BAR)); | 124 | assertEquals("bad cell", true, row.get(BAR)); |
123 | } | 125 | } |
124 | 126 | ||
125 | - | ||
126 | private static final String ONE = "one"; | 127 | private static final String ONE = "one"; |
127 | private static final String TWO = "two"; | 128 | private static final String TWO = "two"; |
128 | private static final String THREE = "three"; | 129 | private static final String THREE = "three"; |
... | @@ -313,7 +314,6 @@ public class TableModelTest { | ... | @@ -313,7 +314,6 @@ public class TableModelTest { |
313 | assertEquals("null sort dir", SortDir.ASC, TableModel.sortDir(null)); | 314 | assertEquals("null sort dir", SortDir.ASC, TableModel.sortDir(null)); |
314 | } | 315 | } |
315 | 316 | ||
316 | - | ||
317 | @Test | 317 | @Test |
318 | public void enumSort() { | 318 | public void enumSort() { |
319 | tm = new TableModel(FOO); | 319 | tm = new TableModel(FOO); |
... | @@ -335,4 +335,83 @@ public class TableModelTest { | ... | @@ -335,4 +335,83 @@ public class TableModelTest { |
335 | assertEquals(UNEX_SORT + i, ordered[i], rows[i].get(FOO)); | 335 | assertEquals(UNEX_SORT + i, ordered[i], rows[i].get(FOO)); |
336 | } | 336 | } |
337 | } | 337 | } |
338 | + | ||
339 | + @Test | ||
340 | + public void stringAnnotation() { | ||
341 | + tm = new TableModel(FOO); | ||
342 | + tm.addAnnotation(BAR, ZOO); | ||
343 | + Collection<TableModel.Annot> annots = tm.getAnnotations(); | ||
344 | + assertEquals("wrong size", 1, annots.size()); | ||
345 | + | ||
346 | + TableModel.Annot annot = annots.iterator().next(); | ||
347 | + assertEquals("wrong key", BAR, annot.key()); | ||
348 | + assertEquals("wrong value", ZOO, annot.value()); | ||
349 | + } | ||
350 | + | ||
351 | + private static final String K_INT = "int"; | ||
352 | + private static final String K_BOOL = "bool"; | ||
353 | + private static final String K_FLOAT = "float"; | ||
354 | + private static final String K_DOUBLE = "double"; | ||
355 | + private static final String K_ENUM = "enum"; | ||
356 | + | ||
357 | + private TableModel.Annot getAnnotation(Collection<TableModel.Annot> annots, String key) { | ||
358 | + final TableModel.Annot[] annot = {null}; | ||
359 | + annots.forEach(a -> { | ||
360 | + if (a.key().equals(key)) { | ||
361 | + annot[0] = a; | ||
362 | + } | ||
363 | + }); | ||
364 | + return annot[0]; | ||
365 | + } | ||
366 | + | ||
367 | + private void verifyCollectionContains(Collection<TableModel.Annot> annots, | ||
368 | + String key, int i) { | ||
369 | + TableModel.Annot a = getAnnotation(annots, key); | ||
370 | + assertEquals("wrong int value", i, a.value()); | ||
371 | + } | ||
372 | + | ||
373 | + private void verifyCollectionContains(Collection<TableModel.Annot> annots, | ||
374 | + String key, boolean b) { | ||
375 | + TableModel.Annot a = getAnnotation(annots, key); | ||
376 | + assertEquals("wrong boolean value", b, a.value()); | ||
377 | + } | ||
378 | + | ||
379 | + private void verifyCollectionContains(Collection<TableModel.Annot> annots, | ||
380 | + String key, float f) { | ||
381 | + TableModel.Annot a = getAnnotation(annots, key); | ||
382 | + assertEquals("wrong float value", f, a.value()); | ||
383 | + } | ||
384 | + | ||
385 | + private void verifyCollectionContains(Collection<TableModel.Annot> annots, | ||
386 | + String key, double d) { | ||
387 | + TableModel.Annot a = getAnnotation(annots, key); | ||
388 | + assertEquals("wrong double value", d, a.value()); | ||
389 | + } | ||
390 | + | ||
391 | + private void verifyCollectionContains(Collection<TableModel.Annot> annots, | ||
392 | + String key, Enum<?> e) { | ||
393 | + TableModel.Annot a = getAnnotation(annots, key); | ||
394 | + assertEquals("wrong double value", e, a.value()); | ||
395 | + } | ||
396 | + | ||
397 | + @Test | ||
398 | + public void primitivesAnnotation() { | ||
399 | + tm = new TableModel(FOO); | ||
400 | + tm.addAnnotation(K_INT, 1); | ||
401 | + tm.addAnnotation(K_BOOL, true); | ||
402 | + tm.addAnnotation(K_FLOAT, 3.14f); | ||
403 | + tm.addAnnotation(K_DOUBLE, 2.71828); | ||
404 | + tm.addAnnotation(K_ENUM, StarWars.LUKE_SKYWALKER); | ||
405 | + | ||
406 | + Collection<TableModel.Annot> annots = tm.getAnnotations(); | ||
407 | + assertEquals("wrong size", 5, annots.size()); | ||
408 | + | ||
409 | + verifyCollectionContains(annots, K_INT, 1); | ||
410 | + verifyCollectionContains(annots, K_BOOL, true); | ||
411 | + verifyCollectionContains(annots, K_FLOAT, 3.14f); | ||
412 | + verifyCollectionContains(annots, K_DOUBLE, 2.71828); | ||
413 | + verifyCollectionContains(annots, K_ENUM, StarWars.LUKE_SKYWALKER); | ||
414 | + } | ||
415 | + | ||
416 | + // TODO: add support for compound object value | ||
338 | } | 417 | } | ... | ... |
... | @@ -37,7 +37,7 @@ public class TableUtilsTest { | ... | @@ -37,7 +37,7 @@ public class TableUtilsTest { |
37 | tm.addRow().cell(FOO, 1).cell(BAR, 2); | 37 | tm.addRow().cell(FOO, 1).cell(BAR, 2); |
38 | tm.addRow().cell(FOO, 3).cell(BAR, 4); | 38 | tm.addRow().cell(FOO, 3).cell(BAR, 4); |
39 | 39 | ||
40 | - ArrayNode array = TableUtils.generateArrayNode(tm); | 40 | + ArrayNode array = TableUtils.generateRowArrayNode(tm); |
41 | Assert.assertEquals("wrong results", ARRAY_AS_STRING, array.toString()); | 41 | Assert.assertEquals("wrong results", ARRAY_AS_STRING, array.toString()); |
42 | } | 42 | } |
43 | 43 | ... | ... |
... | @@ -66,6 +66,8 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { | ... | @@ -66,6 +66,8 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { |
66 | 66 | ||
67 | // handler for application table requests | 67 | // handler for application table requests |
68 | private final class AppDataRequest extends TableRequestHandler { | 68 | private final class AppDataRequest extends TableRequestHandler { |
69 | + private static final String NO_ROWS_MESSAGE = "No applications found"; | ||
70 | + | ||
69 | private AppDataRequest() { | 71 | private AppDataRequest() { |
70 | super(APP_DATA_REQ, APP_DATA_RESP, APPS); | 72 | super(APP_DATA_REQ, APP_DATA_RESP, APPS); |
71 | } | 73 | } |
... | @@ -76,6 +78,11 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { | ... | @@ -76,6 +78,11 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { |
76 | } | 78 | } |
77 | 79 | ||
78 | @Override | 80 | @Override |
81 | + protected String noRowsMessage() { | ||
82 | + return NO_ROWS_MESSAGE; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
79 | protected void populateTable(TableModel tm, ObjectNode payload) { | 86 | protected void populateTable(TableModel tm, ObjectNode payload) { |
80 | ApplicationService as = get(ApplicationService.class); | 87 | ApplicationService as = get(ApplicationService.class); |
81 | for (Application app : as.getApplications()) { | 88 | for (Application app : as.getApplications()) { | ... | ... |
... | @@ -60,6 +60,8 @@ public class ClusterViewMessageHandler extends UiMessageHandler { | ... | @@ -60,6 +60,8 @@ public class ClusterViewMessageHandler extends UiMessageHandler { |
60 | 60 | ||
61 | // handler for cluster table requests | 61 | // handler for cluster table requests |
62 | private final class ClusterDataRequest extends TableRequestHandler { | 62 | private final class ClusterDataRequest extends TableRequestHandler { |
63 | + private static final String NO_ROWS_MESSAGE = "No cluster nodes found"; | ||
64 | + | ||
63 | private ClusterDataRequest() { | 65 | private ClusterDataRequest() { |
64 | super(CLUSTER_DATA_REQ, CLUSTER_DATA_RESP, CLUSTERS); | 66 | super(CLUSTER_DATA_REQ, CLUSTER_DATA_RESP, CLUSTERS); |
65 | } | 67 | } |
... | @@ -70,6 +72,11 @@ public class ClusterViewMessageHandler extends UiMessageHandler { | ... | @@ -70,6 +72,11 @@ public class ClusterViewMessageHandler extends UiMessageHandler { |
70 | } | 72 | } |
71 | 73 | ||
72 | @Override | 74 | @Override |
75 | + protected String noRowsMessage() { | ||
76 | + return NO_ROWS_MESSAGE; | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
73 | protected TableModel createTableModel() { | 80 | protected TableModel createTableModel() { |
74 | TableModel tm = super.createTableModel(); | 81 | TableModel tm = super.createTableModel(); |
75 | tm.setFormatter(UPDATED, new TimeFormatter()); | 82 | tm.setFormatter(UPDATED, new TimeFormatter()); | ... | ... |
... | @@ -127,6 +127,8 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -127,6 +127,8 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
127 | 127 | ||
128 | // handler for device table requests | 128 | // handler for device table requests |
129 | private final class DataRequestHandler extends TableRequestHandler { | 129 | private final class DataRequestHandler extends TableRequestHandler { |
130 | + private static final String NO_ROWS_MESSAGE = "No devices found"; | ||
131 | + | ||
130 | private DataRequestHandler() { | 132 | private DataRequestHandler() { |
131 | super(DEV_DATA_REQ, DEV_DATA_RESP, DEVICES); | 133 | super(DEV_DATA_REQ, DEV_DATA_RESP, DEVICES); |
132 | } | 134 | } |
... | @@ -137,6 +139,11 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -137,6 +139,11 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
137 | } | 139 | } |
138 | 140 | ||
139 | @Override | 141 | @Override |
142 | + protected String noRowsMessage() { | ||
143 | + return NO_ROWS_MESSAGE; | ||
144 | + } | ||
145 | + | ||
146 | + @Override | ||
140 | protected void populateTable(TableModel tm, ObjectNode payload) { | 147 | protected void populateTable(TableModel tm, ObjectNode payload) { |
141 | DeviceService ds = get(DeviceService.class); | 148 | DeviceService ds = get(DeviceService.class); |
142 | MastershipService ms = get(MastershipService.class); | 149 | MastershipService ms = get(MastershipService.class); | ... | ... |
... | @@ -75,6 +75,8 @@ public class FlowViewMessageHandler extends UiMessageHandler { | ... | @@ -75,6 +75,8 @@ public class FlowViewMessageHandler extends UiMessageHandler { |
75 | // handler for flow table requests | 75 | // handler for flow table requests |
76 | private final class FlowDataRequest extends TableRequestHandler { | 76 | private final class FlowDataRequest extends TableRequestHandler { |
77 | 77 | ||
78 | + private static final String NO_ROWS_MESSAGE = "No flows found"; | ||
79 | + | ||
78 | private FlowDataRequest() { | 80 | private FlowDataRequest() { |
79 | super(FLOW_DATA_REQ, FLOW_DATA_RESP, FLOWS); | 81 | super(FLOW_DATA_REQ, FLOW_DATA_RESP, FLOWS); |
80 | } | 82 | } |
... | @@ -85,6 +87,11 @@ public class FlowViewMessageHandler extends UiMessageHandler { | ... | @@ -85,6 +87,11 @@ public class FlowViewMessageHandler extends UiMessageHandler { |
85 | } | 87 | } |
86 | 88 | ||
87 | @Override | 89 | @Override |
90 | + protected String noRowsMessage() { | ||
91 | + return NO_ROWS_MESSAGE; | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
88 | protected TableModel createTableModel() { | 95 | protected TableModel createTableModel() { |
89 | TableModel tm = super.createTableModel(); | 96 | TableModel tm = super.createTableModel(); |
90 | tm.setFormatter(ID, HexLongFormatter.INSTANCE); | 97 | tm.setFormatter(ID, HexLongFormatter.INSTANCE); | ... | ... |
... | @@ -65,6 +65,8 @@ public class GroupViewMessageHandler extends UiMessageHandler { | ... | @@ -65,6 +65,8 @@ public class GroupViewMessageHandler extends UiMessageHandler { |
65 | // handler for group table requests | 65 | // handler for group table requests |
66 | private final class GroupDataRequest extends TableRequestHandler { | 66 | private final class GroupDataRequest extends TableRequestHandler { |
67 | 67 | ||
68 | + private static final String NO_ROWS_MESSAGE = "No groups found"; | ||
69 | + | ||
68 | private GroupDataRequest() { | 70 | private GroupDataRequest() { |
69 | super(GROUP_DATA_REQ, GROUP_DATA_RESP, GROUPS); | 71 | super(GROUP_DATA_REQ, GROUP_DATA_RESP, GROUPS); |
70 | } | 72 | } |
... | @@ -75,6 +77,12 @@ public class GroupViewMessageHandler extends UiMessageHandler { | ... | @@ -75,6 +77,12 @@ public class GroupViewMessageHandler extends UiMessageHandler { |
75 | } | 77 | } |
76 | 78 | ||
77 | @Override | 79 | @Override |
80 | + protected String noRowsMessage() { | ||
81 | + // TODO: if devices with OF 1.0, should return not support message | ||
82 | + return NO_ROWS_MESSAGE; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
78 | protected TableModel createTableModel() { | 86 | protected TableModel createTableModel() { |
79 | TableModel tm = super.createTableModel(); | 87 | TableModel tm = super.createTableModel(); |
80 | tm.setFormatter(ID, HexFormatter.INSTANCE); | 88 | tm.setFormatter(ID, HexFormatter.INSTANCE); | ... | ... |
... | @@ -62,6 +62,8 @@ public class HostViewMessageHandler extends UiMessageHandler { | ... | @@ -62,6 +62,8 @@ public class HostViewMessageHandler extends UiMessageHandler { |
62 | 62 | ||
63 | // handler for host table requests | 63 | // handler for host table requests |
64 | private final class HostDataRequest extends TableRequestHandler { | 64 | private final class HostDataRequest extends TableRequestHandler { |
65 | + private static final String NO_ROWS_MESSAGE = "No hosts found"; | ||
66 | + | ||
65 | private HostDataRequest() { | 67 | private HostDataRequest() { |
66 | super(HOST_DATA_REQ, HOST_DATA_RESP, HOSTS); | 68 | super(HOST_DATA_REQ, HOST_DATA_RESP, HOSTS); |
67 | } | 69 | } |
... | @@ -72,6 +74,11 @@ public class HostViewMessageHandler extends UiMessageHandler { | ... | @@ -72,6 +74,11 @@ public class HostViewMessageHandler extends UiMessageHandler { |
72 | } | 74 | } |
73 | 75 | ||
74 | @Override | 76 | @Override |
77 | + protected String noRowsMessage() { | ||
78 | + return NO_ROWS_MESSAGE; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
75 | protected TableModel createTableModel() { | 82 | protected TableModel createTableModel() { |
76 | TableModel tm = super.createTableModel(); | 83 | TableModel tm = super.createTableModel(); |
77 | tm.setFormatter(LOCATION, HostLocationFormatter.INSTANCE); | 84 | tm.setFormatter(LOCATION, HostLocationFormatter.INSTANCE); | ... | ... |
... | @@ -71,6 +71,8 @@ public class IntentViewMessageHandler extends UiMessageHandler { | ... | @@ -71,6 +71,8 @@ public class IntentViewMessageHandler extends UiMessageHandler { |
71 | 71 | ||
72 | // handler for intent table requests | 72 | // handler for intent table requests |
73 | private final class IntentDataRequest extends TableRequestHandler { | 73 | private final class IntentDataRequest extends TableRequestHandler { |
74 | + private static final String NO_ROWS_MESSAGE = "No intents found"; | ||
75 | + | ||
74 | private IntentDataRequest() { | 76 | private IntentDataRequest() { |
75 | super(INTENT_DATA_REQ, INTENT_DATA_RESP, INTENTS); | 77 | super(INTENT_DATA_REQ, INTENT_DATA_RESP, INTENTS); |
76 | } | 78 | } |
... | @@ -86,6 +88,11 @@ public class IntentViewMessageHandler extends UiMessageHandler { | ... | @@ -86,6 +88,11 @@ public class IntentViewMessageHandler extends UiMessageHandler { |
86 | } | 88 | } |
87 | 89 | ||
88 | @Override | 90 | @Override |
91 | + protected String noRowsMessage() { | ||
92 | + return NO_ROWS_MESSAGE; | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
89 | protected TableModel createTableModel() { | 96 | protected TableModel createTableModel() { |
90 | TableModel tm = super.createTableModel(); | 97 | TableModel tm = super.createTableModel(); |
91 | tm.setFormatter(APP_ID, AppIdFormatter.INSTANCE); | 98 | tm.setFormatter(APP_ID, AppIdFormatter.INSTANCE); | ... | ... |
... | @@ -65,6 +65,8 @@ public class LinkViewMessageHandler extends UiMessageHandler { | ... | @@ -65,6 +65,8 @@ public class LinkViewMessageHandler extends UiMessageHandler { |
65 | 65 | ||
66 | // handler for link table requests | 66 | // handler for link table requests |
67 | private final class LinkDataRequest extends TableRequestHandler { | 67 | private final class LinkDataRequest extends TableRequestHandler { |
68 | + private static final String NO_ROWS_MESSAGE = "No links found"; | ||
69 | + | ||
68 | private LinkDataRequest() { | 70 | private LinkDataRequest() { |
69 | super(LINK_DATA_REQ, LINK_DATA_RESP, LINKS); | 71 | super(LINK_DATA_REQ, LINK_DATA_RESP, LINKS); |
70 | } | 72 | } |
... | @@ -75,6 +77,11 @@ public class LinkViewMessageHandler extends UiMessageHandler { | ... | @@ -75,6 +77,11 @@ public class LinkViewMessageHandler extends UiMessageHandler { |
75 | } | 77 | } |
76 | 78 | ||
77 | @Override | 79 | @Override |
80 | + protected String noRowsMessage() { | ||
81 | + return NO_ROWS_MESSAGE; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
78 | protected String defaultColumnId() { | 85 | protected String defaultColumnId() { |
79 | return ONE; | 86 | return ONE; |
80 | } | 87 | } | ... | ... |
... | @@ -61,6 +61,8 @@ public class MeterViewMessageHandler extends UiMessageHandler { | ... | @@ -61,6 +61,8 @@ public class MeterViewMessageHandler extends UiMessageHandler { |
61 | // handler for meter table requests | 61 | // handler for meter table requests |
62 | private final class MeterDataRequest extends TableRequestHandler { | 62 | private final class MeterDataRequest extends TableRequestHandler { |
63 | 63 | ||
64 | + private static final String NO_ROWS_MESSAGE = "No meters found"; | ||
65 | + | ||
64 | private MeterDataRequest() { | 66 | private MeterDataRequest() { |
65 | super(METER_DATA_REQ, METER_DATA_RESP, METERS); | 67 | super(METER_DATA_REQ, METER_DATA_RESP, METERS); |
66 | } | 68 | } |
... | @@ -71,6 +73,12 @@ public class MeterViewMessageHandler extends UiMessageHandler { | ... | @@ -71,6 +73,12 @@ public class MeterViewMessageHandler extends UiMessageHandler { |
71 | } | 73 | } |
72 | 74 | ||
73 | @Override | 75 | @Override |
76 | + protected String noRowsMessage() { | ||
77 | + // TODO: if the device with OF 1.0, return not support message | ||
78 | + return NO_ROWS_MESSAGE; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
74 | protected TableModel createTableModel() { | 82 | protected TableModel createTableModel() { |
75 | TableModel tm = super.createTableModel(); | 83 | TableModel tm = super.createTableModel(); |
76 | tm.setFormatter(ID, HexLongFormatter.INSTANCE); | 84 | tm.setFormatter(ID, HexLongFormatter.INSTANCE); | ... | ... |
... | @@ -62,6 +62,8 @@ public class PortViewMessageHandler extends UiMessageHandler { | ... | @@ -62,6 +62,8 @@ public class PortViewMessageHandler extends UiMessageHandler { |
62 | // handler for port table requests | 62 | // handler for port table requests |
63 | private final class PortDataRequest extends TableRequestHandler { | 63 | private final class PortDataRequest extends TableRequestHandler { |
64 | 64 | ||
65 | + private static final String NO_ROWS_MESSAGE = "No ports found"; | ||
66 | + | ||
65 | private PortDataRequest() { | 67 | private PortDataRequest() { |
66 | super(PORT_DATA_REQ, PORT_DATA_RESP, PORTS); | 68 | super(PORT_DATA_REQ, PORT_DATA_RESP, PORTS); |
67 | } | 69 | } |
... | @@ -72,6 +74,11 @@ public class PortViewMessageHandler extends UiMessageHandler { | ... | @@ -72,6 +74,11 @@ public class PortViewMessageHandler extends UiMessageHandler { |
72 | } | 74 | } |
73 | 75 | ||
74 | @Override | 76 | @Override |
77 | + protected String noRowsMessage() { | ||
78 | + return NO_ROWS_MESSAGE; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
75 | protected TableModel createTableModel() { | 82 | protected TableModel createTableModel() { |
76 | TableModel tm = super.createTableModel(); | 83 | TableModel tm = super.createTableModel(); |
77 | tm.setFormatter(PKT_RX, NumberFormatter.INTEGER); | 84 | tm.setFormatter(PKT_RX, NumberFormatter.INTEGER); | ... | ... |
... | @@ -64,6 +64,8 @@ public class ProcessorViewMessageHandler extends UiMessageHandler { | ... | @@ -64,6 +64,8 @@ public class ProcessorViewMessageHandler extends UiMessageHandler { |
64 | 64 | ||
65 | // handler for packet processor table requests | 65 | // handler for packet processor table requests |
66 | private final class ProcessorDataRequest extends TableRequestHandler { | 66 | private final class ProcessorDataRequest extends TableRequestHandler { |
67 | + private static final String NO_ROWS_MESSAGE = "No packet processors found"; | ||
68 | + | ||
67 | private ProcessorDataRequest() { | 69 | private ProcessorDataRequest() { |
68 | super(PROCESSOR_DATA_REQ, PROCESSOR_DATA_RESP, PROCESSORS); | 70 | super(PROCESSOR_DATA_REQ, PROCESSOR_DATA_RESP, PROCESSORS); |
69 | } | 71 | } |
... | @@ -74,6 +76,11 @@ public class ProcessorViewMessageHandler extends UiMessageHandler { | ... | @@ -74,6 +76,11 @@ public class ProcessorViewMessageHandler extends UiMessageHandler { |
74 | } | 76 | } |
75 | 77 | ||
76 | @Override | 78 | @Override |
79 | + protected String noRowsMessage() { | ||
80 | + return NO_ROWS_MESSAGE; | ||
81 | + } | ||
82 | + | ||
83 | + @Override | ||
77 | protected TableModel createTableModel() { | 84 | protected TableModel createTableModel() { |
78 | TableModel tm = super.createTableModel(); | 85 | TableModel tm = super.createTableModel(); |
79 | tm.setFormatter(AVG_MS, NumberFormatter.TO_5DP); | 86 | tm.setFormatter(AVG_MS, NumberFormatter.TO_5DP); | ... | ... |
... | @@ -53,6 +53,8 @@ public class SettingsViewMessageHandler extends UiMessageHandler { | ... | @@ -53,6 +53,8 @@ public class SettingsViewMessageHandler extends UiMessageHandler { |
53 | 53 | ||
54 | // handler for host table requests | 54 | // handler for host table requests |
55 | private final class SettingsRequest extends TableRequestHandler { | 55 | private final class SettingsRequest extends TableRequestHandler { |
56 | + private static final String NO_ROWS_MESSAGE = "No settings found"; | ||
57 | + | ||
56 | private SettingsRequest() { | 58 | private SettingsRequest() { |
57 | super(DATA_REQUEST, DATA_RESPONSE, SETTINGS); | 59 | super(DATA_REQUEST, DATA_RESPONSE, SETTINGS); |
58 | } | 60 | } |
... | @@ -63,6 +65,11 @@ public class SettingsViewMessageHandler extends UiMessageHandler { | ... | @@ -63,6 +65,11 @@ public class SettingsViewMessageHandler extends UiMessageHandler { |
63 | } | 65 | } |
64 | 66 | ||
65 | @Override | 67 | @Override |
68 | + protected String noRowsMessage() { | ||
69 | + return NO_ROWS_MESSAGE; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
66 | protected String defaultColumnId() { | 73 | protected String defaultColumnId() { |
67 | return COMPONENT; | 74 | return COMPONENT; |
68 | } | 75 | } | ... | ... |
... | @@ -55,6 +55,8 @@ public class TunnelViewMessageHandler extends UiMessageHandler { | ... | @@ -55,6 +55,8 @@ public class TunnelViewMessageHandler extends UiMessageHandler { |
55 | 55 | ||
56 | private final class TunnelDataRequestHandler extends TableRequestHandler { | 56 | private final class TunnelDataRequestHandler extends TableRequestHandler { |
57 | 57 | ||
58 | + private static final String NO_ROWS_MESSAGE = "No tunnels found"; | ||
59 | + | ||
58 | public TunnelDataRequestHandler() { | 60 | public TunnelDataRequestHandler() { |
59 | super(TUNNEL_DATA_REQ, TUNNEL_DATA_RESP, TUNNELS); | 61 | super(TUNNEL_DATA_REQ, TUNNEL_DATA_RESP, TUNNELS); |
60 | } | 62 | } |
... | @@ -65,6 +67,11 @@ public class TunnelViewMessageHandler extends UiMessageHandler { | ... | @@ -65,6 +67,11 @@ public class TunnelViewMessageHandler extends UiMessageHandler { |
65 | } | 67 | } |
66 | 68 | ||
67 | @Override | 69 | @Override |
70 | + protected String noRowsMessage() { | ||
71 | + return NO_ROWS_MESSAGE; | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
68 | protected TableModel createTableModel() { | 75 | protected TableModel createTableModel() { |
69 | TableModel tm = super.createTableModel(); | 76 | TableModel tm = super.createTableModel(); |
70 | //TODO add more formater class so that we can get a more readable table | 77 | //TODO add more formater class so that we can get a more readable table | ... | ... |
-
Please register or login to post a comment