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 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); } } }
@Test public void testThatUserObjectWhichIsNoOpendapLeafIsResolvedToFalse() { final Integer userObject = 4; final DefaultMutableTreeNode noDapNode = new DefaultMutableTreeNode(userObject); assertEquals(false, CatalogTreeUtils.isDapNode(noDapNode)); }
@Test public void testThatNullIsResolvedToFalse() { final Object noDapNode = null; assertEquals(false, CatalogTreeUtils.isDapNode(noDapNode)); }
@Test public void testThatOpendapLeafWhichHasNoDapServiceSetIsResolvedToFalse() { final OpendapLeaf userObject = new OpendapLeaf("name", new InvDataset(null, "") { }); userObject.setDapAccess(false); final DefaultMutableTreeNode noDapNode = new DefaultMutableTreeNode(userObject); assertEquals(false, CatalogTreeUtils.isDapNode(noDapNode)); }
@Test public void testThatOpendapLeafWhichHasDapServiceSetIsResolvedToTrue() { final OpendapLeaf userObject = new OpendapLeaf("name", new InvDataset(null, "") { }); userObject.setDapAccess(true); final DefaultMutableTreeNode notADapNode = new DefaultMutableTreeNode(userObject); assertEquals(true, CatalogTreeUtils.isDapNode(notADapNode)); } }
@Test public void testAddingDapDataset() { //execution catalogTree.setNewRootDatasets(datasets); //verification assertEquals(true, ((JTree) catalogTree.getComponent()).getModel().getRoot() instanceof DefaultMutableTreeNode); final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertEquals(1, root.getChildCount()); assertEquals(true, CatalogTreeUtils.isDapNode(root.getChildAt(0))); assertEquals("first", ((DefaultMutableTreeNode) root.getChildAt(0)).getUserObject().toString()); }
@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 testThatTwoDapDatasetsHaveBeenAdded() throws URISyntaxException, IOException { //preparation final URI catalogBaseUri = new URI("http://every.where/child/catalog.xml"); InputStream catalogIS = null; try { catalogIS = getThreddsCatalogInputStreamWithTwoChildDapDatasets(); //execution catalogTree.insertCatalogElements(catalogIS, catalogBaseUri, parentNode, false); //verification assertEquals(2, parentNode.getChildCount()); assertEquals(true, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); assertEquals(true, CatalogTreeUtils.isDapNode(parentNode.getChildAt(1))); DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) parentNode.getChildAt(0); OpendapLeaf firstLeaf = (OpendapLeaf) firstChild.getUserObject(); assertEquals("http://every.where/opendap/hyrax/data/child/ProductName.N1.nc.dds", firstLeaf.getDdsUri()); DefaultMutableTreeNode secondChild = (DefaultMutableTreeNode) parentNode.getChildAt(1); OpendapLeaf secondLeaf = (OpendapLeaf) secondChild.getUserObject(); assertEquals("http://every.where/opendap/hyrax/data/child/OtherProductName.N1.nc.dds", secondLeaf.getDdsUri()); } finally { if (catalogIS != null) { catalogIS.close(); } } }
@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))); }
@Test public void testAppendThreeDapNodes() throws URISyntaxException { //preparation datasets.add(createDataset(catalog, "Name_1", "OPENDAP")); datasets.add(createDataset(catalog, "Name_2", "OPENDAP")); datasets.add(createDataset(catalog, "Name_3", "OPENDAP")); //execution new CatalogTree(null, new DefaultAppContext(""), null).appendToNode(new JTree(), datasets, parentNode, true); //verification assertEquals(3, parentNode.getChildCount()); for (int i = 0; i < parentNode.getChildCount(); i++) { final DefaultMutableTreeNode childAt = (DefaultMutableTreeNode) parentNode.getChildAt(i); final String indexMessage = "Index = " + i; assertEquals(indexMessage, true, childAt.isLeaf()); assertEquals(indexMessage, true, CatalogTreeUtils.isDapNode(childAt)); assertEquals(indexMessage, "Name_" + (i + 1), childAt.getUserObject().toString()); } }
@Test public void testAppendingVariousDatasets() { //preparation datasets.add(createDataset(catalog, "dapName", "OPENDAP")); datasets.add(createDataset(catalog, "fileName", "FILE")); datasets.add(createCatalogRefDataset()); //execution new CatalogTree(null, new DefaultAppContext(""), null).appendToNode(new JTree(), datasets, parentNode, true); //verification assertEquals(3, parentNode.getChildCount()); assertEquals(true, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isDapNode(parentNode.getChildAt(1))); assertEquals(false, CatalogTreeUtils.isCatalogReferenceNode(parentNode.getChildAt(1))); assertEquals(true, CatalogTreeUtils.isCatalogReferenceNode(parentNode.getChildAt(2).getChildAt(0))); }
private void testThatChildIsDapNode(DefaultMutableTreeNode parentNode) { assertEquals(1, parentNode.getChildCount()); assertEquals(true, parentNode.getChildAt(0).isLeaf()); assertEquals(true, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); }
@Test public void testAppendDapNode() throws URISyntaxException { // preparation datasets.add(createDataset(catalog, "first", "OPENDAP")); // execution new CatalogTree(null, new DefaultAppContext(""), null).appendToNode(new JTree(), datasets, parentNode, true); // verification assertEquals(1, parentNode.getChildCount()); assertEquals(true, parentNode.getChildAt(0).isLeaf()); assertEquals(true, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); }
@Test public void testAppendFileNode() throws URISyntaxException { //preparation datasets.add(createDataset(catalog, "fileName", "file")); //execution new CatalogTree(null, new DefaultAppContext(""), null).appendToNode(new JTree(), datasets, parentNode, true); //verification assertEquals(1, parentNode.getChildCount()); assertEquals(true, parentNode.getChildAt(0).isLeaf()); assertEquals(false, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); }
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))); }
@Test public void testAppendCatalogNode() throws URISyntaxException { //preparation datasets.add(createCatalogRefDataset()); //execution new CatalogTree(null, new DefaultAppContext(""), null).appendToNode(new JTree(), datasets, parentNode, true); //verification assertEquals(1, parentNode.getChildCount()); assertEquals(1, parentNode.getChildAt(0).getChildCount()); assertEquals(true, parentNode.getChildAt(0).getChildAt(0).isLeaf()); assertEquals(false, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isCatalogReferenceNode(parentNode.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0).getChildAt(0))); assertEquals(true, CatalogTreeUtils.isCatalogReferenceNode(parentNode.getChildAt(0).getChildAt(0))); }