void insertCatalogElements(InputStream catalogIS, URI catalogBaseUri, DefaultMutableTreeNode parent, boolean expandPath) { final List<InvDataset> catalogDatasets = CatalogTreeUtils.getCatalogDatasets(catalogIS, catalogBaseUri); insertCatalogElements(catalogDatasets, parent, expandPath); }
public static List<InvDataset> getCatalogDatasets(DefaultMutableTreeNode node) throws IOException { Object userObject = node.getUserObject(); if (!(userObject instanceof CatalogNode)) { return Collections.emptyList(); } final CatalogNode catalogNode = (CatalogNode) userObject; final URL catalogUrl; InputStream inputStream = null; try { catalogUrl = new URL(catalogNode.getCatalogUri()); URLConnection urlConnection = catalogUrl.openConnection(); inputStream = urlConnection.getInputStream(); return getCatalogDatasets(inputStream, catalogUrl.toURI()); } catch (URISyntaxException e) { throw new IOException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ignore) { // ok } } } } }
public void resolveCatalogReferenceNode(DefaultMutableTreeNode catalogReferenceNode, boolean expandPath) { final DefaultTreeModel model = (DefaultTreeModel) jTree.getModel(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) catalogReferenceNode.getParent(); model.removeNodeFromParent(catalogReferenceNode); try { List<InvDataset> catalogDatasets = CatalogTreeUtils.getCatalogDatasets(catalogReferenceNode); insertCatalogElements(catalogDatasets, parent, expandPath); } catch (Exception e) { String msg = MessageFormat.format("Unable to completely resolve catalog. Reason: {0}", e.getMessage()); BeamLogManager.getSystemLogger().warning(msg); appContext.handleError(msg, e); } }
@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; }