private void appendToNode(JTree jTree, InvDataset dataset, MutableTreeNode parentNode) { final DefaultTreeModel treeModel = (DefaultTreeModel) jTree.getModel(); if (dataset instanceof InvCatalogRef) { CatalogTreeUtils.appendCatalogNode(parentNode, treeModel, (InvCatalogRef) dataset); } else { appendLeafNode(parentNode, treeModel, dataset); } }
private void insertCatalogElements(List<InvDataset> catalogDatasets, DefaultMutableTreeNode parent, boolean expandPath) { appendToNode(jTree, catalogDatasets, parent, true); fireCatalogElementsInsertionFinished(); if (expandPath) { expandPath(parent); } }
@Override public void filterChanged() { final OpendapLeaf[] leaves = catalogTree.getLeaves(); for (OpendapLeaf leaf : leaves) { filterLeaf(leaf); } } }
@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 testThatPreviousDatasetsHaveBeenRemoved() { //preparation catalogTree.setNewRootDatasets(datasets); final DefaultMutableTreeNode previousRootNode = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); final InvDatasetImpl fileDataset = createDataset(catalog, "second", "file"); final ArrayList<InvDataset> otherDatasets = new ArrayList<InvDataset>(); otherDatasets.add(fileDataset); //execution catalogTree.setNewRootDatasets(otherDatasets); //verification final DefaultMutableTreeNode newRootNode = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertNotSame(previousRootNode, newRootNode); }
@Test public void testThatAppendDatasetWithFileAccessOnlyIsResolvedToNodeWithFileAccess() throws URISyntaxException { // preparation final String serviceName = "FILE"; final InvDatasetImpl dapDataset = createDataset(new String[]{serviceName}); // execution new CatalogTree(null, new DefaultAppContext(""), null).appendLeafNode(parentNode, getDefaultTreeModel(), dapDataset); // verification testThatChildIsNodeWithFileAccess(parentNode); }
@Test public void testGetLeaves() throws Exception { Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); final CatalogTree catalogTree = new CatalogTree(null, new DefaultAppContext(""), null); List<InvDataset> datasets = new ArrayList<InvDataset>(); InvCatalog catalog = new InvCatalogImpl("catalogName", "1.0", new URI("http://x.y")); final InvDataset rootDataset = createDataset(catalog, "first", "OPENDAP"); rootDataset.getDatasets().add(createDataset(catalog, "second", "OPENDAP")); rootDataset.getDatasets().add(createDataset(catalog, "third", "OPENDAP")); datasets.add(rootDataset); catalogTree.setNewRootDatasets(datasets); OpendapLeaf[] leaves = catalogTree.getLeaves(); Arrays.sort(leaves, new Comparator<OpendapLeaf>() { @Override public int compare(OpendapLeaf o1, OpendapLeaf o2) { return o1.getName().compareTo(o2.getName()); } }); assertEquals(2, leaves.length); assertEquals("second", leaves[0].getName()); assertEquals("third", leaves[1].getName()); }
@Before public void setUp() throws Exception { catalogTree = new CatalogTree(null, new DefaultAppContext(""), null); parentNode = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); }
void insertCatalogElements(InputStream catalogIS, URI catalogBaseUri, DefaultMutableTreeNode parent, boolean expandPath) { final List<InvDataset> catalogDatasets = CatalogTreeUtils.getCatalogDatasets(catalogIS, catalogBaseUri); insertCatalogElements(catalogDatasets, parent, expandPath); }
catalogTree = new CatalogTree(new DefaultLeafSelectionListener(), appContext, this); useDatasetNameFilter = new JCheckBox("Use dataset name filter"); useTimeRangeFilter = new JCheckBox("Use time range filter"); variableFilter.addFilterChangeListener(filterChangeListener); catalogTree.addCatalogTreeListener(new CatalogTree.CatalogTreeListener() { @Override public void leafAdded(OpendapLeaf leaf, boolean hasNestedDatasets) {
@Before public void setUp() throws Exception { datasets = new ArrayList<InvDataset>(); catalog = new InvCatalogImpl("catalogName", "1.0", new URI("http://x.y")); InvDatasetImpl dapDataset = createDataset(catalog, "first", "OPENDAP"); datasets.add(dapDataset); catalogTree = new CatalogTree(null, new DefaultAppContext(""), null); }
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 boolean refresh() { String url; if (urlField.getSelectedItem() == null) { url = urlField.getEditor().getItem().toString(); } else { url = urlField.getSelectedItem().toString(); } url = checkCatalogURLString(url); final InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(true); final InvCatalog catalog = factory.readXML(url); final List<InvDataset> datasets = catalog.getDatasets(); if (datasets.size() == 0) { JOptionPane.showMessageDialog(this, "Cannnot find THREDDS catalog service xml at '" + url + "'"); return false; } urlField.setSelectedItem(url); catalogTree.setNewRootDatasets(datasets); variableFilter.stopFiltering(); return true; }
void appendToNode(final JTree jTree, List<InvDataset> datasets, MutableTreeNode parentNode, boolean goDeeper) { for (InvDataset dataset : datasets) { final MutableTreeNode deeperParent; if (!goDeeper || !CatalogTreeUtils.isHyraxId(dataset.getID())) { appendToNode(jTree, dataset, parentNode); if (parentNode.getChildCount() == 0) { continue; } deeperParent = (MutableTreeNode) parentNode.getChildAt(parentNode.getChildCount() - 1); } else { deeperParent = parentNode; } if (goDeeper && !(dataset instanceof InvCatalogRef)) { appendToNode(jTree, dataset.getDatasets(), deeperParent, false); } } }
void appendLeafNode(MutableTreeNode parentNode, DefaultTreeModel treeModel, InvDataset dataset) { final OpendapLeaf leaf = new OpendapLeaf(dataset.getName(), dataset); final int fileSize = (int) (OpendapUtils.getDataSizeInBytes(leaf) / 1024); leaf.setFileSize(fileSize); final InvAccess dapAccess = dataset.getAccess(ServiceType.OPENDAP); if (dapAccess != null) { leaf.setDapAccess(true); leaf.setDapUri(dapAccess.getStandardUrlName()); } final InvAccess fileAccess = dataset.getAccess(ServiceType.FILE); if (fileAccess != null) { leaf.setFileAccess(true); leaf.setFileUri(fileAccess.getStandardUrlName()); } else { final InvAccess serverAccess = dataset.getAccess(ServiceType.HTTPServer); if (serverAccess != null) { leaf.setFileAccess(true); leaf.setFileUri(serverAccess.getStandardUrlName()); } } final boolean hasNestedDatasets = dataset.hasNestedDatasets(); appendDataNodeToParent(parentNode, treeModel, leaf); fireLeafAdded(leaf, hasNestedDatasets); }
public VariableFilter(JCheckBox filterCheckBox, CatalogTree catalogTree) { this.filterCheckBox = filterCheckBox; catalogTree.addCatalogTreeListener(this); listeners = new ArrayList<FilterChangeListener>(); }
private void setLeafVisible(OpendapLeaf leaf) { boolean leafIsRemovedFromTree = leafToParentNode.containsKey(leaf); if (leafIsRemovedFromTree) { appendDataNodeToParent(leafToParentNode.get(leaf), (DefaultTreeModel) jTree.getModel(), leaf); leafToParentNode.remove(leaf); } }
public CatalogTree(final LeafSelectionListener leafSelectionListener, AppContext appContext, UIContext uiContext) { this.appContext = appContext; this.uiContext = uiContext; jTree = new JTree(); jTree.setRootVisible(false); ((DefaultTreeModel) jTree.getModel()).setRoot(CatalogTreeUtils.createRootNode()); CatalogTreeUtils.addCellRenderer(jTree); addWillExpandListener(); CatalogTreeUtils.addTreeSelectionListener(jTree, leafSelectionListener); }
@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 testWhetherRootNodeHasBeenExchanged() { //preparation final InvDatasetImpl fileDataset = createDataset(catalog, "second", "file"); final ArrayList<InvDataset> otherDatasets = new ArrayList<InvDataset>(); otherDatasets.add(fileDataset); //execution catalogTree.setNewRootDatasets(datasets); //verification final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); catalogTree.setNewRootDatasets(otherDatasets); final DefaultMutableTreeNode otherRoot = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertEquals(false, root.equals(otherRoot)); }