if (previousCriterias.get(tableView) == null ||
!previousCriterias.get(tableView).equals(type + ":" + criteriaString)) {
// Execute query towards server
JSONObject object = Client.create().resource(HOSTURL + "/browse/" + type + "?" + criteriaString+"&itemInfo=true").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
JSONArray objects = object.getJSONArray("items");
TableViewItem previousSelectedItem = null;
// Make sure we remember previous selection so we can re-select that item if it exists in the new search result
int previousSelectedIndex = -1;
if (tableView.getSelectedIndex() >= 0) {
previousSelectedItem = (TableViewItem) tableView.getTableData().get(tableView.getSelectedIndex());
}
tableView.getTableData().clear();
if (tableView != tracksTableView) {
// Add special "(All)" element at the top unless this is the tracks result list
((List<TableViewItem>) tableView.getTableData()).add(new TableViewItem(null, "(All)", null));
}
// Convert each object from JSON to Java and add it to the table view
for (int i = 0; i < objects.length(); i++) {
T item = jsonProvider.fromJson(objects.getJSONObject(i).getJSONObject("item").toString(), itemClass);
TableViewItem tableViewItem = getTableViewItem(item);
int index = ((List<TableViewItem>) tableView.getTableData()).add(tableViewItem);
// If this is the previously selected object, make sure we remember its index
if (previousSelectedItem != null && tableViewItem.getId().equals(previousSelectedItem.getId())) {