GUI -- refactored all the table views (server side) to use the new TableModel method of data generation.
Change-Id: Ib8a188ad432ff335db6cff1e49e08dbaf039436b
diff --git a/core/api/src/main/java/org/onosproject/ui/table/AbstractTableRow.java b/core/api/src/main/java/org/onosproject/ui/table/AbstractTableRow.java
index 5dd11a4..9f456b9 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/AbstractTableRow.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/AbstractTableRow.java
@@ -26,6 +26,7 @@
/**
* Provides a partial implementation of {@link TableRow}.
*/
+@Deprecated
public abstract class AbstractTableRow implements TableRow {
private static final ObjectMapper MAPPER = new ObjectMapper();
diff --git a/core/api/src/main/java/org/onosproject/ui/table/RowComparator.java b/core/api/src/main/java/org/onosproject/ui/table/RowComparator.java
index 9859a65..86f25c1 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/RowComparator.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/RowComparator.java
@@ -21,6 +21,7 @@
/**
* Comparator for {@link TableRow}.
*/
+@Deprecated
public class RowComparator implements Comparator<TableRow> {
/** Designates the sort direction. */
public enum Direction {
diff --git a/core/api/src/main/java/org/onosproject/ui/table/TableModel.java b/core/api/src/main/java/org/onosproject/ui/table/TableModel.java
index 2c3ffc5..91e23be 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/TableModel.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/TableModel.java
@@ -46,8 +46,8 @@
*/
public class TableModel {
- private static final CellComparator DEF_CMP = new DefaultCellComparator();
- private static final CellFormatter DEF_FMT = new DefaultCellFormatter();
+ private static final CellComparator DEF_CMP = DefaultCellComparator.INSTANCE;
+ private static final CellFormatter DEF_FMT = DefaultCellFormatter.INSTANCE;
private final String[] columnIds;
private final Set<String> idSet;
@@ -99,13 +99,16 @@
}
/**
- * Returns the {@link TableRow} representation of the rows in this table.
+ * Returns the array of column IDs for this table model.
+ * <p>
+ * Implementation note: we are knowingly passing you a reference to
+ * our internal array to avoid copying. Don't mess with it. It's your
+ * table you'll break if you do!
*
- * @return formatted table rows
+ * @return the column identifiers
*/
- // TODO: still need to decide if we need this
- public TableRow[] getTableRows() {
- return new TableRow[0];
+ public String[] getColumnIds() {
+ return columnIds;
}
/**
@@ -113,7 +116,6 @@
*
* @return raw table rows
*/
- // TODO: still need to decide if we should expose this
public Row[] getRows() {
return rows.toArray(new Row[rows.size()]);
}
@@ -264,9 +266,22 @@
* @param columnId column identifier
* @return formatted cell value
*/
- public String getAsString(String columnId) {
+ String getAsString(String columnId) {
return getFormatter(columnId).format(get(columnId));
}
+
+ /**
+ * Returns the row as an array of formatted strings.
+ *
+ * @return the formatted row data
+ */
+ public String[] getAsFormattedStrings() {
+ List<String> formatted = new ArrayList<>(columnCount());
+ for (String c : columnIds) {
+ formatted.add(getAsString(c));
+ }
+ return formatted.toArray(new String[formatted.size()]);
+ }
}
private static final String DESC = "desc";
diff --git a/core/api/src/main/java/org/onosproject/ui/table/TableRequestHandler.java b/core/api/src/main/java/org/onosproject/ui/table/TableRequestHandler.java
index f90c187..b8d4857 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/TableRequestHandler.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/TableRequestHandler.java
@@ -17,10 +17,9 @@
package org.onosproject.ui.table;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.ui.JsonUtils;
import org.onosproject.ui.RequestHandler;
-import java.util.Arrays;
-
/**
* Message handler specifically for table views.
*/
@@ -47,29 +46,66 @@
@Override
public void process(long sid, ObjectNode payload) {
- RowComparator rc = TableUtils.createRowComparator(payload, defaultColId());
- TableRow[] rows = generateTableRows(payload);
- Arrays.sort(rows, rc);
+ TableModel tm = createTableModel();
+ populateTable(tm, payload);
+
+ String sortCol = JsonUtils.string(payload, "sortCol", defaultColumnId());
+ String sortDir = JsonUtils.string(payload, "sortDir", "asc");
+ tm.sort(sortCol, TableModel.sortDir(sortDir));
+
ObjectNode rootNode = MAPPER.createObjectNode();
- rootNode.set(nodeName, TableUtils.generateArrayNode(rows));
+ rootNode.set(nodeName, TableUtils.generateArrayNode(tm));
sendMessage(respType, 0, rootNode);
}
/**
- * Returns the default column ID, when one is not supplied in the payload
- * defining the column on which to sort. This implementation returns "id".
+ * Creates the table model (devoid of data) using {@link #getColumnIds()}
+ * to initialize it, ready to be populated.
+ * <p>
+ * This default implementation returns a table model with default
+ * formatters and comparators for all columns.
*
- * @return default sort column id
+ * @return an empty table model
*/
- protected String defaultColId() {
+ protected TableModel createTableModel() {
+ return new TableModel(getColumnIds());
+ }
+
+ /**
+ * Returns the default column ID to be used when one is not supplied in
+ * the payload as the column on which to sort.
+ * <p>
+ * This default implementation returns "id".
+ *
+ * @return default sort column identifier
+ */
+ protected String defaultColumnId() {
return "id";
}
/**
- * Subclasses should generate table rows for their specific table instance.
+ * Subclasses should return the array of column IDs with which
+ * to initialize their table model.
*
- * @param payload provided in case custom parameters are present
- * @return generated table rows
+ * @return the column IDs
*/
- protected abstract TableRow[] generateTableRows(ObjectNode payload);
+ protected abstract String[] getColumnIds();
+
+ /**
+ * Subclasses should populate the table model by adding
+ * {@link TableModel.Row rows}.
+ * <pre>
+ * tm.addRow()
+ * .cell(COL_ONE, ...)
+ * .cell(COL_TWO, ...)
+ * ... ;
+ * </pre>
+ * The request payload is provided in case there are request filtering
+ * parameters (other than sort column and sort direction) that are required
+ * to generate the appropriate data.
+ *
+ * @param tm the table model
+ * @param payload request payload
+ */
+ protected abstract void populateTable(TableModel tm, ObjectNode payload);
}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/TableRow.java b/core/api/src/main/java/org/onosproject/ui/table/TableRow.java
index 4775687..1824be8 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/TableRow.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/TableRow.java
@@ -22,6 +22,7 @@
/**
* Defines a table row abstraction to support sortable tables on the GUI.
*/
+@Deprecated
public interface TableRow {
// TODO: Define TableCell interface and return that, rather than String
diff --git a/core/api/src/main/java/org/onosproject/ui/table/TableUtils.java b/core/api/src/main/java/org/onosproject/ui/table/TableUtils.java
index 9f63cba..eb2dff7 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/TableUtils.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/TableUtils.java
@@ -16,10 +16,10 @@
package org.onosproject.ui.table;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.ui.JsonUtils;
/**
* Provides static utility methods for dealing with tables.
@@ -32,46 +32,27 @@
private TableUtils() { }
/**
- * Produces a JSON array node from the specified table rows.
+ * Generates a JSON array node from a table model.
*
- * @param rows table rows
- * @return JSON array
+ * @param tm the table model
+ * @return the array node representation
*/
- public static ArrayNode generateArrayNode(TableRow[] rows) {
+ public static ArrayNode generateArrayNode(TableModel tm) {
ArrayNode array = MAPPER.createArrayNode();
- for (TableRow r : rows) {
- array.add(r.toJsonNode());
+ for (TableModel.Row r : tm.getRows()) {
+ array.add(toJsonNode(r, tm));
}
return array;
}
- /**
- * Creates a row comparator for the given request. The ID of the column
- * to sort on is the payload's "sortCol" property (defaults to "id").
- * The direction for the sort is the payload's "sortDir" property
- * (defaults to "asc").
- *
- * @param payload the event payload
- * @return a row comparator
- */
- public static RowComparator createRowComparator(ObjectNode payload) {
- return createRowComparator(payload, "id");
- }
-
- /**
- * Creates a row comparator for the given request. The ID of the column to
- * sort on is the payload's "sortCol" property (or the specified default).
- * The direction for the sort is the payload's "sortDir" property
- * (defaults to "asc").
- *
- * @param payload the event payload
- * @param defColId the default column ID
- * @return a row comparator
- */
- public static RowComparator createRowComparator(ObjectNode payload,
- String defColId) {
- String sortCol = JsonUtils.string(payload, "sortCol", defColId);
- String sortDir = JsonUtils.string(payload, "sortDir", "asc");
- return new RowComparator(sortCol, RowComparator.direction(sortDir));
+ private static JsonNode toJsonNode(TableModel.Row row, TableModel tm) {
+ ObjectNode result = MAPPER.createObjectNode();
+ String[] keys = tm.getColumnIds();
+ String[] cells = row.getAsFormattedStrings();
+ int n = keys.length;
+ for (int i = 0; i < n; i++) {
+ result.put(keys[i], cells[i]);
+ }
+ return result;
}
}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java
new file mode 100644
index 0000000..f6ccf2c0
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.table.cell;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats an application identifier as "(app-id) : (app-name)".
+ */
+public class AppIdFormatter extends AbstractCellFormatter {
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ ApplicationId appId = (ApplicationId) value;
+ return appId.id() + " : " + appId.name();
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new AppIdFormatter();
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.java
new file mode 100644
index 0000000..18f7233
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.table.cell;
+
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats a connect point as "(element-id)/(port)".
+ */
+public class ConnectPointFormatter extends AbstractCellFormatter {
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ ConnectPoint cp = (ConnectPoint) value;
+ return cp.elementId() + "/" + cp.port();
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new ConnectPointFormatter();
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java b/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java
index 7846f89..fa49755 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java
@@ -17,6 +17,8 @@
package org.onosproject.ui.table.cell;
+import org.onosproject.ui.table.CellComparator;
+
/**
* A default cell comparator. Implements a lexicographical compare function
* (i.e. string sorting). Uses the objects' toString() method and then
@@ -24,8 +26,14 @@
* are considered "smaller" than any non-null value.
*/
public class DefaultCellComparator extends AbstractCellComparator {
+
@Override
protected int nonNullCompare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
}
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellComparator INSTANCE = new DefaultCellComparator();
}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java
index c030236..5e4f5ba 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java
@@ -17,12 +17,20 @@
package org.onosproject.ui.table.cell;
+import org.onosproject.ui.table.CellFormatter;
+
/**
* A default cell formatter. Uses the object's toString() method.
*/
public class DefaultCellFormatter extends AbstractCellFormatter {
+
@Override
public String nonNullFormat(Object value) {
return value.toString();
}
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new DefaultCellFormatter();
}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java
index d4aaade..8104f48 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java
@@ -17,12 +17,20 @@
package org.onosproject.ui.table.cell;
+import org.onosproject.ui.table.CellFormatter;
+
/**
- * Formats integer values as hex strings.
+ * Formats integer values as hex strings with a "0x" prefix.
*/
public class HexFormatter extends AbstractCellFormatter {
+
@Override
protected String nonNullFormat(Object value) {
return "0x" + Integer.toHexString((Integer) value);
}
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new HexFormatter();
}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.java
new file mode 100644
index 0000000..9d6024d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.table.cell;
+
+import org.onosproject.net.HostLocation;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats a host location as "(device-id)/(port)".
+ */
+public class HostLocationFormatter extends AbstractCellFormatter {
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ HostLocation loc = (HostLocation) value;
+ return loc.deviceId() + "/" + loc.port();
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new HostLocationFormatter();
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/IntComparator.java b/core/api/src/main/java/org/onosproject/ui/table/cell/IntComparator.java
index c399d53..ddd90eb 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/cell/IntComparator.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/IntComparator.java
@@ -17,14 +17,22 @@
package org.onosproject.ui.table.cell;
+import org.onosproject.ui.table.CellComparator;
+
/**
* An integer-based cell comparator.
* Note that null values are acceptable and are considered "smaller" than
* any non-null value.
*/
public class IntComparator extends AbstractCellComparator {
+
@Override
protected int nonNullCompare(Object o1, Object o2) {
return ((int) o1) - ((int) o2);
}
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellComparator INSTANCE = new IntComparator();
}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/LongComparator.java b/core/api/src/main/java/org/onosproject/ui/table/cell/LongComparator.java
new file mode 100644
index 0000000..3234e50
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/LongComparator.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.table.cell;
+
+import org.onosproject.ui.table.CellComparator;
+
+/**
+ * A long-based cell comparator.
+ * Note that null values are acceptable and are considered "smaller" than
+ * any non-null value.
+ */
+public class LongComparator extends AbstractCellComparator {
+
+ @Override
+ protected int nonNullCompare(Object o1, Object o2) {
+ long diff = ((long) o1) - ((long) o2);
+ return diff == 0 ? 0 : (diff < 0 ? -1 : 1);
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellComparator INSTANCE = new LongComparator();
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
new file mode 100644
index 0000000..e0aec9d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.table.cell;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats time values using {@link DateTimeFormatter}.
+ */
+public class TimeFormatter extends AbstractCellFormatter {
+
+ private static final DateTimeFormatter DTF = DateTimeFormat.longTime();
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ return DTF.print((DateTime) value);
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new TimeFormatter();
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java b/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java
index 40a9672..53725f2 100644
--- a/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java
@@ -45,7 +45,6 @@
private TableModel tm;
private TableModel.Row[] rows;
private TableModel.Row row;
- private TableRow[] tableRows;
private CellFormatter fmt;
@Test(expected = NullPointerException.class)
@@ -68,9 +67,6 @@
tm = new TableModel(FOO, BAR);
assertEquals("column count", 2, tm.columnCount());
assertEquals("row count", 0, tm.rowCount());
-
- tableRows = tm.getTableRows();
- assertEquals("row count alt", 0, tableRows.length);
}
@Test
@@ -225,7 +221,7 @@
initUnsortedTable();
// first, tell the table to use an integer-based comparator
- tm.setComparator(BAR, new IntComparator());
+ tm.setComparator(BAR, IntComparator.INSTANCE);
// sort by number
tm.sort(BAR, SortDir.ASC);
@@ -256,8 +252,8 @@
initUnsortedTable();
// set integer-based comparator and hex formatter
- tm.setComparator(BAR, new IntComparator());
- tm.setFormatter(BAR, new HexFormatter());
+ tm.setComparator(BAR, IntComparator.INSTANCE);
+ tm.setFormatter(BAR, HexFormatter.INSTANCE);
// sort by number
tm.sort(BAR, SortDir.ASC);
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java
index d4cd8ed..38c6bed 100644
--- a/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java
@@ -39,7 +39,7 @@
private static final int NUMBER = 42;
private static final TestClass OBJECT = new TestClass();
- private CellComparator cmp = new DefaultCellComparator();
+ private CellComparator cmp = DefaultCellComparator.INSTANCE;
@Test
public void sameString() {
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java
index 8934f48..6351a1f 100644
--- a/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java
@@ -37,7 +37,7 @@
}
}
- private CellFormatter fmt = new DefaultCellFormatter();
+ private CellFormatter fmt = DefaultCellFormatter.INSTANCE;
@Test
public void formatNull() {
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java
index 738fbdd..ad23b02 100644
--- a/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java
@@ -18,6 +18,7 @@
package org.onosproject.ui.table.cell;
import org.junit.Test;
+import org.onosproject.ui.table.CellFormatter;
import static org.junit.Assert.assertEquals;
@@ -26,7 +27,7 @@
*/
public class HexFormatterTest {
- private HexFormatter fmt = new HexFormatter();
+ private CellFormatter fmt = HexFormatter.INSTANCE;
@Test
public void nullValue() {
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/IntComparatorTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/IntComparatorTest.java
index 2b45b3f..9455329 100644
--- a/core/api/src/test/java/org/onosproject/ui/table/cell/IntComparatorTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/IntComparatorTest.java
@@ -27,7 +27,7 @@
*/
public class IntComparatorTest {
- private CellComparator cmp = new IntComparator();
+ private CellComparator cmp = IntComparator.INSTANCE;
@Test
public void twoNulls() {
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java
index 6a00f13..61a543a 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/ApplicationViewMessageHandler.java
@@ -24,13 +24,10 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
import static org.onosproject.app.ApplicationState.ACTIVE;
@@ -55,6 +52,10 @@
private static final String ICON_ID_ACTIVE = "active";
private static final String ICON_ID_INACTIVE = "appInactive";
+ private static final String[] COL_IDS = {
+ STATE, STATE_IID, ID, VERSION, ORIGIN, DESC
+ };
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(
@@ -70,14 +71,31 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- ApplicationService service = get(ApplicationService.class);
- List<TableRow> list = service.getApplications().stream()
- .map(application -> new ApplicationTableRow(service, application))
- .collect(Collectors.toList());
- return list.toArray(new TableRow[list.size()]);
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ ApplicationService as = get(ApplicationService.class);
+ for (Application app : as.getApplications()) {
+ populateRow(tm.addRow(), app, as);
+ }
+ }
+
+ private void populateRow(TableModel.Row row, Application app,
+ ApplicationService as) {
+ ApplicationId id = app.id();
+ ApplicationState state = as.getState(id);
+ String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE;
+
+ row.cell(STATE, state)
+ .cell(STATE_IID, iconId)
+ .cell(ID, id.name())
+ .cell(VERSION, app.version())
+ .cell(ORIGIN, app.origin())
+ .cell(DESC, app.description());
+ }
}
// handler for application management control button actions
@@ -104,33 +122,4 @@
}
}
}
-
- /**
- * TableRow implementation for
- * {@link org.onosproject.core.Application applications}.
- */
- private static class ApplicationTableRow extends AbstractTableRow {
-
- private static final String[] COL_IDS = {
- STATE, STATE_IID, ID, VERSION, ORIGIN, DESC
- };
-
- public ApplicationTableRow(ApplicationService service, Application app) {
- ApplicationState state = service.getState(app.id());
- String iconId = state == ACTIVE ? ICON_ID_ACTIVE : ICON_ID_INACTIVE;
-
- add(STATE, state);
- add(STATE_IID, iconId);
- add(ID, app.id().name());
- add(VERSION, app.version());
- add(ORIGIN, app.origin());
- add(DESC, app.description());
- }
-
- @Override
- protected String[] columnIds() {
- return COL_IDS;
- }
- }
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java
index 1199b13..ab0da70 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java
@@ -19,19 +19,17 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.joda.time.DateTime;
-import org.joda.time.format.DateTimeFormat;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.IntComparator;
+import org.onosproject.ui.table.cell.TimeFormatter;
import java.util.Collection;
-import java.util.List;
-import java.util.stream.Collectors;
/**
@@ -49,6 +47,13 @@
private static final String STATE_IID = "_iconid_state";
private static final String UPDATED = "updated";
+ private static final String[] COL_IDS = {
+ ID, IP, TCP_PORT, STATE_IID, UPDATED
+ };
+
+ private static final String ICON_ID_ONLINE = "active";
+ private static final String ICON_ID_OFFLINE = "inactive";
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new ClusterDataRequest());
@@ -61,45 +66,38 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- ClusterService service = get(ClusterService.class);
- List<TableRow> list = service.getNodes().stream()
- .map(node -> new ControllerNodeTableRow(service, node))
- .collect(Collectors.toList());
- return list.toArray(new TableRow[list.size()]);
- }
- }
-
- /**
- * TableRow implementation for {@link ControllerNode controller nodes}.
- */
- private static class ControllerNodeTableRow extends AbstractTableRow {
-
- private static final String[] COL_IDS = {
- ID, IP, TCP_PORT, STATE_IID, UPDATED
- };
-
- private static final String ICON_ID_ONLINE = "active";
- private static final String ICON_ID_OFFLINE = "inactive";
-
- public ControllerNodeTableRow(ClusterService service, ControllerNode n) {
- NodeId id = n.id();
- DateTime lastUpdated = service.getLastUpdated(id);
- org.joda.time.format.DateTimeFormatter format = DateTimeFormat.longTime();
- String iconId = (service.getState(id) == ControllerNode.State.ACTIVE) ?
- ICON_ID_ONLINE : ICON_ID_OFFLINE;
-
- add(ID, id.toString());
- add(IP, n.ip().toString());
- add(TCP_PORT, Integer.toString(n.tcpPort()));
- add(STATE_IID, iconId);
- add(UPDATED, format.print(lastUpdated));
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
@Override
- protected String[] columnIds() {
- return COL_IDS;
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setComparator(TCP_PORT, IntComparator.INSTANCE);
+ tm.setFormatter(UPDATED, TimeFormatter.INSTANCE);
+ return tm;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ ClusterService cs = get(ClusterService.class);
+ for (ControllerNode node : cs.getNodes()) {
+ populateRow(tm.addRow(), node, cs);
+ }
+ }
+
+ private void populateRow(TableModel.Row row, ControllerNode node,
+ ClusterService cs) {
+ NodeId id = node.id();
+ DateTime lastUpdated = cs.getLastUpdated(id);
+ String iconId = (cs.getState(id) == ControllerNode.State.ACTIVE) ?
+ ICON_ID_ONLINE : ICON_ID_OFFLINE;
+
+ row.cell(ID, id)
+ .cell(IP, node.ip())
+ .cell(TCP_PORT, node.tcpPort())
+ .cell(STATE_IID, iconId)
+ .cell(UPDATED, lastUpdated);
}
}
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java
index 806e8c6..22c1723 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java
@@ -29,9 +29,9 @@
import org.onosproject.net.link.LinkService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.IntComparator;
import java.util.ArrayList;
import java.util.Collection;
@@ -73,6 +73,15 @@
private static final String NAME = "name";
+ private static final String[] COL_IDS = {
+ AVAILABLE, AVAILABLE_IID, TYPE_IID, ID,
+ NUM_PORTS, MASTER_ID, MFR, HW, SW,
+ PROTOCOL, CHASSIS_ID, SERIAL
+ };
+
+ private static final String ICON_ID_ONLINE = "active";
+ private static final String ICON_ID_OFFLINE = "inactive";
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(
@@ -81,6 +90,10 @@
);
}
+ private static String getTypeIconId(Device d) {
+ return DEV_ICON_PREFIX + d.type().toString();
+ }
+
// handler for device table requests
private final class DataRequestHandler extends TableRequestHandler {
private DataRequestHandler() {
@@ -88,14 +101,42 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- DeviceService service = get(DeviceService.class);
- MastershipService mastershipService = get(MastershipService.class);
- List<TableRow> list = new ArrayList<>();
- for (Device dev : service.getDevices()) {
- list.add(new DeviceTableRow(service, mastershipService, dev));
+ protected String[] getColumnIds() {
+ return COL_IDS;
+ }
+
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setComparator(NUM_PORTS, IntComparator.INSTANCE);
+ return tm;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ DeviceService ds = get(DeviceService.class);
+ MastershipService ms = get(MastershipService.class);
+ for (Device dev : ds.getDevices()) {
+ populateRow(tm.addRow(), dev, ds, ms);
}
- return list.toArray(new TableRow[list.size()]);
+ }
+
+ private void populateRow(TableModel.Row row, Device dev,
+ DeviceService ds, MastershipService ms) {
+ DeviceId id = dev.id();
+ boolean available = ds.isAvailable(id);
+ String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
+
+ row.cell(ID, id)
+ .cell(AVAILABLE, available)
+ .cell(AVAILABLE_IID, iconId)
+ .cell(TYPE_IID, getTypeIconId(dev))
+ .cell(MFR, dev.manufacturer())
+ .cell(HW, dev.hwVersion())
+ .cell(SW, dev.swVersion())
+ .cell(PROTOCOL, dev.annotations().value(PROTOCOL))
+ .cell(NUM_PORTS, ds.getPorts(id).size())
+ .cell(MASTER_ID, ms.getMasterFor(id));
}
}
@@ -168,51 +209,5 @@
return port;
}
-
}
-
- private static String getTypeIconId(Device d) {
- return DEV_ICON_PREFIX + d.type().toString();
- }
-
- /**
- * TableRow implementation for {@link Device devices}.
- */
- private static class DeviceTableRow extends AbstractTableRow {
-
- private static final String[] COL_IDS = {
- AVAILABLE, AVAILABLE_IID, TYPE_IID, ID,
- NUM_PORTS, MASTER_ID, MFR, HW, SW,
- PROTOCOL, CHASSIS_ID, SERIAL
- };
-
- private static final String ICON_ID_ONLINE = "active";
- private static final String ICON_ID_OFFLINE = "inactive";
-
- public DeviceTableRow(DeviceService service,
- MastershipService ms,
- Device d) {
- boolean available = service.isAvailable(d.id());
- String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
- DeviceId id = d.id();
- List<Port> ports = service.getPorts(id);
-
- add(ID, id.toString());
- add(AVAILABLE, Boolean.toString(available));
- add(AVAILABLE_IID, iconId);
- add(TYPE_IID, getTypeIconId(d));
- add(MFR, d.manufacturer());
- add(HW, d.hwVersion());
- add(SW, d.swVersion());
- add(PROTOCOL, d.annotations().value(PROTOCOL));
- add(NUM_PORTS, Integer.toString(ports.size()));
- add(MASTER_ID, ms.getMasterFor(d.id()).toString());
- }
-
- @Override
- protected String[] columnIds() {
- return COL_IDS;
- }
- }
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java
index 5a795ed..61417cd 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java
@@ -28,11 +28,11 @@
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.IntComparator;
+import org.onosproject.ui.table.cell.LongComparator;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -64,6 +64,11 @@
private static final String COMMA = ", ";
+ private static final String[] COL_IDS = {
+ ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR,
+ TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES
+ };
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new FlowDataRequest());
@@ -77,45 +82,47 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- String uri = string(payload, "devId");
- if (Strings.isNullOrEmpty(uri)) {
- return new TableRow[0];
- }
- DeviceId deviceId = DeviceId.deviceId(uri);
- FlowRuleService service = get(FlowRuleService.class);
- List<TableRow> list = new ArrayList<>();
- for (FlowEntry flow : service.getFlowEntries(deviceId)) {
- list.add(new FlowTableRow(flow));
- }
- return list.toArray(new TableRow[list.size()]);
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
- }
- /**
- * TableRow implementation for
- * {@link org.onosproject.net.flow.FlowRule flows}.
- */
- private static class FlowTableRow extends AbstractTableRow {
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setComparator(GROUP_ID, IntComparator.INSTANCE);
+ tm.setComparator(TABLE_ID, IntComparator.INSTANCE);
+ tm.setComparator(PRIORITY, IntComparator.INSTANCE);
+ tm.setComparator(TIMEOUT, IntComparator.INSTANCE);
+ tm.setComparator(PACKETS, LongComparator.INSTANCE);
+ tm.setComparator(BYTES, LongComparator.INSTANCE);
+ return tm;
+ }
- private static final String[] COL_IDS = {
- ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR,
- TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES
- };
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ String uri = string(payload, "devId");
+ if (!Strings.isNullOrEmpty(uri)) {
+ DeviceId deviceId = DeviceId.deviceId(uri);
+ FlowRuleService frs = get(FlowRuleService.class);
+ for (FlowEntry flow : frs.getFlowEntries(deviceId)) {
+ populateRow(tm.addRow(), flow);
+ }
+ }
+ }
- public FlowTableRow(FlowEntry f) {
- add(ID, f.id().value());
- add(APP_ID, f.appId());
- add(GROUP_ID, f.groupId().id());
- add(TABLE_ID, f.tableId());
- add(PRIORITY, f.priority());
- add(SELECTOR, getSelectorString(f));
- add(TREATMENT, getTreatmentString(f));
- add(TIMEOUT, f.timeout());
- add(PERMANENT, f.isPermanent());
- add(STATE, capitalizeFully(f.state().toString()));
- add(PACKETS, f.packets());
- add(BYTES, f.packets());
+ private void populateRow(TableModel.Row row, FlowEntry flow) {
+ row.cell(ID, flow.id().value())
+ .cell(APP_ID, flow.appId())
+ .cell(GROUP_ID, flow.groupId().id())
+ .cell(TABLE_ID, flow.tableId())
+ .cell(PRIORITY, flow.priority())
+ .cell(SELECTOR, getSelectorString(flow))
+ .cell(TREATMENT, getTreatmentString(flow))
+ .cell(TIMEOUT, flow.timeout())
+ .cell(PERMANENT, flow.isPermanent())
+ .cell(STATE, capitalizeFully(flow.state().toString()))
+ .cell(PACKETS, flow.packets())
+ .cell(BYTES, flow.bytes());
}
private String getSelectorString(FlowEntry f) {
@@ -184,11 +191,5 @@
sb.delete(pos, sb.length());
return sb;
}
-
- @Override
- protected String[] columnIds() {
- return COL_IDS;
- }
}
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java
index e20b3e1..643fe40 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/HostViewMessageHandler.java
@@ -19,17 +19,14 @@
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Host;
-import org.onosproject.net.HostLocation;
import org.onosproject.net.host.HostService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.HostLocationFormatter;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -51,6 +48,9 @@
private static final String HOST_ICON_PREFIX = "hostIcon_";
+ private static final String[] COL_IDS = {
+ TYPE_IID, ID, MAC, VLAN, IPS, LOCATION
+ };
@Override
protected Collection<RequestHandler> getHandlers() {
@@ -64,34 +64,32 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- HostService service = get(HostService.class);
- List<TableRow> list = new ArrayList<>();
- for (Host host : service.getHosts()) {
- list.add(new HostTableRow(host));
- }
- return list.toArray(new TableRow[list.size()]);
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
- }
- /**
- * TableRow implementation for {@link Host hosts}.
- */
- private static class HostTableRow extends AbstractTableRow {
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setFormatter(LOCATION, HostLocationFormatter.INSTANCE);
+ return tm;
+ }
- private static final String[] COL_IDS = {
- TYPE_IID, ID, MAC, VLAN, IPS, LOCATION
- };
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ HostService hs = get(HostService.class);
+ for (Host host : hs.getHosts()) {
+ populateRow(tm.addRow(), host);
+ }
+ }
- public HostTableRow(Host h) {
- HostLocation location = h.location();
-
- add(TYPE_IID, getTypeIconId(h));
- add(ID, h.id());
- add(MAC, h.mac());
- add(VLAN, h.vlan());
- add(IPS, h.ipAddresses());
- add(LOCATION, concat(location.deviceId(), "/", location.port()));
+ private void populateRow(TableModel.Row row, Host host) {
+ row.cell(TYPE_IID, getTypeIconId(host))
+ .cell(ID, host.id())
+ .cell(MAC, host.mac())
+ .cell(VLAN, host.vlan())
+ .cell(IPS, host.ipAddresses())
+ .cell(LOCATION, host.location());
}
private String getTypeIconId(Host host) {
@@ -99,11 +97,5 @@
return HOST_ICON_PREFIX +
(isNullOrEmpty(hostType) ? "endstation" : hostType);
}
-
- @Override
- protected String[] columnIds() {
- return COL_IDS;
- }
}
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java
index 6d4ef6d..2ab2f08 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/IntentViewMessageHandler.java
@@ -17,7 +17,6 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
-import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
@@ -33,11 +32,11 @@
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.AppIdFormatter;
+import org.onosproject.ui.table.cell.IntComparator;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -58,6 +57,10 @@
private static final String RESOURCES = "resources";
private static final String DETAILS = "details";
+ private static final String[] COL_IDS = {
+ APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS
+ };
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new IntentDataRequest());
@@ -70,30 +73,42 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- IntentService service = get(IntentService.class);
- List<TableRow> list = new ArrayList<>();
- for (Intent intent : service.getIntents()) {
- list.add(new IntentTableRow(intent));
- }
- return list.toArray(new TableRow[list.size()]);
+ protected String defaultColumnId() {
+ return APP_ID;
}
@Override
- protected String defaultColId() {
- return APP_ID;
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
- }
- /**
- * TableRow implementation for {@link Intent intents}.
- */
- private static class IntentTableRow extends AbstractTableRow {
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setComparator(PRIORITY, IntComparator.INSTANCE);
+ tm.setFormatter(APP_ID, AppIdFormatter.INSTANCE);
+ return tm;
+ }
- private static final String[] COL_IDS = {
- APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS
- };
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ IntentService is = get(IntentService.class);
+ for (Intent intent : is.getIntents()) {
+ populateRow(tm.addRow(), intent);
+ }
+ }
+ private void populateRow(TableModel.Row row, Intent intent) {
+ row.cell(APP_ID, intent.appId())
+ .cell(KEY, intent.key())
+ .cell(TYPE, intent.getClass().getSimpleName())
+ .cell(PRIORITY, intent.priority())
+ .cell(RESOURCES, formatResources(intent))
+ .cell(DETAILS, formatDetails(intent));
+ }
+
+
+ // == TODO: Review -- Move the following code to a helper class?
private StringBuilder details = new StringBuilder();
private void appendMultiPointsDetails(Set<ConnectPoint> points) {
@@ -217,25 +232,8 @@
private String formatResources(Intent intent) {
return (intent.resources().isEmpty() ?
- "(No resources for this intent)" :
- "Resources: " + intent.resources());
- }
-
- public IntentTableRow(Intent intent) {
- ApplicationId appid = intent.appId();
-
- add(APP_ID, concat(appid.id(), " : ", appid.name()));
- add(KEY, intent.key());
- add(TYPE, intent.getClass().getSimpleName());
- add(PRIORITY, intent.priority());
- add(RESOURCES, formatResources(intent));
- add(DETAILS, formatDetails(intent));
- }
-
- @Override
- protected String[] columnIds() {
- return COL_IDS;
+ "(No resources for this intent)" :
+ "Resources: " + intent.resources());
}
}
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java
index ae7f489..e361563 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/LinkViewMessageHandler.java
@@ -19,20 +19,17 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
-import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.link.LinkService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.impl.TopologyViewMessageHandlerBase.BiLink;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.ConnectPointFormatter;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import static org.onosproject.ui.impl.TopologyViewMessageHandlerBase.addLink;
@@ -53,6 +50,13 @@
private static final String DIRECTION = "direction";
private static final String DURABLE = "durable";
+ private static final String[] COL_IDS = {
+ ONE, TWO, TYPE, STATE, DIRECTION, DURABLE
+ };
+
+ private static final String ICON_ID_ONLINE = "active";
+ private static final String ICON_ID_OFFLINE = "inactive";
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new LinkDataRequest());
@@ -65,48 +69,51 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- LinkService service = get(LinkService.class);
- List<TableRow> list = new ArrayList<>();
-
- // First consolidate all uni-directional links into two-directional ones.
- Map<LinkKey, BiLink> biLinks = Maps.newHashMap();
- service.getLinks().forEach(link -> addLink(biLinks, link));
-
- // Now scan over all bi-links and produce table rows from them.
- biLinks.values().forEach(biLink -> list.add(new LinkTableRow(biLink)));
- return list.toArray(new TableRow[list.size()]);
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
@Override
- protected String defaultColId() {
+ protected String defaultColumnId() {
return ONE;
}
- }
- /**
- * TableRow implementation for {@link org.onosproject.net.Link links}.
- */
- private static class LinkTableRow extends AbstractTableRow {
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setFormatter(ONE, ConnectPointFormatter.INSTANCE);
+ tm.setFormatter(TWO, ConnectPointFormatter.INSTANCE);
+ return tm;
+ }
- private static final String[] COL_IDS = {
- ONE, TWO, TYPE, STATE, DIRECTION, DURABLE
- };
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ LinkService ls = get(LinkService.class);
- private static final String ICON_ID_ONLINE = "active";
- private static final String ICON_ID_OFFLINE = "inactive";
+ // First consolidate all uni-directional links into two-directional ones.
+ Map<LinkKey, BiLink> biLinks = Maps.newHashMap();
+ ls.getLinks().forEach(link -> addLink(biLinks, link));
- public LinkTableRow(BiLink link) {
- ConnectPoint src = link.one.src();
- ConnectPoint dst = link.one.dst();
- linkState(link);
+ // Now scan over all bi-links and produce table rows from them.
+ biLinks.values().forEach(biLink -> populateRow(tm.addRow(), biLink));
+ }
- add(ONE, concat(src.elementId(), "/", src.port()));
- add(TWO, concat(dst.elementId(), "/", dst.port()));
- add(TYPE, linkType(link).toLowerCase());
- add(STATE, linkState(link));
- add(DIRECTION, link.two != null ? "A <--> B" : "A --> B");
- add(DURABLE, Boolean.toString(link.one.isDurable()));
+ private void populateRow(TableModel.Row row, BiLink biLink) {
+ row.cell(ONE, biLink.one.src())
+ .cell(TWO, biLink.one.dst())
+ .cell(TYPE, linkType(biLink))
+ .cell(STATE, linkState(biLink))
+ .cell(DIRECTION, linkDir(biLink))
+ .cell(DURABLE, biLink.one.isDurable());
+ }
+
+ private String linkType(BiLink link) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(link.one.type());
+ if (link.two != null && link.two.type() != link.one.type()) {
+ sb.append(" / ").append(link.two.type());
+ }
+ return sb.toString().toLowerCase();
}
private String linkState(BiLink link) {
@@ -115,16 +122,8 @@
ICON_ID_ONLINE : ICON_ID_OFFLINE;
}
- private String linkType(BiLink link) {
- return link.two == null || link.one.type() == link.two.type() ?
- link.one.type().toString() :
- link.one.type().toString() + " / " + link.two.type().toString();
- }
-
- @Override
- protected String[] columnIds() {
- return COL_IDS;
+ private String linkDir(BiLink link) {
+ return link.two != null ? "A <--> B" : "A --> B";
}
}
-
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/PortViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/PortViewMessageHandler.java
index 796207c..a6b5818 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/PortViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/PortViewMessageHandler.java
@@ -24,13 +24,11 @@
import org.onosproject.net.device.PortStatistics;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
-import org.onosproject.ui.table.AbstractTableRow;
+import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
-import org.onosproject.ui.table.TableRow;
+import org.onosproject.ui.table.cell.LongComparator;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
/**
@@ -51,6 +49,11 @@
private static final String PKT_TX_DRP = "pkt_tx_drp";
private static final String DURATION = "duration";
+ private static final String[] COL_IDS = {
+ ID, PKT_RX, PKT_TX, BYTES_RX, BYTES_TX,
+ PKT_RX_DRP, PKT_TX_DRP, DURATION
+ };
+
@Override
protected Collection<RequestHandler> getHandlers() {
return ImmutableSet.of(new PortDataRequest());
@@ -64,47 +67,44 @@
}
@Override
- protected TableRow[] generateTableRows(ObjectNode payload) {
- String uri = string(payload, "devId");
- if (Strings.isNullOrEmpty(uri)) {
- return new TableRow[0];
- }
- DeviceId deviceId = DeviceId.deviceId(uri);
- DeviceService service = get(DeviceService.class);
- List<TableRow> list = new ArrayList<>();
- for (PortStatistics stat : service.getPortStatistics(deviceId)) {
- list.add(new PortTableRow(stat));
- }
- return list.toArray(new TableRow[list.size()]);
- }
- }
-
- /**
- * TableRow implementation for
- * {@link org.onosproject.net.device.PortStatistics port statistics}.
- */
- private static class PortTableRow extends AbstractTableRow {
-
- private static final String[] COL_IDS = {
- ID, PKT_RX, PKT_TX, BYTES_RX, BYTES_TX,
- PKT_RX_DRP, PKT_TX_DRP, DURATION
- };
-
- public PortTableRow(PortStatistics stat) {
- add(ID, Integer.toString(stat.port()));
- add(PKT_RX, Long.toString(stat.packetsReceived()));
- add(PKT_TX, Long.toString(stat.packetsSent()));
- add(BYTES_RX, Long.toString(stat.bytesReceived()));
- add(BYTES_TX, Long.toString(stat.bytesSent()));
- add(PKT_RX_DRP, Long.toString(stat.packetsRxDropped()));
- add(PKT_TX_DRP, Long.toString(stat.packetsTxDropped()));
- add(DURATION, Long.toString(stat.durationSec()));
+ protected String[] getColumnIds() {
+ return COL_IDS;
}
@Override
- protected String[] columnIds() {
- return COL_IDS;
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setComparator(PKT_RX, LongComparator.INSTANCE);
+ tm.setComparator(PKT_TX, LongComparator.INSTANCE);
+ tm.setComparator(BYTES_RX, LongComparator.INSTANCE);
+ tm.setComparator(BYTES_TX, LongComparator.INSTANCE);
+ tm.setComparator(PKT_RX_DRP, LongComparator.INSTANCE);
+ tm.setComparator(PKT_TX_DRP, LongComparator.INSTANCE);
+ tm.setComparator(DURATION, LongComparator.INSTANCE);
+ return tm;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ String uri = string(payload, "devId");
+ if (!Strings.isNullOrEmpty(uri)) {
+ DeviceId deviceId = DeviceId.deviceId(uri);
+ DeviceService ds = get(DeviceService.class);
+ for (PortStatistics stat : ds.getPortStatistics(deviceId)) {
+ populateRow(tm.addRow(), stat);
+ }
+ }
+ }
+
+ private void populateRow(TableModel.Row row, PortStatistics stat) {
+ row.cell(ID, stat.port())
+ .cell(PKT_RX, stat.packetsReceived())
+ .cell(PKT_TX, stat.packetsSent())
+ .cell(BYTES_RX, stat.bytesReceived())
+ .cell(BYTES_TX, stat.bytesSent())
+ .cell(PKT_RX_DRP, stat.packetsRxDropped())
+ .cell(PKT_TX_DRP, stat.packetsTxDropped())
+ .cell(DURATION, stat.durationSec());
}
}
-
}