private void getLeaves(Object node, TreeModel model, Set<OpendapLeaf> result) { for (int i = 0; i < model.getChildCount(node); i++) { if (model.isLeaf(model.getChild(node, i))) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) (model.getChild(node, i)); if (CatalogTreeUtils.isDapNode(childNode) || CatalogTreeUtils.isFileNode(childNode)) { result.add((OpendapLeaf) childNode.getUserObject()); } } else { getLeaves(model.getChild(node, i), model, result); } } }
private void collectURIs() { final TreePath[] selectionPaths = ((JTree) catalogTree.getComponent()).getSelectionModel().getSelectionPaths(); if (selectionPaths == null || selectionPaths.length <= 0) { return; } for (TreePath selectionPath : selectionPaths) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); if (CatalogTreeUtils.isDapNode(treeNode) || CatalogTreeUtils.isFileNode(treeNode)) { final OpendapLeaf leaf = (OpendapLeaf) treeNode.getUserObject(); if (leaf.isDapAccess()) { dapURIs.put(leaf.getDapUri(), leaf.getFileSize() >= 2 * 1024 * 1024); } else if (leaf.isFileAccess()) { fileURIs.add(leaf.getFileUri()); } } } }
private void testThatChildIsDapNodeWhichHasFileAccessToo(DefaultMutableTreeNode parentNode) { testThatChildIsDapNode(parentNode); assertEquals(true, CatalogTreeUtils.isFileNode(parentNode.getChildAt(0))); }
private void testThatChildIsOnlyDapNodeWithoutFileAccess(DefaultMutableTreeNode parentNode) { testThatChildIsDapNode(parentNode); assertEquals(false, CatalogTreeUtils.isFileNode(parentNode.getChildAt(0))); }
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; if (CatalogTreeUtils.isDapNode(value)) { setLeafIcon(dapIcon); setToolTip(node, tree); } else if (CatalogTreeUtils.isFileNode(value)) { setLeafIcon(fileIcon); setToolTip(node, tree); } else try { if (leaf && isOpendapLeaf(node) && CatalogTreeUtils.getCatalogDatasets(node).isEmpty()) { setLeafIcon(errorIcon); tree.setToolTipText(null); } else { setLeafIcon(getClosedIcon()); } } catch (IOException e) { setLeafIcon(errorIcon); tree.setToolTipText(null); } super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); return this; }
@Test public void testAddingDatasetWithDAPAccessAndOneWithFileAccessOnly_FileAccessOnlyResolvesToNodeWithFileAccess() { //preparation final InvDatasetImpl fileDataset = createDataset(catalog, "second", "file"); datasets.add(fileDataset); //execution catalogTree.setNewRootDatasets(datasets); //verification final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertEquals(2, root.getChildCount()); assertEquals(true, CatalogTreeUtils.isDapNode(root.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isFileNode(root.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isDapNode(root.getChildAt(1))); assertEquals(true, CatalogTreeUtils.isFileNode(root.getChildAt(1))); }
private void testThatChildIsNodeWithFileAccess(DefaultMutableTreeNode parentNode) { assertEquals(1, parentNode.getChildCount()); assertEquals(true, parentNode.getChildAt(0).isLeaf()); assertEquals(false, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); assertEquals(true, CatalogTreeUtils.isFileNode(parentNode.getChildAt(0))); }