@Override public String getValue(CatalogEntry object) { return object.getLabel(); }
@Test public void countries() { // should have only one country on current data set : Rdc List<CatalogEntry> countries = catalog.getChildren(GeoDatabaseProvider.GEODB_ID.asString(), ALEX); assert countries.size() == 1; assert countries.get(0).getId().equals(RDC_CODE); assert countries.get(0).getLabel().equals(RDC_LABEL); assert countries.get(0).getType().equals(CatalogEntryType.FOLDER); assert !countries.get(0).isLeaf(); }
private void matchEntries(List<CatalogEntry> fetched, List<String> expectedEntries, CatalogEntryType expectedType, boolean leaf) { assert fetched.size() == expectedEntries.size(); for (CatalogEntry entry : fetched) { assert expectedEntries.contains(entry.getId()); assert entry.getType().equals(expectedType); assert entry.isLeaf() == leaf; } }
@Override public Object getKey(CatalogEntry node) { return node == null ? null : node.getId(); } };
@Override public boolean isLeaf(Object value) { if (value instanceof CatalogEntry) { CatalogEntry entry = (CatalogEntry) value; if(entry.getType() == CatalogEntryType.FOLDER) { return false; } } return true; } }
private List<CatalogEntry> queryCountries() throws SQLException { List<CatalogEntry> entries = new ArrayList<>(); try(ResultSet rs = executor.query("SELECT iso2, name FROM country ORDER BY name")) { while(rs.next()) { entries.add(new CatalogEntry( countryId(rs.getString(1)), rs.getString(2), CatalogEntryType.FOLDER)); } } return entries; }
private static CatalogEntry buildCatalogEntry(Resource.Node node) { CatalogEntry entry = new CatalogEntry(node.getResource().getId().asString(), node.getResource().getLabel(), catalogType(node.getResource().getType())); entry.setLeaf(node.isLeaf()); return entry; }
public static List<CatalogEntry> fromJsonArray(JsonValue jsonArray) { List<CatalogEntry> list = new ArrayList<>(); for(JsonValue element : jsonArray.values()) { list.add(fromJson(element)); } return list; } }
private void folderEntries(UserDatabaseMeta db) { // Each folder entry should have: // - an id equal to the resource id // - a label equal to the resource label // - an isLeaf boolean of FALSE, as the FORM should have a nested subform // - a type of FORM Map<ResourceId,Resource> folderResources = RESOURCES.folderResources().stream().collect(Collectors.toMap(Resource::getId,r -> r)); List<CatalogEntry> rootEntries = db.findCatalogEntries(RESOURCES.FOLDER_ID); assert rootEntries.size() == folderResources.size(); for (CatalogEntry rootEntry : rootEntries) { ResourceId rootEntryId = ResourceId.valueOf(rootEntry.getId()); assert folderResources.containsKey(rootEntryId); assert folderResources.get(rootEntryId).getLabel().equals(rootEntry.getLabel()); assert !rootEntry.isLeaf(); assert rootEntry.getType().equals(CatalogEntryType.FORM); } }
DataProvider(ResourceLocator locator, CatalogEntry parent) { this.locator = locator; if(parent == null) { this.parentId = null; } else { this.parentId = parent.getId(); } }
private Set<CatalogEntry> getSelectedLeafNodes() { Set<CatalogEntry> set = Sets.newHashSet(); for (CatalogEntry node : selectionModel.getSelectedSet()) { if (node.getType() == CatalogEntryType.FORM) { set.add(node); } } return set; }
@Override public CatalogEntry apply(AnalysisEntity analysisEntity) { return new CatalogEntry(analysisEntity.getId(), analysisEntity.getLabel(), CatalogEntryType.ANALYSIS); } });
private void subFormEntries(UserDatabaseMeta db) { // Single sub form entry should have: // - an id equal to the resource id // - a label equal to the resource label // - an isLeaf boolean of TRUE // - a type of FORM List<CatalogEntry> rootEntries = db.findCatalogEntries(RESOURCES.FOLDER_FORM_ID); assert rootEntries.size() == 1; CatalogEntry subFormEntry = rootEntries.get(0); ResourceId subFormEntryId = ResourceId.valueOf(subFormEntry.getId()); assert subFormEntryId.equals(RESOURCES.SUB_FORM_ID); assert subFormEntry.getLabel().equals(RESOURCES.subFormResource().getLabel()); assert subFormEntry.isLeaf(); assert subFormEntry.getType().equals(CatalogEntryType.FORM); }
@Override public String getKey(CatalogEntry item) { return item.getId(); } }
private void selectionChanged(Observable<Optional<CatalogEntry>> selection) { boolean hasSelection = selection.isLoaded() && selection.get().isPresent(); CatalogEntry catalogEntry = null; if(hasSelection) { catalogEntry = selection.get().get(); } openTable.setEnabled(hasSelection && (catalogEntry.getType() == CatalogEntryType.FORM || catalogEntry.getType() == CatalogEntryType.ANALYSIS)); newReport.setEnabled(hasSelection && catalogEntry.getType() == CatalogEntryType.FOLDER); }
@Override public void render(Context context, CatalogEntry value, SafeHtmlBuilder sb) { if (value != null) { sb.append(TEMPLATE.cell(icon(value), value.getLabel())); } }