private boolean applyFilters(CategorySerializable cat) { // Apply any filters. boolean include = true; if (filters.size() > 0) { for (Iterator filterIt = filters.iterator(); filterIt.hasNext(); ) { DatasetFilter filter = (DatasetFilter) filterIt.next(); // This should be done with introspection, but for now do a // big cheat String name = "x"; String value = "y"; if (filter.getAttribute().equals("name")) { name = cat.getName().toLowerCase(); value = filter.getValue().toLowerCase(); } else if (filter.getAttribute().equals("ID")) { name = cat.getID(); value = filter.getValue(); } if (name.contains(value)) { include = include && filter.isInclude(); } else { include = include && !filter.isInclude(); } } } return include; }
public void onSuccess(Object result) { CategorySerializable[] cats = (CategorySerializable[]) result; if (cats != null && cats.length > 0) { if (currentlySelected == null) { for (int i = 0; i < cats.length; i++) { CategorySerializable cat = cats[i]; String children = cat.getAttributes().get("children"); boolean empty = false; if (children != null && children.equals("none")) empty = true; if (applyFilters(cat) && !empty) { TreeItem item = new TreeItem(); item.addItem( new SafeHtmlBuilder().appendEscaped(DatasetWidget.LOADING).toSafeHtml()); InnerItem inner = new InnerItem(cat); item.setWidget(inner); item.setUserObject(cat); addItem(item); } } } else { for (int i = 0; i < cats.length; i++) { CategorySerializable cat = cats[i]; if (cat.isCategoryChildren()) { String name = cat.getName(); TreeItem item; if (i == 0) { item = currentlySelected.getChild(0); } else { item = new TreeItem(); } item.addItem( new SafeHtmlBuilder().appendEscaped(DatasetWidget.LOADING).toSafeHtml()); InnerItem inner = new InnerItem(cat); item.setWidget(inner); item.setUserObject(cat); if (i > 0) { currentlySelected.addItem(item); } } else if (cat.isVariableChildren()) { // Must have variable children... TreeItem item = currentlySelected.getChild(0); if (cat.hasMultipleDatasets()) { DatasetSerializable[] dses = cat.getDatasetSerializableArray(); DatasetSerializable ds = dses[0]; VariableSerializable[] vars = ds.getVariablesSerializable(); currentlySelected.removeItems(); for (int j = 0; j < dses.length; j++) { ds = dses[j]; vars = ds.getVariablesSerializable(); loadItem(vars); } } else { DatasetSerializable ds = cat.getDatasetSerializable(); VariableSerializable[] vars = ds.getVariablesSerializable(); currentlySelected.removeItems(); loadItem(vars); } } } } } else { // A category was selected, but it came back empty... if (currentlySelected != null) { TreeItem item = currentlySelected.getChild(0); item.setText("No data sets found."); } } if (saveSelection != null) { currentlySelected = saveSelection; saveSelection = null; } }