Simon Hunt

GUI -- Deleted deprecated table classes.

Change-Id: I2e8c93ceee4b0e9776d27e528e4d1f036e5d7519
/*
* 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;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.HashMap;
import java.util.Map;
/**
* Provides a partial implementation of {@link TableRow}.
*/
@Deprecated
public abstract class AbstractTableRow implements TableRow {
private static final ObjectMapper MAPPER = new ObjectMapper();
private final Map<String, String> cells = new HashMap<>();
@Override
public String get(String key) {
return cells.get(key);
}
@Override
public ObjectNode toJsonNode() {
ObjectNode result = MAPPER.createObjectNode();
for (String id : columnIds()) {
result.put(id, cells.get(id));
}
return result;
}
/**
* Subclasses must provide the list of column IDs.
*
* @return array of column IDs
*/
protected abstract String[] columnIds();
/**
* Add a column ID to cell value binding.
*
* @param id the column ID
* @param value the cell value
*/
protected void add(String id, String value) {
cells.put(id, value);
}
/**
* Add a column ID to cell value binding.
* Note that value.toString() is invoked.
*
* @param id the column ID
* @param value the cell value
*/
protected void add(String id, Object value) {
cells.put(id, value.toString());
}
/**
* Concatenates an arbitrary number of objects, using their
* toString() methods.
*
* @param items the items to concatenate
* @return a concatenated string
*/
protected static String concat(Object... items) {
StringBuilder sb = new StringBuilder();
for (Object o : items) {
sb.append(o);
}
return sb.toString();
}
}
/*
* 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;
import java.util.Comparator;
/**
* Comparator for {@link TableRow}.
*/
@Deprecated
public class RowComparator implements Comparator<TableRow> {
/** Designates the sort direction. */
public enum Direction {
/** Sort Ascending. */
ASC,
/** Sort Descending. */
DESC
}
public static final String DESC_STR = "desc";
private final String colId;
private final Direction dir;
/**
* Constructs a comparator for table rows that uses the given
* column ID and direction.
*
* @param colId the column to sort on
* @param dir the direction to sort in
*/
public RowComparator(String colId, Direction dir) {
if (colId == null || dir == null) {
throw new NullPointerException("Null parameters not allowed");
}
this.colId = colId;
this.dir = dir;
}
@Override
public int compare(TableRow a, TableRow b) {
String cellA = a.get(colId);
String cellB = b.get(colId);
if (dir.equals(Direction.ASC)) {
return cellA.compareTo(cellB);
}
return cellB.compareTo(cellA);
}
/**
* Returns the sort direction constant for the given string.
* The expected strings are "asc" and "desc"; defaults to "asc".
*
* @param s the direction as a string
* @return the constant
*/
public static Direction direction(String s) {
return DESC_STR.equals(s) ? Direction.DESC : Direction.ASC;
}
}
/*
* 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;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* 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
// The hope is that this will allow us to write a generic mechanism for
// selecting a comparator based on the cell type for the column, to be
// used for sorting the table rows.
/**
* Returns the value of the cell for the given column ID.
*
* @param key the column ID
* @return the cell value
*/
String get(String key);
/**
* Returns this table row in the form of a JSON object.
*
* @return the JSON node
*/
ObjectNode toJsonNode();
}