ONOS-3749: Show Flow ID and group ID in the flow table as hex values.
Change-Id: If98e0d76876ada2fa1c8d01a1b89230d1919f6c5
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/HexLongFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/HexLongFormatter.java
new file mode 100644
index 0000000..9155efe
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/HexLongFormatter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016 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.CellFormatter;
+
+/**
+ * Formats long values as hex strings with a "0x" prefix.
+ */
+public final class HexLongFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private HexLongFormatter() { }
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ return "0x" + Long.toHexString((Long) value);
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new HexLongFormatter();
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/HexLongFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/HexLongFormatterTest.java
new file mode 100644
index 0000000..c8a0912
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/HexLongFormatterTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 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.junit.Test;
+import org.onosproject.ui.table.CellFormatter;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link HexLongFormatter}.
+ */
+public class HexLongFormatterTest {
+
+ private CellFormatter fmt = HexLongFormatter.INSTANCE;
+
+ @Test
+ public void nullValue() {
+ assertEquals("null value", "", fmt.format(null));
+ }
+
+ @Test
+ public void zero() {
+ assertEquals("zero", "0x0", fmt.format(0L));
+ }
+
+ @Test
+ public void one() {
+ assertEquals("one", "0x1", fmt.format(1L));
+ }
+
+ @Test
+ public void ten() {
+ assertEquals("ten", "0xa", fmt.format(10L));
+ }
+
+ @Test
+ public void twenty() {
+ assertEquals("twenty", "0x14", fmt.format(20L));
+ }
+
+ @Test
+ public void veryBig() {
+ assertEquals("very big", "0x7048860f3a38", fmt.format(123456789101112L));
+ }
+
+ @Test
+ public void maxLong() {
+ assertEquals("max long", "0x7fffffffffffffff", fmt.format(Long.MAX_VALUE));
+ }
+}
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 0217911..44bd78d 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
@@ -30,6 +30,8 @@
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.cell.EnumFormatter;
+import org.onosproject.ui.table.cell.HexFormatter;
+import org.onosproject.ui.table.cell.HexLongFormatter;
import java.util.Collection;
import java.util.List;
@@ -84,6 +86,8 @@
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
+ tm.setFormatter(ID, HexLongFormatter.INSTANCE);
+ tm.setFormatter(GROUP_ID, HexFormatter.INSTANCE);
tm.setFormatter(SELECTOR, new SelectorFormatter());
tm.setFormatter(TREATMENT, new TreatmentFormatter());
tm.setFormatter(STATE, EnumFormatter.INSTANCE);
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java
index c7d539b..c78d32f 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java
@@ -29,6 +29,7 @@
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.cell.EnumFormatter;
+import org.onosproject.ui.table.cell.HexFormatter;
import java.util.Collection;
import java.util.List;
@@ -75,6 +76,7 @@
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
+ tm.setFormatter(ID, HexFormatter.INSTANCE);
tm.setFormatter(TYPE, EnumFormatter.INSTANCE);
tm.setFormatter(BUCKETS, new BucketFormatter());
return tm;