aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell')
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellComparator.java61
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellFormatter.java42
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java41
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.java41
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java52
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java39
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java40
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java39
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.java41
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java72
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/package-info.java20
11 files changed, 488 insertions, 0 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellComparator.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellComparator.java
new file mode 100644
index 00000000..6113fc3f
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellComparator.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+/**
+ * Base implementation of a {@link CellComparator}. This class takes care
+ * of dealing with null inputs; subclasses should implement their comparison
+ * knowing that both inputs are guaranteed to be non-null.
+ */
+public abstract class AbstractCellComparator implements CellComparator {
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ if (o1 == null && o2 == null) {
+ return 0; // o1 == o2
+ }
+ if (o1 == null) {
+ return -1; // o1 < o2
+ }
+ if (o2 == null) {
+ return 1; // o1 > o2
+ }
+ return nonNullCompare(o1, o2);
+ }
+
+ /**
+ * Compares its two arguments for order. Returns a negative integer,
+ * zero, or a positive integer as the first argument is less than, equal
+ * to, or greater than the second.<p>
+ *
+ * Note that both objects are guaranteed to be non-null.
+ *
+ * @see java.util.Comparator#compare(Object, Object)
+ *
+ * @param o1 the first object to be compared.
+ * @param o2 the second object to be compared.
+ * @return a negative integer, zero, or a positive integer as the
+ * first argument is less than, equal to, or greater than the
+ * second.
+ * @throws ClassCastException if the arguments' types prevent them from
+ * being compared by this comparator.
+ */
+ protected abstract int nonNullCompare(Object o1, Object o2);
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellFormatter.java
new file mode 100644
index 00000000..33ce2ab5
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AbstractCellFormatter.java
@@ -0,0 +1,42 @@
+/*
+ * 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.CellFormatter;
+
+/**
+ * Base implementation of a {@link CellFormatter}. This class takes care of
+ * dealing with null inputs; subclasses should implement their format method
+ * knowing that the input is guaranteed to be non-null.
+ */
+public abstract class AbstractCellFormatter implements CellFormatter {
+
+ @Override
+ public String format(Object value) {
+ return value == null ? "" : nonNullFormat(value);
+ }
+
+ /**
+ * Formats the specified value into a string appropriate for displaying
+ * in a table cell. Note that value is guaranteed to be non-null.
+ *
+ * @param value the value
+ * @return the formatted string
+ */
+ protected abstract String nonNullFormat(Object value);
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java
new file mode 100644
index 00000000..42d684b6
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.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.onosproject.core.ApplicationId;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats an application identifier as "(app-id) : (app-name)".
+ */
+public final class AppIdFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private AppIdFormatter() { }
+
+ @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/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.java
new file mode 100644
index 00000000..fee26154
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/ConnectPointFormatter.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.onosproject.net.ConnectPoint;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats a connect point as "(element-id)/(port)".
+ */
+public final class ConnectPointFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private ConnectPointFormatter() { }
+
+ @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/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java
new file mode 100644
index 00000000..093a20d3
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellComparator.java
@@ -0,0 +1,52 @@
+/*
+ * 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 default cell comparator.
+ * <p>
+ * Verifies that the objects being compared are the same class.
+ * Looks to see if the objects being compared implement comparable and, if so,
+ * delegates to that; otherwise, implements a lexicographical compare function
+ * (i.e. string sorting). Uses the objects' toString() method and then
+ * compares the resulting strings. Note that null values are acceptable and
+ * are considered "smaller" than any non-null value.
+ */
+public final class DefaultCellComparator extends AbstractCellComparator {
+
+ // non-instantiable
+ private DefaultCellComparator() { }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected int nonNullCompare(Object o1, Object o2) {
+ if (o1 instanceof Comparable) {
+ // if o2 is not the same class as o1, then compareTo will
+ // throw ClassCastException for us
+ return ((Comparable) o1).compareTo(o2);
+ }
+ return o1.toString().compareTo(o2.toString());
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellComparator INSTANCE = new DefaultCellComparator();
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.java
new file mode 100644
index 00000000..0efa2ebd
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/DefaultCellFormatter.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.CellFormatter;
+
+/**
+ * A default cell formatter. Uses the object's toString() method.
+ */
+public final class DefaultCellFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private DefaultCellFormatter() { }
+
+ @Override
+ public String nonNullFormat(Object value) {
+ return value.toString();
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new DefaultCellFormatter();
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java
new file mode 100644
index 00000000..5b89a0b7
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java
@@ -0,0 +1,40 @@
+/*
+ * 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.CellFormatter;
+
+import static org.apache.commons.lang.WordUtils.capitalizeFully;
+
+/**
+ * Formats enum types to be readable strings.
+ */
+public final class EnumFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private EnumFormatter() { }
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ return capitalizeFully(value.toString().replace("_", " "));
+ }
+
+ /**
+ * An instance of this class.
+ */
+ public static final CellFormatter INSTANCE = new EnumFormatter();
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.java
new file mode 100644
index 00000000..e09982ea
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HexFormatter.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.CellFormatter;
+
+/**
+ * Formats integer values as hex strings with a "0x" prefix.
+ */
+public final class HexFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private HexFormatter() { }
+
+ @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/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.java
new file mode 100644
index 00000000..fe87c61b
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/HostLocationFormatter.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.onosproject.net.HostLocation;
+import org.onosproject.ui.table.CellFormatter;
+
+/**
+ * Formats a host location as "(device-id)/(port)".
+ */
+public final class HostLocationFormatter extends AbstractCellFormatter {
+
+ // non-instantiable
+ private HostLocationFormatter() { }
+
+ @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/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
new file mode 100644
index 00000000..44dc1940
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
@@ -0,0 +1,72 @@
+/*
+ * 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.DateTimeZone;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.util.Locale;
+
+/**
+ * Formats time values using {@link DateTimeFormatter}.
+ */
+public final class TimeFormatter extends AbstractCellFormatter {
+
+ private DateTimeFormatter dtf;
+
+ // NOTE: Unlike other formatters in this package, this one is not
+ // implemented as a Singleton, because instances may be
+ // decorated with alternate locale and/or timezone.
+
+ /**
+ * Constructs a time formatter that uses the default locale and timezone.
+ */
+ public TimeFormatter() {
+ dtf = DateTimeFormat.longTime();
+ }
+
+ /**
+ * Sets the locale to use for formatting the time.
+ *
+ * @param locale locale to use for formatting
+ * @return self, for chaining
+ */
+ public TimeFormatter withLocale(Locale locale) {
+ dtf = dtf.withLocale(locale);
+ return this;
+ }
+
+ /**
+ * Sets the time zone to use for formatting the time.
+ *
+ * @param zone time zone to use
+ * @return self, for chaining
+ */
+ public TimeFormatter withZone(DateTimeZone zone) {
+ dtf = dtf.withZone(zone);
+ return this;
+ }
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ return dtf.print((DateTime) value);
+ }
+
+}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/package-info.java
new file mode 100644
index 00000000..c25bcb06
--- /dev/null
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Set of table cell renderers and comparators for use by GUI apps.
+ */
+package org.onosproject.ui.table.cell; \ No newline at end of file