Committed by
Gerrit Code Review
GUI -- refactored all the table views (server side) to use the new TableModel me…
…thod of data generation. Change-Id: Ib8a188ad432ff335db6cff1e49e08dbaf039436b
Showing
28 changed files
with
639 additions
and
409 deletions
| ... | @@ -26,6 +26,7 @@ import java.util.Map; | ... | @@ -26,6 +26,7 @@ import java.util.Map; |
| 26 | /** | 26 | /** |
| 27 | * Provides a partial implementation of {@link TableRow}. | 27 | * Provides a partial implementation of {@link TableRow}. |
| 28 | */ | 28 | */ |
| 29 | +@Deprecated | ||
| 29 | public abstract class AbstractTableRow implements TableRow { | 30 | public abstract class AbstractTableRow implements TableRow { |
| 30 | 31 | ||
| 31 | private static final ObjectMapper MAPPER = new ObjectMapper(); | 32 | private static final ObjectMapper MAPPER = new ObjectMapper(); | ... | ... |
| ... | @@ -21,6 +21,7 @@ import java.util.Comparator; | ... | @@ -21,6 +21,7 @@ import java.util.Comparator; |
| 21 | /** | 21 | /** |
| 22 | * Comparator for {@link TableRow}. | 22 | * Comparator for {@link TableRow}. |
| 23 | */ | 23 | */ |
| 24 | +@Deprecated | ||
| 24 | public class RowComparator implements Comparator<TableRow> { | 25 | public class RowComparator implements Comparator<TableRow> { |
| 25 | /** Designates the sort direction. */ | 26 | /** Designates the sort direction. */ |
| 26 | public enum Direction { | 27 | public enum Direction { | ... | ... |
| ... | @@ -46,8 +46,8 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -46,8 +46,8 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 46 | */ | 46 | */ |
| 47 | public class TableModel { | 47 | public class TableModel { |
| 48 | 48 | ||
| 49 | - private static final CellComparator DEF_CMP = new DefaultCellComparator(); | 49 | + private static final CellComparator DEF_CMP = DefaultCellComparator.INSTANCE; |
| 50 | - private static final CellFormatter DEF_FMT = new DefaultCellFormatter(); | 50 | + private static final CellFormatter DEF_FMT = DefaultCellFormatter.INSTANCE; |
| 51 | 51 | ||
| 52 | private final String[] columnIds; | 52 | private final String[] columnIds; |
| 53 | private final Set<String> idSet; | 53 | private final Set<String> idSet; |
| ... | @@ -99,13 +99,16 @@ public class TableModel { | ... | @@ -99,13 +99,16 @@ public class TableModel { |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | /** | 101 | /** |
| 102 | - * Returns the {@link TableRow} representation of the rows in this table. | 102 | + * Returns the array of column IDs for this table model. |
| 103 | + * <p> | ||
| 104 | + * Implementation note: we are knowingly passing you a reference to | ||
| 105 | + * our internal array to avoid copying. Don't mess with it. It's your | ||
| 106 | + * table you'll break if you do! | ||
| 103 | * | 107 | * |
| 104 | - * @return formatted table rows | 108 | + * @return the column identifiers |
| 105 | */ | 109 | */ |
| 106 | - // TODO: still need to decide if we need this | 110 | + public String[] getColumnIds() { |
| 107 | - public TableRow[] getTableRows() { | 111 | + return columnIds; |
| 108 | - return new TableRow[0]; | ||
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | /** | 114 | /** |
| ... | @@ -113,7 +116,6 @@ public class TableModel { | ... | @@ -113,7 +116,6 @@ public class TableModel { |
| 113 | * | 116 | * |
| 114 | * @return raw table rows | 117 | * @return raw table rows |
| 115 | */ | 118 | */ |
| 116 | - // TODO: still need to decide if we should expose this | ||
| 117 | public Row[] getRows() { | 119 | public Row[] getRows() { |
| 118 | return rows.toArray(new Row[rows.size()]); | 120 | return rows.toArray(new Row[rows.size()]); |
| 119 | } | 121 | } |
| ... | @@ -264,9 +266,22 @@ public class TableModel { | ... | @@ -264,9 +266,22 @@ public class TableModel { |
| 264 | * @param columnId column identifier | 266 | * @param columnId column identifier |
| 265 | * @return formatted cell value | 267 | * @return formatted cell value |
| 266 | */ | 268 | */ |
| 267 | - public String getAsString(String columnId) { | 269 | + String getAsString(String columnId) { |
| 268 | return getFormatter(columnId).format(get(columnId)); | 270 | return getFormatter(columnId).format(get(columnId)); |
| 269 | } | 271 | } |
| 272 | + | ||
| 273 | + /** | ||
| 274 | + * Returns the row as an array of formatted strings. | ||
| 275 | + * | ||
| 276 | + * @return the formatted row data | ||
| 277 | + */ | ||
| 278 | + public String[] getAsFormattedStrings() { | ||
| 279 | + List<String> formatted = new ArrayList<>(columnCount()); | ||
| 280 | + for (String c : columnIds) { | ||
| 281 | + formatted.add(getAsString(c)); | ||
| 282 | + } | ||
| 283 | + return formatted.toArray(new String[formatted.size()]); | ||
| 284 | + } | ||
| 270 | } | 285 | } |
| 271 | 286 | ||
| 272 | private static final String DESC = "desc"; | 287 | private static final String DESC = "desc"; | ... | ... |
| ... | @@ -17,10 +17,9 @@ | ... | @@ -17,10 +17,9 @@ |
| 17 | package org.onosproject.ui.table; | 17 | package org.onosproject.ui.table; |
| 18 | 18 | ||
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | +import org.onosproject.ui.JsonUtils; | ||
| 20 | import org.onosproject.ui.RequestHandler; | 21 | import org.onosproject.ui.RequestHandler; |
| 21 | 22 | ||
| 22 | -import java.util.Arrays; | ||
| 23 | - | ||
| 24 | /** | 23 | /** |
| 25 | * Message handler specifically for table views. | 24 | * Message handler specifically for table views. |
| 26 | */ | 25 | */ |
| ... | @@ -47,29 +46,66 @@ public abstract class TableRequestHandler extends RequestHandler { | ... | @@ -47,29 +46,66 @@ public abstract class TableRequestHandler extends RequestHandler { |
| 47 | 46 | ||
| 48 | @Override | 47 | @Override |
| 49 | public void process(long sid, ObjectNode payload) { | 48 | public void process(long sid, ObjectNode payload) { |
| 50 | - RowComparator rc = TableUtils.createRowComparator(payload, defaultColId()); | 49 | + TableModel tm = createTableModel(); |
| 51 | - TableRow[] rows = generateTableRows(payload); | 50 | + populateTable(tm, payload); |
| 52 | - Arrays.sort(rows, rc); | 51 | + |
| 52 | + String sortCol = JsonUtils.string(payload, "sortCol", defaultColumnId()); | ||
| 53 | + String sortDir = JsonUtils.string(payload, "sortDir", "asc"); | ||
| 54 | + tm.sort(sortCol, TableModel.sortDir(sortDir)); | ||
| 55 | + | ||
| 53 | ObjectNode rootNode = MAPPER.createObjectNode(); | 56 | ObjectNode rootNode = MAPPER.createObjectNode(); |
| 54 | - rootNode.set(nodeName, TableUtils.generateArrayNode(rows)); | 57 | + rootNode.set(nodeName, TableUtils.generateArrayNode(tm)); |
| 55 | sendMessage(respType, 0, rootNode); | 58 | sendMessage(respType, 0, rootNode); |
| 56 | } | 59 | } |
| 57 | 60 | ||
| 58 | /** | 61 | /** |
| 59 | - * Returns the default column ID, when one is not supplied in the payload | 62 | + * Creates the table model (devoid of data) using {@link #getColumnIds()} |
| 60 | - * defining the column on which to sort. This implementation returns "id". | 63 | + * to initialize it, ready to be populated. |
| 64 | + * <p> | ||
| 65 | + * This default implementation returns a table model with default | ||
| 66 | + * formatters and comparators for all columns. | ||
| 67 | + * | ||
| 68 | + * @return an empty table model | ||
| 69 | + */ | ||
| 70 | + protected TableModel createTableModel() { | ||
| 71 | + return new TableModel(getColumnIds()); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * Returns the default column ID to be used when one is not supplied in | ||
| 76 | + * the payload as the column on which to sort. | ||
| 77 | + * <p> | ||
| 78 | + * This default implementation returns "id". | ||
| 61 | * | 79 | * |
| 62 | - * @return default sort column id | 80 | + * @return default sort column identifier |
| 63 | */ | 81 | */ |
| 64 | - protected String defaultColId() { | 82 | + protected String defaultColumnId() { |
| 65 | return "id"; | 83 | return "id"; |
| 66 | } | 84 | } |
| 67 | 85 | ||
| 68 | /** | 86 | /** |
| 69 | - * Subclasses should generate table rows for their specific table instance. | 87 | + * Subclasses should return the array of column IDs with which |
| 88 | + * to initialize their table model. | ||
| 89 | + * | ||
| 90 | + * @return the column IDs | ||
| 91 | + */ | ||
| 92 | + protected abstract String[] getColumnIds(); | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Subclasses should populate the table model by adding | ||
| 96 | + * {@link TableModel.Row rows}. | ||
| 97 | + * <pre> | ||
| 98 | + * tm.addRow() | ||
| 99 | + * .cell(COL_ONE, ...) | ||
| 100 | + * .cell(COL_TWO, ...) | ||
| 101 | + * ... ; | ||
| 102 | + * </pre> | ||
| 103 | + * The request payload is provided in case there are request filtering | ||
| 104 | + * parameters (other than sort column and sort direction) that are required | ||
| 105 | + * to generate the appropriate data. | ||
| 70 | * | 106 | * |
| 71 | - * @param payload provided in case custom parameters are present | 107 | + * @param tm the table model |
| 72 | - * @return generated table rows | 108 | + * @param payload request payload |
| 73 | */ | 109 | */ |
| 74 | - protected abstract TableRow[] generateTableRows(ObjectNode payload); | 110 | + protected abstract void populateTable(TableModel tm, ObjectNode payload); |
| 75 | } | 111 | } | ... | ... |
| ... | @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | /** | 22 | /** |
| 23 | * Defines a table row abstraction to support sortable tables on the GUI. | 23 | * Defines a table row abstraction to support sortable tables on the GUI. |
| 24 | */ | 24 | */ |
| 25 | +@Deprecated | ||
| 25 | public interface TableRow { | 26 | public interface TableRow { |
| 26 | 27 | ||
| 27 | // TODO: Define TableCell interface and return that, rather than String | 28 | // TODO: Define TableCell interface and return that, rather than String | ... | ... |
| ... | @@ -16,10 +16,10 @@ | ... | @@ -16,10 +16,10 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.ui.table; | 17 | package org.onosproject.ui.table; |
| 18 | 18 | ||
| 19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 21 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; | 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | -import org.onosproject.ui.JsonUtils; | ||
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * Provides static utility methods for dealing with tables. | 25 | * Provides static utility methods for dealing with tables. |
| ... | @@ -32,46 +32,27 @@ public final class TableUtils { | ... | @@ -32,46 +32,27 @@ public final class TableUtils { |
| 32 | private TableUtils() { } | 32 | private TableUtils() { } |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | - * Produces a JSON array node from the specified table rows. | 35 | + * Generates a JSON array node from a table model. |
| 36 | * | 36 | * |
| 37 | - * @param rows table rows | 37 | + * @param tm the table model |
| 38 | - * @return JSON array | 38 | + * @return the array node representation |
| 39 | */ | 39 | */ |
| 40 | - public static ArrayNode generateArrayNode(TableRow[] rows) { | 40 | + public static ArrayNode generateArrayNode(TableModel tm) { |
| 41 | ArrayNode array = MAPPER.createArrayNode(); | 41 | ArrayNode array = MAPPER.createArrayNode(); |
| 42 | - for (TableRow r : rows) { | 42 | + for (TableModel.Row r : tm.getRows()) { |
| 43 | - array.add(r.toJsonNode()); | 43 | + array.add(toJsonNode(r, tm)); |
| 44 | } | 44 | } |
| 45 | return array; | 45 | return array; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | - /** | 48 | + private static JsonNode toJsonNode(TableModel.Row row, TableModel tm) { |
| 49 | - * Creates a row comparator for the given request. The ID of the column | 49 | + ObjectNode result = MAPPER.createObjectNode(); |
| 50 | - * to sort on is the payload's "sortCol" property (defaults to "id"). | 50 | + String[] keys = tm.getColumnIds(); |
| 51 | - * The direction for the sort is the payload's "sortDir" property | 51 | + String[] cells = row.getAsFormattedStrings(); |
| 52 | - * (defaults to "asc"). | 52 | + int n = keys.length; |
| 53 | - * | 53 | + for (int i = 0; i < n; i++) { |
| 54 | - * @param payload the event payload | 54 | + result.put(keys[i], cells[i]); |
| 55 | - * @return a row comparator | 55 | + } |
| 56 | - */ | 56 | + return result; |
| 57 | - public static RowComparator createRowComparator(ObjectNode payload) { | ||
| 58 | - return createRowComparator(payload, "id"); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - /** | ||
| 62 | - * Creates a row comparator for the given request. The ID of the column to | ||
| 63 | - * sort on is the payload's "sortCol" property (or the specified default). | ||
| 64 | - * The direction for the sort is the payload's "sortDir" property | ||
| 65 | - * (defaults to "asc"). | ||
| 66 | - * | ||
| 67 | - * @param payload the event payload | ||
| 68 | - * @param defColId the default column ID | ||
| 69 | - * @return a row comparator | ||
| 70 | - */ | ||
| 71 | - public static RowComparator createRowComparator(ObjectNode payload, | ||
| 72 | - String defColId) { | ||
| 73 | - String sortCol = JsonUtils.string(payload, "sortCol", defColId); | ||
| 74 | - String sortDir = JsonUtils.string(payload, "sortDir", "asc"); | ||
| 75 | - return new RowComparator(sortCol, RowComparator.direction(sortDir)); | ||
| 76 | } | 57 | } |
| 77 | } | 58 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package org.onosproject.ui.table.cell; | ||
| 19 | + | ||
| 20 | +import org.onosproject.core.ApplicationId; | ||
| 21 | +import org.onosproject.ui.table.CellFormatter; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Formats an application identifier as "(app-id) : (app-name)". | ||
| 25 | + */ | ||
| 26 | +public class AppIdFormatter extends AbstractCellFormatter { | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + protected String nonNullFormat(Object value) { | ||
| 30 | + ApplicationId appId = (ApplicationId) value; | ||
| 31 | + return appId.id() + " : " + appId.name(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * An instance of this class. | ||
| 36 | + */ | ||
| 37 | + public static final CellFormatter INSTANCE = new AppIdFormatter(); | ||
| 38 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package org.onosproject.ui.table.cell; | ||
| 19 | + | ||
| 20 | +import org.onosproject.net.ConnectPoint; | ||
| 21 | +import org.onosproject.ui.table.CellFormatter; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Formats a connect point as "(element-id)/(port)". | ||
| 25 | + */ | ||
| 26 | +public class ConnectPointFormatter extends AbstractCellFormatter { | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + protected String nonNullFormat(Object value) { | ||
| 30 | + ConnectPoint cp = (ConnectPoint) value; | ||
| 31 | + return cp.elementId() + "/" + cp.port(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * An instance of this class. | ||
| 36 | + */ | ||
| 37 | + public static final CellFormatter INSTANCE = new ConnectPointFormatter(); | ||
| 38 | +} |
| ... | @@ -17,6 +17,8 @@ | ... | @@ -17,6 +17,8 @@ |
| 17 | 17 | ||
| 18 | package org.onosproject.ui.table.cell; | 18 | package org.onosproject.ui.table.cell; |
| 19 | 19 | ||
| 20 | +import org.onosproject.ui.table.CellComparator; | ||
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | * A default cell comparator. Implements a lexicographical compare function | 23 | * A default cell comparator. Implements a lexicographical compare function |
| 22 | * (i.e. string sorting). Uses the objects' toString() method and then | 24 | * (i.e. string sorting). Uses the objects' toString() method and then |
| ... | @@ -24,8 +26,14 @@ package org.onosproject.ui.table.cell; | ... | @@ -24,8 +26,14 @@ package org.onosproject.ui.table.cell; |
| 24 | * are considered "smaller" than any non-null value. | 26 | * are considered "smaller" than any non-null value. |
| 25 | */ | 27 | */ |
| 26 | public class DefaultCellComparator extends AbstractCellComparator { | 28 | public class DefaultCellComparator extends AbstractCellComparator { |
| 29 | + | ||
| 27 | @Override | 30 | @Override |
| 28 | protected int nonNullCompare(Object o1, Object o2) { | 31 | protected int nonNullCompare(Object o1, Object o2) { |
| 29 | return o1.toString().compareTo(o2.toString()); | 32 | return o1.toString().compareTo(o2.toString()); |
| 30 | } | 33 | } |
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * An instance of this class. | ||
| 37 | + */ | ||
| 38 | + public static final CellComparator INSTANCE = new DefaultCellComparator(); | ||
| 31 | } | 39 | } | ... | ... |
| ... | @@ -17,12 +17,20 @@ | ... | @@ -17,12 +17,20 @@ |
| 17 | 17 | ||
| 18 | package org.onosproject.ui.table.cell; | 18 | package org.onosproject.ui.table.cell; |
| 19 | 19 | ||
| 20 | +import org.onosproject.ui.table.CellFormatter; | ||
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | * A default cell formatter. Uses the object's toString() method. | 23 | * A default cell formatter. Uses the object's toString() method. |
| 22 | */ | 24 | */ |
| 23 | public class DefaultCellFormatter extends AbstractCellFormatter { | 25 | public class DefaultCellFormatter extends AbstractCellFormatter { |
| 26 | + | ||
| 24 | @Override | 27 | @Override |
| 25 | public String nonNullFormat(Object value) { | 28 | public String nonNullFormat(Object value) { |
| 26 | return value.toString(); | 29 | return value.toString(); |
| 27 | } | 30 | } |
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * An instance of this class. | ||
| 34 | + */ | ||
| 35 | + public static final CellFormatter INSTANCE = new DefaultCellFormatter(); | ||
| 28 | } | 36 | } | ... | ... |
| ... | @@ -17,12 +17,20 @@ | ... | @@ -17,12 +17,20 @@ |
| 17 | 17 | ||
| 18 | package org.onosproject.ui.table.cell; | 18 | package org.onosproject.ui.table.cell; |
| 19 | 19 | ||
| 20 | +import org.onosproject.ui.table.CellFormatter; | ||
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | - * Formats integer values as hex strings. | 23 | + * Formats integer values as hex strings with a "0x" prefix. |
| 22 | */ | 24 | */ |
| 23 | public class HexFormatter extends AbstractCellFormatter { | 25 | public class HexFormatter extends AbstractCellFormatter { |
| 26 | + | ||
| 24 | @Override | 27 | @Override |
| 25 | protected String nonNullFormat(Object value) { | 28 | protected String nonNullFormat(Object value) { |
| 26 | return "0x" + Integer.toHexString((Integer) value); | 29 | return "0x" + Integer.toHexString((Integer) value); |
| 27 | } | 30 | } |
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * An instance of this class. | ||
| 34 | + */ | ||
| 35 | + public static final CellFormatter INSTANCE = new HexFormatter(); | ||
| 28 | } | 36 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package org.onosproject.ui.table.cell; | ||
| 19 | + | ||
| 20 | +import org.onosproject.net.HostLocation; | ||
| 21 | +import org.onosproject.ui.table.CellFormatter; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Formats a host location as "(device-id)/(port)". | ||
| 25 | + */ | ||
| 26 | +public class HostLocationFormatter extends AbstractCellFormatter { | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + protected String nonNullFormat(Object value) { | ||
| 30 | + HostLocation loc = (HostLocation) value; | ||
| 31 | + return loc.deviceId() + "/" + loc.port(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * An instance of this class. | ||
| 36 | + */ | ||
| 37 | + public static final CellFormatter INSTANCE = new HostLocationFormatter(); | ||
| 38 | +} |
| ... | @@ -17,14 +17,22 @@ | ... | @@ -17,14 +17,22 @@ |
| 17 | 17 | ||
| 18 | package org.onosproject.ui.table.cell; | 18 | package org.onosproject.ui.table.cell; |
| 19 | 19 | ||
| 20 | +import org.onosproject.ui.table.CellComparator; | ||
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | * An integer-based cell comparator. | 23 | * An integer-based cell comparator. |
| 22 | * Note that null values are acceptable and are considered "smaller" than | 24 | * Note that null values are acceptable and are considered "smaller" than |
| 23 | * any non-null value. | 25 | * any non-null value. |
| 24 | */ | 26 | */ |
| 25 | public class IntComparator extends AbstractCellComparator { | 27 | public class IntComparator extends AbstractCellComparator { |
| 28 | + | ||
| 26 | @Override | 29 | @Override |
| 27 | protected int nonNullCompare(Object o1, Object o2) { | 30 | protected int nonNullCompare(Object o1, Object o2) { |
| 28 | return ((int) o1) - ((int) o2); | 31 | return ((int) o1) - ((int) o2); |
| 29 | } | 32 | } |
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * An instance of this class. | ||
| 36 | + */ | ||
| 37 | + public static final CellComparator INSTANCE = new IntComparator(); | ||
| 30 | } | 38 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package org.onosproject.ui.table.cell; | ||
| 19 | + | ||
| 20 | +import org.onosproject.ui.table.CellComparator; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * A long-based cell comparator. | ||
| 24 | + * Note that null values are acceptable and are considered "smaller" than | ||
| 25 | + * any non-null value. | ||
| 26 | + */ | ||
| 27 | +public class LongComparator extends AbstractCellComparator { | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + protected int nonNullCompare(Object o1, Object o2) { | ||
| 31 | + long diff = ((long) o1) - ((long) o2); | ||
| 32 | + return diff == 0 ? 0 : (diff < 0 ? -1 : 1); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * An instance of this class. | ||
| 37 | + */ | ||
| 38 | + public static final CellComparator INSTANCE = new LongComparator(); | ||
| 39 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +package org.onosproject.ui.table.cell; | ||
| 19 | + | ||
| 20 | +import org.joda.time.DateTime; | ||
| 21 | +import org.joda.time.format.DateTimeFormat; | ||
| 22 | +import org.joda.time.format.DateTimeFormatter; | ||
| 23 | +import org.onosproject.ui.table.CellFormatter; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Formats time values using {@link DateTimeFormatter}. | ||
| 27 | + */ | ||
| 28 | +public class TimeFormatter extends AbstractCellFormatter { | ||
| 29 | + | ||
| 30 | + private static final DateTimeFormatter DTF = DateTimeFormat.longTime(); | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + protected String nonNullFormat(Object value) { | ||
| 34 | + return DTF.print((DateTime) value); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * An instance of this class. | ||
| 39 | + */ | ||
| 40 | + public static final CellFormatter INSTANCE = new TimeFormatter(); | ||
| 41 | +} |
| ... | @@ -45,7 +45,6 @@ public class TableModelTest { | ... | @@ -45,7 +45,6 @@ public class TableModelTest { |
| 45 | private TableModel tm; | 45 | private TableModel tm; |
| 46 | private TableModel.Row[] rows; | 46 | private TableModel.Row[] rows; |
| 47 | private TableModel.Row row; | 47 | private TableModel.Row row; |
| 48 | - private TableRow[] tableRows; | ||
| 49 | private CellFormatter fmt; | 48 | private CellFormatter fmt; |
| 50 | 49 | ||
| 51 | @Test(expected = NullPointerException.class) | 50 | @Test(expected = NullPointerException.class) |
| ... | @@ -68,9 +67,6 @@ public class TableModelTest { | ... | @@ -68,9 +67,6 @@ public class TableModelTest { |
| 68 | tm = new TableModel(FOO, BAR); | 67 | tm = new TableModel(FOO, BAR); |
| 69 | assertEquals("column count", 2, tm.columnCount()); | 68 | assertEquals("column count", 2, tm.columnCount()); |
| 70 | assertEquals("row count", 0, tm.rowCount()); | 69 | assertEquals("row count", 0, tm.rowCount()); |
| 71 | - | ||
| 72 | - tableRows = tm.getTableRows(); | ||
| 73 | - assertEquals("row count alt", 0, tableRows.length); | ||
| 74 | } | 70 | } |
| 75 | 71 | ||
| 76 | @Test | 72 | @Test |
| ... | @@ -225,7 +221,7 @@ public class TableModelTest { | ... | @@ -225,7 +221,7 @@ public class TableModelTest { |
| 225 | initUnsortedTable(); | 221 | initUnsortedTable(); |
| 226 | 222 | ||
| 227 | // first, tell the table to use an integer-based comparator | 223 | // first, tell the table to use an integer-based comparator |
| 228 | - tm.setComparator(BAR, new IntComparator()); | 224 | + tm.setComparator(BAR, IntComparator.INSTANCE); |
| 229 | 225 | ||
| 230 | // sort by number | 226 | // sort by number |
| 231 | tm.sort(BAR, SortDir.ASC); | 227 | tm.sort(BAR, SortDir.ASC); |
| ... | @@ -256,8 +252,8 @@ public class TableModelTest { | ... | @@ -256,8 +252,8 @@ public class TableModelTest { |
| 256 | initUnsortedTable(); | 252 | initUnsortedTable(); |
| 257 | 253 | ||
| 258 | // set integer-based comparator and hex formatter | 254 | // set integer-based comparator and hex formatter |
| 259 | - tm.setComparator(BAR, new IntComparator()); | 255 | + tm.setComparator(BAR, IntComparator.INSTANCE); |
| 260 | - tm.setFormatter(BAR, new HexFormatter()); | 256 | + tm.setFormatter(BAR, HexFormatter.INSTANCE); |
| 261 | 257 | ||
| 262 | // sort by number | 258 | // sort by number |
| 263 | tm.sort(BAR, SortDir.ASC); | 259 | tm.sort(BAR, SortDir.ASC); | ... | ... |
| ... | @@ -39,7 +39,7 @@ public class DefaultCellComparatorTest { | ... | @@ -39,7 +39,7 @@ public class DefaultCellComparatorTest { |
| 39 | private static final int NUMBER = 42; | 39 | private static final int NUMBER = 42; |
| 40 | private static final TestClass OBJECT = new TestClass(); | 40 | private static final TestClass OBJECT = new TestClass(); |
| 41 | 41 | ||
| 42 | - private CellComparator cmp = new DefaultCellComparator(); | 42 | + private CellComparator cmp = DefaultCellComparator.INSTANCE; |
| 43 | 43 | ||
| 44 | @Test | 44 | @Test |
| 45 | public void sameString() { | 45 | public void sameString() { | ... | ... |
| ... | @@ -37,7 +37,7 @@ public class DefaultCellFormatterTest { | ... | @@ -37,7 +37,7 @@ public class DefaultCellFormatterTest { |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | - private CellFormatter fmt = new DefaultCellFormatter(); | 40 | + private CellFormatter fmt = DefaultCellFormatter.INSTANCE; |
| 41 | 41 | ||
| 42 | @Test | 42 | @Test |
| 43 | public void formatNull() { | 43 | public void formatNull() { | ... | ... |
| ... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
| 18 | package org.onosproject.ui.table.cell; | 18 | package org.onosproject.ui.table.cell; |
| 19 | 19 | ||
| 20 | import org.junit.Test; | 20 | import org.junit.Test; |
| 21 | +import org.onosproject.ui.table.CellFormatter; | ||
| 21 | 22 | ||
| 22 | import static org.junit.Assert.assertEquals; | 23 | import static org.junit.Assert.assertEquals; |
| 23 | 24 | ||
| ... | @@ -26,7 +27,7 @@ import static org.junit.Assert.assertEquals; | ... | @@ -26,7 +27,7 @@ import static org.junit.Assert.assertEquals; |
| 26 | */ | 27 | */ |
| 27 | public class HexFormatterTest { | 28 | public class HexFormatterTest { |
| 28 | 29 | ||
| 29 | - private HexFormatter fmt = new HexFormatter(); | 30 | + private CellFormatter fmt = HexFormatter.INSTANCE; |
| 30 | 31 | ||
| 31 | @Test | 32 | @Test |
| 32 | public void nullValue() { | 33 | public void nullValue() { | ... | ... |
| ... | @@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue; | ... | @@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue; |
| 27 | */ | 27 | */ |
| 28 | public class IntComparatorTest { | 28 | public class IntComparatorTest { |
| 29 | 29 | ||
| 30 | - private CellComparator cmp = new IntComparator(); | 30 | + private CellComparator cmp = IntComparator.INSTANCE; |
| 31 | 31 | ||
| 32 | @Test | 32 | @Test |
| 33 | public void twoNulls() { | 33 | public void twoNulls() { | ... | ... |
| ... | @@ -24,13 +24,10 @@ import org.onosproject.core.Application; | ... | @@ -24,13 +24,10 @@ import org.onosproject.core.Application; |
| 24 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.ui.RequestHandler; | 25 | import org.onosproject.ui.RequestHandler; |
| 26 | import org.onosproject.ui.UiMessageHandler; | 26 | import org.onosproject.ui.UiMessageHandler; |
| 27 | -import org.onosproject.ui.table.AbstractTableRow; | 27 | +import org.onosproject.ui.table.TableModel; |
| 28 | import org.onosproject.ui.table.TableRequestHandler; | 28 | import org.onosproject.ui.table.TableRequestHandler; |
| 29 | -import org.onosproject.ui.table.TableRow; | ||
| 30 | 29 | ||
| 31 | import java.util.Collection; | 30 | import java.util.Collection; |
| 32 | -import java.util.List; | ||
| 33 | -import java.util.stream.Collectors; | ||
| 34 | 31 | ||
| 35 | import static org.onosproject.app.ApplicationState.ACTIVE; | 32 | import static org.onosproject.app.ApplicationState.ACTIVE; |
| 36 | 33 | ||
| ... | @@ -55,6 +52,10 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { | ... | @@ -55,6 +52,10 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { |
| 55 | private static final String ICON_ID_ACTIVE = "active"; | 52 | private static final String ICON_ID_ACTIVE = "active"; |
| 56 | private static final String ICON_ID_INACTIVE = "appInactive"; | 53 | private static final String ICON_ID_INACTIVE = "appInactive"; |
| 57 | 54 | ||
| 55 | + private static final String[] COL_IDS = { | ||
| 56 | + STATE, STATE_IID, ID, VERSION, ORIGIN, DESC | ||
| 57 | + }; | ||
| 58 | + | ||
| 58 | @Override | 59 | @Override |
| 59 | protected Collection<RequestHandler> getHandlers() { | 60 | protected Collection<RequestHandler> getHandlers() { |
| 60 | return ImmutableSet.of( | 61 | return ImmutableSet.of( |
| ... | @@ -70,14 +71,31 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { | ... | @@ -70,14 +71,31 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | @Override | 73 | @Override |
| 73 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 74 | + protected String[] getColumnIds() { |
| 74 | - ApplicationService service = get(ApplicationService.class); | 75 | + return COL_IDS; |
| 75 | - List<TableRow> list = service.getApplications().stream() | 76 | + } |
| 76 | - .map(application -> new ApplicationTableRow(service, application)) | 77 | + |
| 77 | - .collect(Collectors.toList()); | 78 | + @Override |
| 78 | - return list.toArray(new TableRow[list.size()]); | 79 | + protected void populateTable(TableModel tm, ObjectNode payload) { |
| 80 | + ApplicationService as = get(ApplicationService.class); | ||
| 81 | + for (Application app : as.getApplications()) { | ||
| 82 | + populateRow(tm.addRow(), app, as); | ||
| 83 | + } | ||
| 79 | } | 84 | } |
| 80 | 85 | ||
| 86 | + private void populateRow(TableModel.Row row, Application app, | ||
| 87 | + ApplicationService as) { | ||
| 88 | + ApplicationId id = app.id(); | ||
| 89 | + ApplicationState state = as.getState(id); | ||
| 90 | + String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE; | ||
| 91 | + | ||
| 92 | + row.cell(STATE, state) | ||
| 93 | + .cell(STATE_IID, iconId) | ||
| 94 | + .cell(ID, id.name()) | ||
| 95 | + .cell(VERSION, app.version()) | ||
| 96 | + .cell(ORIGIN, app.origin()) | ||
| 97 | + .cell(DESC, app.description()); | ||
| 98 | + } | ||
| 81 | } | 99 | } |
| 82 | 100 | ||
| 83 | // handler for application management control button actions | 101 | // handler for application management control button actions |
| ... | @@ -104,33 +122,4 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { | ... | @@ -104,33 +122,4 @@ public class ApplicationViewMessageHandler extends UiMessageHandler { |
| 104 | } | 122 | } |
| 105 | } | 123 | } |
| 106 | } | 124 | } |
| 107 | - | ||
| 108 | - /** | ||
| 109 | - * TableRow implementation for | ||
| 110 | - * {@link org.onosproject.core.Application applications}. | ||
| 111 | - */ | ||
| 112 | - private static class ApplicationTableRow extends AbstractTableRow { | ||
| 113 | - | ||
| 114 | - private static final String[] COL_IDS = { | ||
| 115 | - STATE, STATE_IID, ID, VERSION, ORIGIN, DESC | ||
| 116 | - }; | ||
| 117 | - | ||
| 118 | - public ApplicationTableRow(ApplicationService service, Application app) { | ||
| 119 | - ApplicationState state = service.getState(app.id()); | ||
| 120 | - String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE; | ||
| 121 | - | ||
| 122 | - add(STATE, state); | ||
| 123 | - add(STATE_IID, iconId); | ||
| 124 | - add(ID, app.id().name()); | ||
| 125 | - add(VERSION, app.version()); | ||
| 126 | - add(ORIGIN, app.origin()); | ||
| 127 | - add(DESC, app.description()); | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - @Override | ||
| 131 | - protected String[] columnIds() { | ||
| 132 | - return COL_IDS; | ||
| 133 | - } | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | } | 125 | } | ... | ... |
| ... | @@ -19,19 +19,17 @@ package org.onosproject.ui.impl; | ... | @@ -19,19 +19,17 @@ package org.onosproject.ui.impl; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import org.joda.time.DateTime; | 21 | import org.joda.time.DateTime; |
| 22 | -import org.joda.time.format.DateTimeFormat; | ||
| 23 | import org.onosproject.cluster.ClusterService; | 22 | import org.onosproject.cluster.ClusterService; |
| 24 | import org.onosproject.cluster.ControllerNode; | 23 | import org.onosproject.cluster.ControllerNode; |
| 25 | import org.onosproject.cluster.NodeId; | 24 | import org.onosproject.cluster.NodeId; |
| 26 | import org.onosproject.ui.RequestHandler; | 25 | import org.onosproject.ui.RequestHandler; |
| 27 | import org.onosproject.ui.UiMessageHandler; | 26 | import org.onosproject.ui.UiMessageHandler; |
| 28 | -import org.onosproject.ui.table.AbstractTableRow; | 27 | +import org.onosproject.ui.table.TableModel; |
| 29 | import org.onosproject.ui.table.TableRequestHandler; | 28 | import org.onosproject.ui.table.TableRequestHandler; |
| 30 | -import org.onosproject.ui.table.TableRow; | 29 | +import org.onosproject.ui.table.cell.IntComparator; |
| 30 | +import org.onosproject.ui.table.cell.TimeFormatter; | ||
| 31 | 31 | ||
| 32 | import java.util.Collection; | 32 | import java.util.Collection; |
| 33 | -import java.util.List; | ||
| 34 | -import java.util.stream.Collectors; | ||
| 35 | 33 | ||
| 36 | 34 | ||
| 37 | /** | 35 | /** |
| ... | @@ -49,6 +47,13 @@ public class ClusterViewMessageHandler extends UiMessageHandler { | ... | @@ -49,6 +47,13 @@ public class ClusterViewMessageHandler extends UiMessageHandler { |
| 49 | private static final String STATE_IID = "_iconid_state"; | 47 | private static final String STATE_IID = "_iconid_state"; |
| 50 | private static final String UPDATED = "updated"; | 48 | private static final String UPDATED = "updated"; |
| 51 | 49 | ||
| 50 | + private static final String[] COL_IDS = { | ||
| 51 | + ID, IP, TCP_PORT, STATE_IID, UPDATED | ||
| 52 | + }; | ||
| 53 | + | ||
| 54 | + private static final String ICON_ID_ONLINE = "active"; | ||
| 55 | + private static final String ICON_ID_OFFLINE = "inactive"; | ||
| 56 | + | ||
| 52 | @Override | 57 | @Override |
| 53 | protected Collection<RequestHandler> getHandlers() { | 58 | protected Collection<RequestHandler> getHandlers() { |
| 54 | return ImmutableSet.of(new ClusterDataRequest()); | 59 | return ImmutableSet.of(new ClusterDataRequest()); |
| ... | @@ -61,45 +66,38 @@ public class ClusterViewMessageHandler extends UiMessageHandler { | ... | @@ -61,45 +66,38 @@ public class ClusterViewMessageHandler extends UiMessageHandler { |
| 61 | } | 66 | } |
| 62 | 67 | ||
| 63 | @Override | 68 | @Override |
| 64 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 69 | + protected String[] getColumnIds() { |
| 65 | - ClusterService service = get(ClusterService.class); | 70 | + return COL_IDS; |
| 66 | - List<TableRow> list = service.getNodes().stream() | ||
| 67 | - .map(node -> new ControllerNodeTableRow(service, node)) | ||
| 68 | - .collect(Collectors.toList()); | ||
| 69 | - return list.toArray(new TableRow[list.size()]); | ||
| 70 | } | 71 | } |
| 71 | - } | ||
| 72 | 72 | ||
| 73 | - /** | 73 | + @Override |
| 74 | - * TableRow implementation for {@link ControllerNode controller nodes}. | 74 | + protected TableModel createTableModel() { |
| 75 | - */ | 75 | + TableModel tm = super.createTableModel(); |
| 76 | - private static class ControllerNodeTableRow extends AbstractTableRow { | 76 | + tm.setComparator(TCP_PORT, IntComparator.INSTANCE); |
| 77 | - | 77 | + tm.setFormatter(UPDATED, TimeFormatter.INSTANCE); |
| 78 | - private static final String[] COL_IDS = { | 78 | + return tm; |
| 79 | - ID, IP, TCP_PORT, STATE_IID, UPDATED | 79 | + } |
| 80 | - }; | ||
| 81 | 80 | ||
| 82 | - private static final String ICON_ID_ONLINE = "active"; | 81 | + @Override |
| 83 | - private static final String ICON_ID_OFFLINE = "inactive"; | 82 | + protected void populateTable(TableModel tm, ObjectNode payload) { |
| 83 | + ClusterService cs = get(ClusterService.class); | ||
| 84 | + for (ControllerNode node : cs.getNodes()) { | ||
| 85 | + populateRow(tm.addRow(), node, cs); | ||
| 86 | + } | ||
| 87 | + } | ||
| 84 | 88 | ||
| 85 | - public ControllerNodeTableRow(ClusterService service, ControllerNode n) { | 89 | + private void populateRow(TableModel.Row row, ControllerNode node, |
| 86 | - NodeId id = n.id(); | 90 | + ClusterService cs) { |
| 87 | - DateTime lastUpdated = service.getLastUpdated(id); | 91 | + NodeId id = node.id(); |
| 88 | - org.joda.time.format.DateTimeFormatter format = DateTimeFormat.longTime(); | 92 | + DateTime lastUpdated = cs.getLastUpdated(id); |
| 89 | - String iconId = (service.getState(id) == ControllerNode.State.ACTIVE) ? | 93 | + String iconId = (cs.getState(id) == ControllerNode.State.ACTIVE) ? |
| 90 | ICON_ID_ONLINE : ICON_ID_OFFLINE; | 94 | ICON_ID_ONLINE : ICON_ID_OFFLINE; |
| 91 | 95 | ||
| 92 | - add(ID, id.toString()); | 96 | + row.cell(ID, id) |
| 93 | - add(IP, n.ip().toString()); | 97 | + .cell(IP, node.ip()) |
| 94 | - add(TCP_PORT, Integer.toString(n.tcpPort())); | 98 | + .cell(TCP_PORT, node.tcpPort()) |
| 95 | - add(STATE_IID, iconId); | 99 | + .cell(STATE_IID, iconId) |
| 96 | - add(UPDATED, format.print(lastUpdated)); | 100 | + .cell(UPDATED, lastUpdated); |
| 97 | - } | ||
| 98 | - | ||
| 99 | - @Override | ||
| 100 | - protected String[] columnIds() { | ||
| 101 | - return COL_IDS; | ||
| 102 | } | 101 | } |
| 103 | } | 102 | } |
| 104 | - | ||
| 105 | } | 103 | } | ... | ... |
| ... | @@ -29,9 +29,9 @@ import org.onosproject.net.device.DeviceService; | ... | @@ -29,9 +29,9 @@ import org.onosproject.net.device.DeviceService; |
| 29 | import org.onosproject.net.link.LinkService; | 29 | import org.onosproject.net.link.LinkService; |
| 30 | import org.onosproject.ui.RequestHandler; | 30 | import org.onosproject.ui.RequestHandler; |
| 31 | import org.onosproject.ui.UiMessageHandler; | 31 | import org.onosproject.ui.UiMessageHandler; |
| 32 | -import org.onosproject.ui.table.AbstractTableRow; | 32 | +import org.onosproject.ui.table.TableModel; |
| 33 | import org.onosproject.ui.table.TableRequestHandler; | 33 | import org.onosproject.ui.table.TableRequestHandler; |
| 34 | -import org.onosproject.ui.table.TableRow; | 34 | +import org.onosproject.ui.table.cell.IntComparator; |
| 35 | 35 | ||
| 36 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
| 37 | import java.util.Collection; | 37 | import java.util.Collection; |
| ... | @@ -73,6 +73,15 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -73,6 +73,15 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 73 | private static final String NAME = "name"; | 73 | private static final String NAME = "name"; |
| 74 | 74 | ||
| 75 | 75 | ||
| 76 | + private static final String[] COL_IDS = { | ||
| 77 | + AVAILABLE, AVAILABLE_IID, TYPE_IID, ID, | ||
| 78 | + NUM_PORTS, MASTER_ID, MFR, HW, SW, | ||
| 79 | + PROTOCOL, CHASSIS_ID, SERIAL | ||
| 80 | + }; | ||
| 81 | + | ||
| 82 | + private static final String ICON_ID_ONLINE = "active"; | ||
| 83 | + private static final String ICON_ID_OFFLINE = "inactive"; | ||
| 84 | + | ||
| 76 | @Override | 85 | @Override |
| 77 | protected Collection<RequestHandler> getHandlers() { | 86 | protected Collection<RequestHandler> getHandlers() { |
| 78 | return ImmutableSet.of( | 87 | return ImmutableSet.of( |
| ... | @@ -81,6 +90,10 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -81,6 +90,10 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 81 | ); | 90 | ); |
| 82 | } | 91 | } |
| 83 | 92 | ||
| 93 | + private static String getTypeIconId(Device d) { | ||
| 94 | + return DEV_ICON_PREFIX + d.type().toString(); | ||
| 95 | + } | ||
| 96 | + | ||
| 84 | // handler for device table requests | 97 | // handler for device table requests |
| 85 | private final class DataRequestHandler extends TableRequestHandler { | 98 | private final class DataRequestHandler extends TableRequestHandler { |
| 86 | private DataRequestHandler() { | 99 | private DataRequestHandler() { |
| ... | @@ -88,14 +101,42 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -88,14 +101,42 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 88 | } | 101 | } |
| 89 | 102 | ||
| 90 | @Override | 103 | @Override |
| 91 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 104 | + protected String[] getColumnIds() { |
| 92 | - DeviceService service = get(DeviceService.class); | 105 | + return COL_IDS; |
| 93 | - MastershipService mastershipService = get(MastershipService.class); | 106 | + } |
| 94 | - List<TableRow> list = new ArrayList<>(); | 107 | + |
| 95 | - for (Device dev : service.getDevices()) { | 108 | + @Override |
| 96 | - list.add(new DeviceTableRow(service, mastershipService, dev)); | 109 | + protected TableModel createTableModel() { |
| 110 | + TableModel tm = super.createTableModel(); | ||
| 111 | + tm.setComparator(NUM_PORTS, IntComparator.INSTANCE); | ||
| 112 | + return tm; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + @Override | ||
| 116 | + protected void populateTable(TableModel tm, ObjectNode payload) { | ||
| 117 | + DeviceService ds = get(DeviceService.class); | ||
| 118 | + MastershipService ms = get(MastershipService.class); | ||
| 119 | + for (Device dev : ds.getDevices()) { | ||
| 120 | + populateRow(tm.addRow(), dev, ds, ms); | ||
| 97 | } | 121 | } |
| 98 | - return list.toArray(new TableRow[list.size()]); | 122 | + } |
| 123 | + | ||
| 124 | + private void populateRow(TableModel.Row row, Device dev, | ||
| 125 | + DeviceService ds, MastershipService ms) { | ||
| 126 | + DeviceId id = dev.id(); | ||
| 127 | + boolean available = ds.isAvailable(id); | ||
| 128 | + String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE; | ||
| 129 | + | ||
| 130 | + row.cell(ID, id) | ||
| 131 | + .cell(AVAILABLE, available) | ||
| 132 | + .cell(AVAILABLE_IID, iconId) | ||
| 133 | + .cell(TYPE_IID, getTypeIconId(dev)) | ||
| 134 | + .cell(MFR, dev.manufacturer()) | ||
| 135 | + .cell(HW, dev.hwVersion()) | ||
| 136 | + .cell(SW, dev.swVersion()) | ||
| 137 | + .cell(PROTOCOL, dev.annotations().value(PROTOCOL)) | ||
| 138 | + .cell(NUM_PORTS, ds.getPorts(id).size()) | ||
| 139 | + .cell(MASTER_ID, ms.getMasterFor(id)); | ||
| 99 | } | 140 | } |
| 100 | } | 141 | } |
| 101 | 142 | ||
| ... | @@ -168,51 +209,5 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -168,51 +209,5 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 168 | 209 | ||
| 169 | return port; | 210 | return port; |
| 170 | } | 211 | } |
| 171 | - | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - private static String getTypeIconId(Device d) { | ||
| 175 | - return DEV_ICON_PREFIX + d.type().toString(); | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - /** | ||
| 179 | - * TableRow implementation for {@link Device devices}. | ||
| 180 | - */ | ||
| 181 | - private static class DeviceTableRow extends AbstractTableRow { | ||
| 182 | - | ||
| 183 | - private static final String[] COL_IDS = { | ||
| 184 | - AVAILABLE, AVAILABLE_IID, TYPE_IID, ID, | ||
| 185 | - NUM_PORTS, MASTER_ID, MFR, HW, SW, | ||
| 186 | - PROTOCOL, CHASSIS_ID, SERIAL | ||
| 187 | - }; | ||
| 188 | - | ||
| 189 | - private static final String ICON_ID_ONLINE = "active"; | ||
| 190 | - private static final String ICON_ID_OFFLINE = "inactive"; | ||
| 191 | - | ||
| 192 | - public DeviceTableRow(DeviceService service, | ||
| 193 | - MastershipService ms, | ||
| 194 | - Device d) { | ||
| 195 | - boolean available = service.isAvailable(d.id()); | ||
| 196 | - String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE; | ||
| 197 | - DeviceId id = d.id(); | ||
| 198 | - List<Port> ports = service.getPorts(id); | ||
| 199 | - | ||
| 200 | - add(ID, id.toString()); | ||
| 201 | - add(AVAILABLE, Boolean.toString(available)); | ||
| 202 | - add(AVAILABLE_IID, iconId); | ||
| 203 | - add(TYPE_IID, getTypeIconId(d)); | ||
| 204 | - add(MFR, d.manufacturer()); | ||
| 205 | - add(HW, d.hwVersion()); | ||
| 206 | - add(SW, d.swVersion()); | ||
| 207 | - add(PROTOCOL, d.annotations().value(PROTOCOL)); | ||
| 208 | - add(NUM_PORTS, Integer.toString(ports.size())); | ||
| 209 | - add(MASTER_ID, ms.getMasterFor(d.id()).toString()); | ||
| 210 | - } | ||
| 211 | - | ||
| 212 | - @Override | ||
| 213 | - protected String[] columnIds() { | ||
| 214 | - return COL_IDS; | ||
| 215 | - } | ||
| 216 | } | 212 | } |
| 217 | - | ||
| 218 | } | 213 | } | ... | ... |
| ... | @@ -28,11 +28,11 @@ import org.onosproject.net.flow.criteria.Criterion; | ... | @@ -28,11 +28,11 @@ import org.onosproject.net.flow.criteria.Criterion; |
| 28 | import org.onosproject.net.flow.instructions.Instruction; | 28 | import org.onosproject.net.flow.instructions.Instruction; |
| 29 | import org.onosproject.ui.RequestHandler; | 29 | import org.onosproject.ui.RequestHandler; |
| 30 | import org.onosproject.ui.UiMessageHandler; | 30 | import org.onosproject.ui.UiMessageHandler; |
| 31 | -import org.onosproject.ui.table.AbstractTableRow; | 31 | +import org.onosproject.ui.table.TableModel; |
| 32 | import org.onosproject.ui.table.TableRequestHandler; | 32 | import org.onosproject.ui.table.TableRequestHandler; |
| 33 | -import org.onosproject.ui.table.TableRow; | 33 | +import org.onosproject.ui.table.cell.IntComparator; |
| 34 | +import org.onosproject.ui.table.cell.LongComparator; | ||
| 34 | 35 | ||
| 35 | -import java.util.ArrayList; | ||
| 36 | import java.util.Collection; | 36 | import java.util.Collection; |
| 37 | import java.util.List; | 37 | import java.util.List; |
| 38 | import java.util.Set; | 38 | import java.util.Set; |
| ... | @@ -64,6 +64,11 @@ public class FlowViewMessageHandler extends UiMessageHandler { | ... | @@ -64,6 +64,11 @@ public class FlowViewMessageHandler extends UiMessageHandler { |
| 64 | 64 | ||
| 65 | private static final String COMMA = ", "; | 65 | private static final String COMMA = ", "; |
| 66 | 66 | ||
| 67 | + private static final String[] COL_IDS = { | ||
| 68 | + ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR, | ||
| 69 | + TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES | ||
| 70 | + }; | ||
| 71 | + | ||
| 67 | @Override | 72 | @Override |
| 68 | protected Collection<RequestHandler> getHandlers() { | 73 | protected Collection<RequestHandler> getHandlers() { |
| 69 | return ImmutableSet.of(new FlowDataRequest()); | 74 | return ImmutableSet.of(new FlowDataRequest()); |
| ... | @@ -77,45 +82,47 @@ public class FlowViewMessageHandler extends UiMessageHandler { | ... | @@ -77,45 +82,47 @@ public class FlowViewMessageHandler extends UiMessageHandler { |
| 77 | } | 82 | } |
| 78 | 83 | ||
| 79 | @Override | 84 | @Override |
| 80 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 85 | + protected String[] getColumnIds() { |
| 86 | + return COL_IDS; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + protected TableModel createTableModel() { | ||
| 91 | + TableModel tm = super.createTableModel(); | ||
| 92 | + tm.setComparator(GROUP_ID, IntComparator.INSTANCE); | ||
| 93 | + tm.setComparator(TABLE_ID, IntComparator.INSTANCE); | ||
| 94 | + tm.setComparator(PRIORITY, IntComparator.INSTANCE); | ||
| 95 | + tm.setComparator(TIMEOUT, IntComparator.INSTANCE); | ||
| 96 | + tm.setComparator(PACKETS, LongComparator.INSTANCE); | ||
| 97 | + tm.setComparator(BYTES, LongComparator.INSTANCE); | ||
| 98 | + return tm; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + protected void populateTable(TableModel tm, ObjectNode payload) { | ||
| 81 | String uri = string(payload, "devId"); | 103 | String uri = string(payload, "devId"); |
| 82 | - if (Strings.isNullOrEmpty(uri)) { | 104 | + if (!Strings.isNullOrEmpty(uri)) { |
| 83 | - return new TableRow[0]; | 105 | + DeviceId deviceId = DeviceId.deviceId(uri); |
| 84 | - } | 106 | + FlowRuleService frs = get(FlowRuleService.class); |
| 85 | - DeviceId deviceId = DeviceId.deviceId(uri); | 107 | + for (FlowEntry flow : frs.getFlowEntries(deviceId)) { |
| 86 | - FlowRuleService service = get(FlowRuleService.class); | 108 | + populateRow(tm.addRow(), flow); |
| 87 | - List<TableRow> list = new ArrayList<>(); | 109 | + } |
| 88 | - for (FlowEntry flow : service.getFlowEntries(deviceId)) { | ||
| 89 | - list.add(new FlowTableRow(flow)); | ||
| 90 | } | 110 | } |
| 91 | - return list.toArray(new TableRow[list.size()]); | ||
| 92 | } | 111 | } |
| 93 | - } | ||
| 94 | 112 | ||
| 95 | - /** | 113 | + private void populateRow(TableModel.Row row, FlowEntry flow) { |
| 96 | - * TableRow implementation for | 114 | + row.cell(ID, flow.id().value()) |
| 97 | - * {@link org.onosproject.net.flow.FlowRule flows}. | 115 | + .cell(APP_ID, flow.appId()) |
| 98 | - */ | 116 | + .cell(GROUP_ID, flow.groupId().id()) |
| 99 | - private static class FlowTableRow extends AbstractTableRow { | 117 | + .cell(TABLE_ID, flow.tableId()) |
| 100 | - | 118 | + .cell(PRIORITY, flow.priority()) |
| 101 | - private static final String[] COL_IDS = { | 119 | + .cell(SELECTOR, getSelectorString(flow)) |
| 102 | - ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR, | 120 | + .cell(TREATMENT, getTreatmentString(flow)) |
| 103 | - TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES | 121 | + .cell(TIMEOUT, flow.timeout()) |
| 104 | - }; | 122 | + .cell(PERMANENT, flow.isPermanent()) |
| 105 | - | 123 | + .cell(STATE, capitalizeFully(flow.state().toString())) |
| 106 | - public FlowTableRow(FlowEntry f) { | 124 | + .cell(PACKETS, flow.packets()) |
| 107 | - add(ID, f.id().value()); | 125 | + .cell(BYTES, flow.bytes()); |
| 108 | - add(APP_ID, f.appId()); | ||
| 109 | - add(GROUP_ID, f.groupId().id()); | ||
| 110 | - add(TABLE_ID, f.tableId()); | ||
| 111 | - add(PRIORITY, f.priority()); | ||
| 112 | - add(SELECTOR, getSelectorString(f)); | ||
| 113 | - add(TREATMENT, getTreatmentString(f)); | ||
| 114 | - add(TIMEOUT, f.timeout()); | ||
| 115 | - add(PERMANENT, f.isPermanent()); | ||
| 116 | - add(STATE, capitalizeFully(f.state().toString())); | ||
| 117 | - add(PACKETS, f.packets()); | ||
| 118 | - add(BYTES, f.packets()); | ||
| 119 | } | 126 | } |
| 120 | 127 | ||
| 121 | private String getSelectorString(FlowEntry f) { | 128 | private String getSelectorString(FlowEntry f) { |
| ... | @@ -184,11 +191,5 @@ public class FlowViewMessageHandler extends UiMessageHandler { | ... | @@ -184,11 +191,5 @@ public class FlowViewMessageHandler extends UiMessageHandler { |
| 184 | sb.delete(pos, sb.length()); | 191 | sb.delete(pos, sb.length()); |
| 185 | return sb; | 192 | return sb; |
| 186 | } | 193 | } |
| 187 | - | ||
| 188 | - @Override | ||
| 189 | - protected String[] columnIds() { | ||
| 190 | - return COL_IDS; | ||
| 191 | - } | ||
| 192 | } | 194 | } |
| 193 | - | ||
| 194 | } | 195 | } | ... | ... |
| ... | @@ -19,17 +19,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -19,17 +19,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onosproject.net.AnnotationKeys; | 20 | import org.onosproject.net.AnnotationKeys; |
| 21 | import org.onosproject.net.Host; | 21 | import org.onosproject.net.Host; |
| 22 | -import org.onosproject.net.HostLocation; | ||
| 23 | import org.onosproject.net.host.HostService; | 22 | import org.onosproject.net.host.HostService; |
| 24 | import org.onosproject.ui.RequestHandler; | 23 | import org.onosproject.ui.RequestHandler; |
| 25 | import org.onosproject.ui.UiMessageHandler; | 24 | import org.onosproject.ui.UiMessageHandler; |
| 26 | -import org.onosproject.ui.table.AbstractTableRow; | 25 | +import org.onosproject.ui.table.TableModel; |
| 27 | import org.onosproject.ui.table.TableRequestHandler; | 26 | import org.onosproject.ui.table.TableRequestHandler; |
| 28 | -import org.onosproject.ui.table.TableRow; | 27 | +import org.onosproject.ui.table.cell.HostLocationFormatter; |
| 29 | 28 | ||
| 30 | -import java.util.ArrayList; | ||
| 31 | import java.util.Collection; | 29 | import java.util.Collection; |
| 32 | -import java.util.List; | ||
| 33 | 30 | ||
| 34 | import static com.google.common.base.Strings.isNullOrEmpty; | 31 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 35 | 32 | ||
| ... | @@ -51,6 +48,9 @@ public class HostViewMessageHandler extends UiMessageHandler { | ... | @@ -51,6 +48,9 @@ public class HostViewMessageHandler extends UiMessageHandler { |
| 51 | 48 | ||
| 52 | private static final String HOST_ICON_PREFIX = "hostIcon_"; | 49 | private static final String HOST_ICON_PREFIX = "hostIcon_"; |
| 53 | 50 | ||
| 51 | + private static final String[] COL_IDS = { | ||
| 52 | + TYPE_IID, ID, MAC, VLAN, IPS, LOCATION | ||
| 53 | + }; | ||
| 54 | 54 | ||
| 55 | @Override | 55 | @Override |
| 56 | protected Collection<RequestHandler> getHandlers() { | 56 | protected Collection<RequestHandler> getHandlers() { |
| ... | @@ -64,34 +64,32 @@ public class HostViewMessageHandler extends UiMessageHandler { | ... | @@ -64,34 +64,32 @@ public class HostViewMessageHandler extends UiMessageHandler { |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | @Override | 66 | @Override |
| 67 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 67 | + protected String[] getColumnIds() { |
| 68 | - HostService service = get(HostService.class); | 68 | + return COL_IDS; |
| 69 | - List<TableRow> list = new ArrayList<>(); | ||
| 70 | - for (Host host : service.getHosts()) { | ||
| 71 | - list.add(new HostTableRow(host)); | ||
| 72 | - } | ||
| 73 | - return list.toArray(new TableRow[list.size()]); | ||
| 74 | } | 69 | } |
| 75 | - } | ||
| 76 | - | ||
| 77 | - /** | ||
| 78 | - * TableRow implementation for {@link Host hosts}. | ||
| 79 | - */ | ||
| 80 | - private static class HostTableRow extends AbstractTableRow { | ||
| 81 | 70 | ||
| 82 | - private static final String[] COL_IDS = { | 71 | + @Override |
| 83 | - TYPE_IID, ID, MAC, VLAN, IPS, LOCATION | 72 | + protected TableModel createTableModel() { |
| 84 | - }; | 73 | + TableModel tm = super.createTableModel(); |
| 74 | + tm.setFormatter(LOCATION, HostLocationFormatter.INSTANCE); | ||
| 75 | + return tm; | ||
| 76 | + } | ||
| 85 | 77 | ||
| 86 | - public HostTableRow(Host h) { | 78 | + @Override |
| 87 | - HostLocation location = h.location(); | 79 | + protected void populateTable(TableModel tm, ObjectNode payload) { |
| 80 | + HostService hs = get(HostService.class); | ||
| 81 | + for (Host host : hs.getHosts()) { | ||
| 82 | + populateRow(tm.addRow(), host); | ||
| 83 | + } | ||
| 84 | + } | ||
| 88 | 85 | ||
| 89 | - add(TYPE_IID, getTypeIconId(h)); | 86 | + private void populateRow(TableModel.Row row, Host host) { |
| 90 | - add(ID, h.id()); | 87 | + row.cell(TYPE_IID, getTypeIconId(host)) |
| 91 | - add(MAC, h.mac()); | 88 | + .cell(ID, host.id()) |
| 92 | - add(VLAN, h.vlan()); | 89 | + .cell(MAC, host.mac()) |
| 93 | - add(IPS, h.ipAddresses()); | 90 | + .cell(VLAN, host.vlan()) |
| 94 | - add(LOCATION, concat(location.deviceId(), "/", location.port())); | 91 | + .cell(IPS, host.ipAddresses()) |
| 92 | + .cell(LOCATION, host.location()); | ||
| 95 | } | 93 | } |
| 96 | 94 | ||
| 97 | private String getTypeIconId(Host host) { | 95 | private String getTypeIconId(Host host) { |
| ... | @@ -99,11 +97,5 @@ public class HostViewMessageHandler extends UiMessageHandler { | ... | @@ -99,11 +97,5 @@ public class HostViewMessageHandler extends UiMessageHandler { |
| 99 | return HOST_ICON_PREFIX + | 97 | return HOST_ICON_PREFIX + |
| 100 | (isNullOrEmpty(hostType) ? "endstation" : hostType); | 98 | (isNullOrEmpty(hostType) ? "endstation" : hostType); |
| 101 | } | 99 | } |
| 102 | - | ||
| 103 | - @Override | ||
| 104 | - protected String[] columnIds() { | ||
| 105 | - return COL_IDS; | ||
| 106 | - } | ||
| 107 | } | 100 | } |
| 108 | - | ||
| 109 | } | 101 | } | ... | ... |
| ... | @@ -17,7 +17,6 @@ package org.onosproject.ui.impl; | ... | @@ -17,7 +17,6 @@ package org.onosproject.ui.impl; |
| 17 | 17 | ||
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | -import org.onosproject.core.ApplicationId; | ||
| 21 | import org.onosproject.net.ConnectPoint; | 20 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.flow.criteria.Criterion; | 21 | import org.onosproject.net.flow.criteria.Criterion; |
| 23 | import org.onosproject.net.flow.instructions.Instruction; | 22 | import org.onosproject.net.flow.instructions.Instruction; |
| ... | @@ -33,11 +32,11 @@ import org.onosproject.net.intent.PointToPointIntent; | ... | @@ -33,11 +32,11 @@ import org.onosproject.net.intent.PointToPointIntent; |
| 33 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; | 32 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
| 34 | import org.onosproject.ui.RequestHandler; | 33 | import org.onosproject.ui.RequestHandler; |
| 35 | import org.onosproject.ui.UiMessageHandler; | 34 | import org.onosproject.ui.UiMessageHandler; |
| 36 | -import org.onosproject.ui.table.AbstractTableRow; | 35 | +import org.onosproject.ui.table.TableModel; |
| 37 | import org.onosproject.ui.table.TableRequestHandler; | 36 | import org.onosproject.ui.table.TableRequestHandler; |
| 38 | -import org.onosproject.ui.table.TableRow; | 37 | +import org.onosproject.ui.table.cell.AppIdFormatter; |
| 38 | +import org.onosproject.ui.table.cell.IntComparator; | ||
| 39 | 39 | ||
| 40 | -import java.util.ArrayList; | ||
| 41 | import java.util.Collection; | 40 | import java.util.Collection; |
| 42 | import java.util.List; | 41 | import java.util.List; |
| 43 | import java.util.Set; | 42 | import java.util.Set; |
| ... | @@ -58,6 +57,10 @@ public class IntentViewMessageHandler extends UiMessageHandler { | ... | @@ -58,6 +57,10 @@ public class IntentViewMessageHandler extends UiMessageHandler { |
| 58 | private static final String RESOURCES = "resources"; | 57 | private static final String RESOURCES = "resources"; |
| 59 | private static final String DETAILS = "details"; | 58 | private static final String DETAILS = "details"; |
| 60 | 59 | ||
| 60 | + private static final String[] COL_IDS = { | ||
| 61 | + APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS | ||
| 62 | + }; | ||
| 63 | + | ||
| 61 | @Override | 64 | @Override |
| 62 | protected Collection<RequestHandler> getHandlers() { | 65 | protected Collection<RequestHandler> getHandlers() { |
| 63 | return ImmutableSet.of(new IntentDataRequest()); | 66 | return ImmutableSet.of(new IntentDataRequest()); |
| ... | @@ -70,30 +73,42 @@ public class IntentViewMessageHandler extends UiMessageHandler { | ... | @@ -70,30 +73,42 @@ public class IntentViewMessageHandler extends UiMessageHandler { |
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | @Override | 75 | @Override |
| 73 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 76 | + protected String defaultColumnId() { |
| 74 | - IntentService service = get(IntentService.class); | 77 | + return APP_ID; |
| 75 | - List<TableRow> list = new ArrayList<>(); | ||
| 76 | - for (Intent intent : service.getIntents()) { | ||
| 77 | - list.add(new IntentTableRow(intent)); | ||
| 78 | - } | ||
| 79 | - return list.toArray(new TableRow[list.size()]); | ||
| 80 | } | 78 | } |
| 81 | 79 | ||
| 82 | @Override | 80 | @Override |
| 83 | - protected String defaultColId() { | 81 | + protected String[] getColumnIds() { |
| 84 | - return APP_ID; | 82 | + return COL_IDS; |
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + protected TableModel createTableModel() { | ||
| 87 | + TableModel tm = super.createTableModel(); | ||
| 88 | + tm.setComparator(PRIORITY, IntComparator.INSTANCE); | ||
| 89 | + tm.setFormatter(APP_ID, AppIdFormatter.INSTANCE); | ||
| 90 | + return tm; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + protected void populateTable(TableModel tm, ObjectNode payload) { | ||
| 95 | + IntentService is = get(IntentService.class); | ||
| 96 | + for (Intent intent : is.getIntents()) { | ||
| 97 | + populateRow(tm.addRow(), intent); | ||
| 98 | + } | ||
| 85 | } | 99 | } |
| 86 | - } | ||
| 87 | 100 | ||
| 88 | - /** | 101 | + private void populateRow(TableModel.Row row, Intent intent) { |
| 89 | - * TableRow implementation for {@link Intent intents}. | 102 | + row.cell(APP_ID, intent.appId()) |
| 90 | - */ | 103 | + .cell(KEY, intent.key()) |
| 91 | - private static class IntentTableRow extends AbstractTableRow { | 104 | + .cell(TYPE, intent.getClass().getSimpleName()) |
| 105 | + .cell(PRIORITY, intent.priority()) | ||
| 106 | + .cell(RESOURCES, formatResources(intent)) | ||
| 107 | + .cell(DETAILS, formatDetails(intent)); | ||
| 108 | + } | ||
| 92 | 109 | ||
| 93 | - private static final String[] COL_IDS = { | ||
| 94 | - APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS | ||
| 95 | - }; | ||
| 96 | 110 | ||
| 111 | + // == TODO: Review -- Move the following code to a helper class? | ||
| 97 | private StringBuilder details = new StringBuilder(); | 112 | private StringBuilder details = new StringBuilder(); |
| 98 | 113 | ||
| 99 | private void appendMultiPointsDetails(Set<ConnectPoint> points) { | 114 | private void appendMultiPointsDetails(Set<ConnectPoint> points) { |
| ... | @@ -217,25 +232,8 @@ public class IntentViewMessageHandler extends UiMessageHandler { | ... | @@ -217,25 +232,8 @@ public class IntentViewMessageHandler extends UiMessageHandler { |
| 217 | 232 | ||
| 218 | private String formatResources(Intent intent) { | 233 | private String formatResources(Intent intent) { |
| 219 | return (intent.resources().isEmpty() ? | 234 | return (intent.resources().isEmpty() ? |
| 220 | - "(No resources for this intent)" : | 235 | + "(No resources for this intent)" : |
| 221 | - "Resources: " + intent.resources()); | 236 | + "Resources: " + intent.resources()); |
| 222 | - } | ||
| 223 | - | ||
| 224 | - public IntentTableRow(Intent intent) { | ||
| 225 | - ApplicationId appid = intent.appId(); | ||
| 226 | - | ||
| 227 | - add(APP_ID, concat(appid.id(), " : ", appid.name())); | ||
| 228 | - add(KEY, intent.key()); | ||
| 229 | - add(TYPE, intent.getClass().getSimpleName()); | ||
| 230 | - add(PRIORITY, intent.priority()); | ||
| 231 | - add(RESOURCES, formatResources(intent)); | ||
| 232 | - add(DETAILS, formatDetails(intent)); | ||
| 233 | - } | ||
| 234 | - | ||
| 235 | - @Override | ||
| 236 | - protected String[] columnIds() { | ||
| 237 | - return COL_IDS; | ||
| 238 | } | 237 | } |
| 239 | } | 238 | } |
| 240 | - | ||
| 241 | } | 239 | } | ... | ... |
| ... | @@ -19,20 +19,17 @@ package org.onosproject.ui.impl; | ... | @@ -19,20 +19,17 @@ package org.onosproject.ui.impl; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
| 22 | -import org.onosproject.net.ConnectPoint; | ||
| 23 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.LinkKey; | 23 | import org.onosproject.net.LinkKey; |
| 25 | import org.onosproject.net.link.LinkService; | 24 | import org.onosproject.net.link.LinkService; |
| 26 | import org.onosproject.ui.RequestHandler; | 25 | import org.onosproject.ui.RequestHandler; |
| 27 | import org.onosproject.ui.UiMessageHandler; | 26 | import org.onosproject.ui.UiMessageHandler; |
| 28 | import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; | 27 | import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink; |
| 29 | -import org.onosproject.ui.table.AbstractTableRow; | 28 | +import org.onosproject.ui.table.TableModel; |
| 30 | import org.onosproject.ui.table.TableRequestHandler; | 29 | import org.onosproject.ui.table.TableRequestHandler; |
| 31 | -import org.onosproject.ui.table.TableRow; | 30 | +import org.onosproject.ui.table.cell.ConnectPointFormatter; |
| 32 | 31 | ||
| 33 | -import java.util.ArrayList; | ||
| 34 | import java.util.Collection; | 32 | import java.util.Collection; |
| 35 | -import java.util.List; | ||
| 36 | import java.util.Map; | 33 | import java.util.Map; |
| 37 | 34 | ||
| 38 | import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; | 35 | import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink; |
| ... | @@ -53,6 +50,13 @@ public class LinkViewMessageHandler extends UiMessageHandler { | ... | @@ -53,6 +50,13 @@ public class LinkViewMessageHandler extends UiMessageHandler { |
| 53 | private static final String DIRECTION = "direction"; | 50 | private static final String DIRECTION = "direction"; |
| 54 | private static final String DURABLE = "durable"; | 51 | private static final String DURABLE = "durable"; |
| 55 | 52 | ||
| 53 | + private static final String[] COL_IDS = { | ||
| 54 | + ONE, TWO, TYPE, STATE, DIRECTION, DURABLE | ||
| 55 | + }; | ||
| 56 | + | ||
| 57 | + private static final String ICON_ID_ONLINE = "active"; | ||
| 58 | + private static final String ICON_ID_OFFLINE = "inactive"; | ||
| 59 | + | ||
| 56 | @Override | 60 | @Override |
| 57 | protected Collection<RequestHandler> getHandlers() { | 61 | protected Collection<RequestHandler> getHandlers() { |
| 58 | return ImmutableSet.of(new LinkDataRequest()); | 62 | return ImmutableSet.of(new LinkDataRequest()); |
| ... | @@ -65,48 +69,51 @@ public class LinkViewMessageHandler extends UiMessageHandler { | ... | @@ -65,48 +69,51 @@ public class LinkViewMessageHandler extends UiMessageHandler { |
| 65 | } | 69 | } |
| 66 | 70 | ||
| 67 | @Override | 71 | @Override |
| 68 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 72 | + protected String[] getColumnIds() { |
| 69 | - LinkService service = get(LinkService.class); | 73 | + return COL_IDS; |
| 70 | - List<TableRow> list = new ArrayList<>(); | 74 | + } |
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + protected String defaultColumnId() { | ||
| 78 | + return ONE; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + protected TableModel createTableModel() { | ||
| 83 | + TableModel tm = super.createTableModel(); | ||
| 84 | + tm.setFormatter(ONE, ConnectPointFormatter.INSTANCE); | ||
| 85 | + tm.setFormatter(TWO, ConnectPointFormatter.INSTANCE); | ||
| 86 | + return tm; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + protected void populateTable(TableModel tm, ObjectNode payload) { | ||
| 91 | + LinkService ls = get(LinkService.class); | ||
| 71 | 92 | ||
| 72 | // First consolidate all uni-directional links into two-directional ones. | 93 | // First consolidate all uni-directional links into two-directional ones. |
| 73 | Map<LinkKey, BiLink> biLinks = Maps.newHashMap(); | 94 | Map<LinkKey, BiLink> biLinks = Maps.newHashMap(); |
| 74 | - service.getLinks().forEach(link -> addLink(biLinks, link)); | 95 | + ls.getLinks().forEach(link -> addLink(biLinks, link)); |
| 75 | 96 | ||
| 76 | // Now scan over all bi-links and produce table rows from them. | 97 | // Now scan over all bi-links and produce table rows from them. |
| 77 | - biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink))); | 98 | + biLinks.values().forEach(biLink -> populateRow(tm.addRow(), biLink)); |
| 78 | - return list.toArray(new TableRow[list.size()]); | ||
| 79 | } | 99 | } |
| 80 | 100 | ||
| 81 | - @Override | 101 | + private void populateRow(TableModel.Row row, BiLink biLink) { |
| 82 | - protected String defaultColId() { | 102 | + row.cell(ONE, biLink.one.src()) |
| 83 | - return ONE; | 103 | + .cell(TWO, biLink.one.dst()) |
| 104 | + .cell(TYPE, linkType(biLink)) | ||
| 105 | + .cell(STATE, linkState(biLink)) | ||
| 106 | + .cell(DIRECTION, linkDir(biLink)) | ||
| 107 | + .cell(DURABLE, biLink.one.isDurable()); | ||
| 84 | } | 108 | } |
| 85 | - } | ||
| 86 | 109 | ||
| 87 | - /** | 110 | + private String linkType(BiLink link) { |
| 88 | - * TableRow implementation for {@link org.onosproject.net.Link links}. | 111 | + StringBuilder sb = new StringBuilder(); |
| 89 | - */ | 112 | + sb.append(link.one.type()); |
| 90 | - private static class LinkTableRow extends AbstractTableRow { | 113 | + if (link.two != null && link.two.type() != link.one.type()) { |
| 91 | - | 114 | + sb.append(" / ").append(link.two.type()); |
| 92 | - private static final String[] COL_IDS = { | 115 | + } |
| 93 | - ONE, TWO, TYPE, STATE, DIRECTION, DURABLE | 116 | + return sb.toString().toLowerCase(); |
| 94 | - }; | ||
| 95 | - | ||
| 96 | - private static final String ICON_ID_ONLINE = "active"; | ||
| 97 | - private static final String ICON_ID_OFFLINE = "inactive"; | ||
| 98 | - | ||
| 99 | - public LinkTableRow(BiLink link) { | ||
| 100 | - ConnectPoint src = link.one.src(); | ||
| 101 | - ConnectPoint dst = link.one.dst(); | ||
| 102 | - linkState(link); | ||
| 103 | - | ||
| 104 | - add(ONE, concat(src.elementId(), "/", src.port())); | ||
| 105 | - add(TWO, concat(dst.elementId(), "/", dst.port())); | ||
| 106 | - add(TYPE, linkType(link).toLowerCase()); | ||
| 107 | - add(STATE, linkState(link)); | ||
| 108 | - add(DIRECTION, link.two != null ? "A <--> B" : "A --> B"); | ||
| 109 | - add(DURABLE, Boolean.toString(link.one.isDurable())); | ||
| 110 | } | 117 | } |
| 111 | 118 | ||
| 112 | private String linkState(BiLink link) { | 119 | private String linkState(BiLink link) { |
| ... | @@ -115,16 +122,8 @@ public class LinkViewMessageHandler extends UiMessageHandler { | ... | @@ -115,16 +122,8 @@ public class LinkViewMessageHandler extends UiMessageHandler { |
| 115 | ICON_ID_ONLINE : ICON_ID_OFFLINE; | 122 | ICON_ID_ONLINE : ICON_ID_OFFLINE; |
| 116 | } | 123 | } |
| 117 | 124 | ||
| 118 | - private String linkType(BiLink link) { | 125 | + private String linkDir(BiLink link) { |
| 119 | - return link.two == null || link.one.type() == link.two.type() ? | 126 | + return link.two != null ? "A <--> B" : "A --> B"; |
| 120 | - link.one.type().toString() : | ||
| 121 | - link.one.type().toString() + " / " + link.two.type().toString(); | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - @Override | ||
| 125 | - protected String[] columnIds() { | ||
| 126 | - return COL_IDS; | ||
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | - | ||
| 130 | } | 129 | } | ... | ... |
| ... | @@ -24,13 +24,11 @@ import org.onosproject.net.device.DeviceService; | ... | @@ -24,13 +24,11 @@ import org.onosproject.net.device.DeviceService; |
| 24 | import org.onosproject.net.device.PortStatistics; | 24 | import org.onosproject.net.device.PortStatistics; |
| 25 | import org.onosproject.ui.RequestHandler; | 25 | import org.onosproject.ui.RequestHandler; |
| 26 | import org.onosproject.ui.UiMessageHandler; | 26 | import org.onosproject.ui.UiMessageHandler; |
| 27 | -import org.onosproject.ui.table.AbstractTableRow; | 27 | +import org.onosproject.ui.table.TableModel; |
| 28 | import org.onosproject.ui.table.TableRequestHandler; | 28 | import org.onosproject.ui.table.TableRequestHandler; |
| 29 | -import org.onosproject.ui.table.TableRow; | 29 | +import org.onosproject.ui.table.cell.LongComparator; |
| 30 | 30 | ||
| 31 | -import java.util.ArrayList; | ||
| 32 | import java.util.Collection; | 31 | import java.util.Collection; |
| 33 | -import java.util.List; | ||
| 34 | 32 | ||
| 35 | 33 | ||
| 36 | /** | 34 | /** |
| ... | @@ -51,6 +49,11 @@ public class PortViewMessageHandler extends UiMessageHandler { | ... | @@ -51,6 +49,11 @@ public class PortViewMessageHandler extends UiMessageHandler { |
| 51 | private static final String PKT_TX_DRP = "pkt_tx_drp"; | 49 | private static final String PKT_TX_DRP = "pkt_tx_drp"; |
| 52 | private static final String DURATION = "duration"; | 50 | private static final String DURATION = "duration"; |
| 53 | 51 | ||
| 52 | + private static final String[] COL_IDS = { | ||
| 53 | + ID, PKT_RX, PKT_TX, BYTES_RX, BYTES_TX, | ||
| 54 | + PKT_RX_DRP, PKT_TX_DRP, DURATION | ||
| 55 | + }; | ||
| 56 | + | ||
| 54 | @Override | 57 | @Override |
| 55 | protected Collection<RequestHandler> getHandlers() { | 58 | protected Collection<RequestHandler> getHandlers() { |
| 56 | return ImmutableSet.of(new PortDataRequest()); | 59 | return ImmutableSet.of(new PortDataRequest()); |
| ... | @@ -64,47 +67,44 @@ public class PortViewMessageHandler extends UiMessageHandler { | ... | @@ -64,47 +67,44 @@ public class PortViewMessageHandler extends UiMessageHandler { |
| 64 | } | 67 | } |
| 65 | 68 | ||
| 66 | @Override | 69 | @Override |
| 67 | - protected TableRow[] generateTableRows(ObjectNode payload) { | 70 | + protected String[] getColumnIds() { |
| 68 | - String uri = string(payload, "devId"); | 71 | + return COL_IDS; |
| 69 | - if (Strings.isNullOrEmpty(uri)) { | ||
| 70 | - return new TableRow[0]; | ||
| 71 | - } | ||
| 72 | - DeviceId deviceId = DeviceId.deviceId(uri); | ||
| 73 | - DeviceService service = get(DeviceService.class); | ||
| 74 | - List<TableRow> list = new ArrayList<>(); | ||
| 75 | - for (PortStatistics stat : service.getPortStatistics(deviceId)) { | ||
| 76 | - list.add(new PortTableRow(stat)); | ||
| 77 | - } | ||
| 78 | - return list.toArray(new TableRow[list.size()]); | ||
| 79 | } | 72 | } |
| 80 | - } | ||
| 81 | - | ||
| 82 | - /** | ||
| 83 | - * TableRow implementation for | ||
| 84 | - * {@link org.onosproject.net.device.PortStatistics port statistics}. | ||
| 85 | - */ | ||
| 86 | - private static class PortTableRow extends AbstractTableRow { | ||
| 87 | - | ||
| 88 | - private static final String[] COL_IDS = { | ||
| 89 | - ID, PKT_RX, PKT_TX, BYTES_RX, BYTES_TX, | ||
| 90 | - PKT_RX_DRP, PKT_TX_DRP, DURATION | ||
| 91 | - }; | ||
| 92 | 73 | ||
| 93 | - public PortTableRow(PortStatistics stat) { | 74 | + @Override |
| 94 | - add(ID, Integer.toString(stat.port())); | 75 | + protected TableModel createTableModel() { |
| 95 | - add(PKT_RX, Long.toString(stat.packetsReceived())); | 76 | + TableModel tm = super.createTableModel(); |
| 96 | - add(PKT_TX, Long.toString(stat.packetsSent())); | 77 | + tm.setComparator(PKT_RX, LongComparator.INSTANCE); |
| 97 | - add(BYTES_RX, Long.toString(stat.bytesReceived())); | 78 | + tm.setComparator(PKT_TX, LongComparator.INSTANCE); |
| 98 | - add(BYTES_TX, Long.toString(stat.bytesSent())); | 79 | + tm.setComparator(BYTES_RX, LongComparator.INSTANCE); |
| 99 | - add(PKT_RX_DRP, Long.toString(stat.packetsRxDropped())); | 80 | + tm.setComparator(BYTES_TX, LongComparator.INSTANCE); |
| 100 | - add(PKT_TX_DRP, Long.toString(stat.packetsTxDropped())); | 81 | + tm.setComparator(PKT_RX_DRP, LongComparator.INSTANCE); |
| 101 | - add(DURATION, Long.toString(stat.durationSec())); | 82 | + tm.setComparator(PKT_TX_DRP, LongComparator.INSTANCE); |
| 83 | + tm.setComparator(DURATION, LongComparator.INSTANCE); | ||
| 84 | + return tm; | ||
| 102 | } | 85 | } |
| 103 | 86 | ||
| 104 | @Override | 87 | @Override |
| 105 | - protected String[] columnIds() { | 88 | + protected void populateTable(TableModel tm, ObjectNode payload) { |
| 106 | - return COL_IDS; | 89 | + String uri = string(payload, "devId"); |
| 90 | + if (!Strings.isNullOrEmpty(uri)) { | ||
| 91 | + DeviceId deviceId = DeviceId.deviceId(uri); | ||
| 92 | + DeviceService ds = get(DeviceService.class); | ||
| 93 | + for (PortStatistics stat : ds.getPortStatistics(deviceId)) { | ||
| 94 | + populateRow(tm.addRow(), stat); | ||
| 95 | + } | ||
| 96 | + } | ||
| 107 | } | 97 | } |
| 108 | - } | ||
| 109 | 98 | ||
| 99 | + private void populateRow(TableModel.Row row, PortStatistics stat) { | ||
| 100 | + row.cell(ID, stat.port()) | ||
| 101 | + .cell(PKT_RX, stat.packetsReceived()) | ||
| 102 | + .cell(PKT_TX, stat.packetsSent()) | ||
| 103 | + .cell(BYTES_RX, stat.bytesReceived()) | ||
| 104 | + .cell(BYTES_TX, stat.bytesSent()) | ||
| 105 | + .cell(PKT_RX_DRP, stat.packetsRxDropped()) | ||
| 106 | + .cell(PKT_TX_DRP, stat.packetsTxDropped()) | ||
| 107 | + .cell(DURATION, stat.durationSec()); | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | } | 110 | } | ... | ... |
-
Please register or login to post a comment