List of usage examples for javax.swing.tree DefaultTreeModel reload
public void reload(TreeNode node)
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Removes the specified set of nodes from the tree. * //from w w w.j a v a 2 s . c o m * @param nodes The collection of nodes to remove. * @param parentDisplay The selected parent. */ void removeNodes(List nodes, TreeImageDisplay parentDisplay) { if (parentDisplay == null) parentDisplay = getTreeRoot(); Iterator i = nodes.iterator(); TreeImageDisplay node; TreeImageDisplay parent; DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); while (i.hasNext()) { node = (TreeImageDisplay) i.next(); parent = node.getParentDisplay(); if (parent.isChildrenLoaded()) { parent.removeChildDisplay(node); parent.remove(node); dtm.reload(parent); if (parent.equals(parentDisplay)) treeDisplay.setSelectionPath(new TreePath(parent.getPath())); } } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Adds the newly created node to the tree. * /*from w w w . j a v a 2 s. co m*/ * @param nodes The collection of the parent nodes. * @param newNode The node to add to the parent. * @param parentDisplay The selected parent. */ void createNodes(List nodes, TreeImageDisplay newNode, TreeImageDisplay parentDisplay) { if (parentDisplay == null) parentDisplay = getTreeRoot(); Iterator i = nodes.iterator(); TreeImageDisplay parent; List list; Iterator j; DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); //buildEmptyNode(newNode); boolean toLoad = false; TreeImageDisplay n; while (i.hasNext()) { parent = (TreeImageDisplay) i.next(); //problem will come when we have images if (parent.isChildrenLoaded()) { parent.addChildDisplay(newNode); list = prepareSortedList(sorter.sort(parent.getChildrenDisplay())); parent.removeAllChildren(); j = list.iterator(); while (j.hasNext()) { n = (TreeImageDisplay) j.next(); if (!n.isChildrenLoaded()) { n.removeAllChildren(); buildEmptyNode(n); } dtm.insertNodeInto(n, parent, parent.getChildCount()); } dtm.reload(parent); expandNode(parent); if (parent.equals(parentDisplay)) treeDisplay.setSelectionPath(new TreePath(newNode.getPath())); } else { //Only the currently selected one will be loaded. if (parent.equals(parentDisplay)) toLoad = true; } } //should be leaves. Need to review that code. if (toLoad) { //TO BE MODIFIED //if (parentDisplay.getParentDisplay() == null) //root // controller.loadData(); //else controller.loadLeaves(); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Sorts the nodes in the tree view according to the specified index. * /*from w ww . j a v a 2 s . com*/ * @param type One out of the following constants: * {@link Browser#SORT_NODES_BY_DATE} or * {@link Browser#SORT_NODES_BY_NAME}. */ void sortNodes(int type) { boolean b = type == Browser.SORT_NODES_BY_DATE; sorter.setByDate(b); sorter.setAscending(!b); DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); TreeImageDisplay root = (TreeImageDisplay) dtm.getRoot(); int n = root.getChildCount(); TreeImageDisplay node; List children; Iterator j; List all; switch (model.getBrowserType()) { case Browser.IMAGES_EXPLORER: case Browser.FILES_EXPLORER: for (int i = 0; i < n; i++) { node = (TreeImageDisplay) root.getChildAt(i); children = node.getChildrenDisplay(); j = children.iterator(); TreeImageDisplay child; while (j.hasNext()) { child = (TreeImageDisplay) j.next(); if (child instanceof TreeImageTimeSet || child instanceof TreeFileSet) sortNode((TreeImageSet) child); } } break; case Browser.ADMIN_EXPLORER: for (int i = 0; i < n; i++) { node = (TreeImageDisplay) root.getChildAt(i); children = node.getChildrenDisplay(); node.removeAllChildren(); dtm.reload(node); if (!children.isEmpty()) { if (node.getUserObject() instanceof GroupData) { all = prepareSortedList(sorter.sort(children)); buildTreeNode(node, all, dtm); } else { buildTreeNode(node, sorter.sort(children), dtm); } } else buildEmptyNode(node); j = nodesToReset.iterator(); while (j.hasNext()) { setExpandedParent((TreeImageDisplay) j.next(), true); } } break; default: for (int i = 0; i < n; i++) { node = (TreeImageDisplay) root.getChildAt(i); children = node.getChildrenDisplay(); node.removeAllChildren(); dtm.reload(node); if (!children.isEmpty()) { if (node.getUserObject() instanceof ExperimenterData) { List<Object> sets = new ArrayList<Object>(); List<Object> toSort = new ArrayList<Object>(); Iterator k = children.iterator(); while (k.hasNext()) { Object object = (Object) k.next(); if (object instanceof TreeFileSet) { sets.add((TreeFileSet) object); } else toSort.add(object); } sets.addAll(sorter.sort(toSort)); Collections.reverse(sets); all = prepareSortedList(sets); buildTreeNode(node, all, dtm); } else { buildTreeNode(node, sorter.sort(children), dtm); } } else buildEmptyNode(node); j = nodesToReset.iterator(); while (j.hasNext()) { setExpandedParent((TreeImageDisplay) j.next(), true); } } } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Adds the experimenter's data to the passed node. * /*from w ww .j a v a 2 s .c o m*/ * @param nodes The data to add. * @param expNode The selected experimenter node. */ void setExperimenterData(Set nodes, TreeImageDisplay expNode) { DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); expNode.removeAllChildren(); expNode.removeAllChildrenDisplay(); expNode.setChildrenLoaded(Boolean.valueOf(true)); dtm.reload(expNode); Iterator i; if (nodes.size() > 0) { boolean createFolder = true; i = nodes.iterator(); TreeImageDisplay node; TreeFileSet n = null; Set<TreeImageDisplay> toKeep = new HashSet<TreeImageDisplay>(); int type; while (i.hasNext()) { node = (TreeImageDisplay) i.next(); if (node instanceof TreeFileSet) { type = ((TreeFileSet) node).getType(); if (type == TreeFileSet.TAG || type == TreeFileSet.ORPHANED_IMAGES) { List l = node.getChildrenDisplay(); if (l.size() > 0) { createFolder = false; n = (TreeFileSet) node.copy(); n.setChildrenLoaded(Boolean.valueOf(true)); expNode.addChildDisplay(n); expandNode(n); } } else { toKeep.add(node); expNode.addChildDisplay(node); } } else { toKeep.add(node); expNode.addChildDisplay(node); } } List sorted = prepareSortedList(sorter.sort(toKeep)); if (n != null) sorted.add(n); buildTreeNode(expNode, sorted, (DefaultTreeModel) treeDisplay.getModel()); if (createFolder) { switch (model.getBrowserType()) { case Browser.TAGS_EXPLORER: if (n == null) createTagsElements(expNode); break; case Browser.PROJECTS_EXPLORER: buildOrphanImagesNode(expNode); } } } else { switch (model.getBrowserType()) { case Browser.TAGS_EXPLORER: createTagsElements(expNode); break; case Browser.PROJECTS_EXPLORER: buildOrphanImagesNode(expNode); break; default: expNode.setExpanded(false); buildEmptyNode(expNode); } } // i = nodesToReset.iterator(); while (i.hasNext()) setExpandedParent((TreeImageDisplay) i.next(), true); TreeImageDisplay root = getTreeRoot(); TreeImageDisplay element, child; Object ho; List children; for (int j = 0; j < root.getChildCount(); j++) { element = (TreeImageDisplay) root.getChildAt(j); ho = element.getUserObject(); if (ho instanceof GroupData && element.isExpanded()) { expandNode(element); children = element.getChildrenDisplay(); if (children != null) { i = children.iterator(); while (i.hasNext()) { child = (TreeImageDisplay) i.next(); if (child.isExpanded()) expandNode(child); } } } } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Sets the number of items imported during a period of time. * /*from ww w.jav a 2 s .com*/ * @param expNode The node hosting the experimenter. * @param index The index of the time node. * @param value The value to set. */ void setCountValues(TreeImageDisplay expNode, int index, Object value) { DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); if (model.getBrowserType() != Browser.TAGS_EXPLORER) expNode.setChildrenLoaded(Boolean.valueOf(true)); int n = expNode.getChildCount(); TreeImageSet node; List l; Iterator i, k; TreeImageTimeSet child; //Test List<TreeImageSet> toRemove = new ArrayList<TreeImageSet>(); List<TreeImageSet> toKeep = new ArrayList<TreeImageSet>(); int number; int total; DefaultMutableTreeNode childNode; List<DefaultMutableTreeNode> remove = new ArrayList<DefaultMutableTreeNode>(); for (int j = 0; j < n; j++) { childNode = (DefaultMutableTreeNode) expNode.getChildAt(j); Object o = childNode.getUserObject(); if (o instanceof String) { String s = (String) o; if (Browser.EMPTY_MSG.equals(s)) { remove.add(childNode); } } if (childNode instanceof TreeImageTimeSet) { node = (TreeImageTimeSet) childNode; if (((TreeImageTimeSet) node).getType() == index) { if (value instanceof Integer) { //Check if the number is 0 int vv = ((Integer) value).intValue(); long v = node.getNumberItems(); node.setNumberItems(vv); if (v == 0 && vv > 0) { buildEmptyNode(node); node.setChildrenLoaded(Boolean.valueOf(false)); } } else if (value instanceof List) { l = (List) value; total = 0; i = node.getChildrenDisplay().iterator(); while (i.hasNext()) { child = (TreeImageTimeSet) i.next(); number = child.countTime(l); total += number; if (number > 0) { child.setNumberItems(number); toKeep.add(child); } else { toRemove.add(child); } } node.removeAllChildren(); node.removeChildrenDisplay(toRemove); node.setNumberItems(total); k = toKeep.iterator(); while (k.hasNext()) { dtm.insertNodeInto((TreeImageTimeSet) k.next(), node, node.getChildCount()); } } dtm.reload(node); } } else if (childNode instanceof TreeFileSet) { node = (TreeFileSet) childNode; if (((TreeFileSet) node).getType() == index) { if (value instanceof Long) node.setNumberItems((Long) value); } } } if (remove.size() > 0) { Iterator<DefaultMutableTreeNode> j = remove.iterator(); while (j.hasNext()) { expNode.remove(j.next()); dtm.reload(expNode); } } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Adds the specifies nodes to the currently selected * {@link TreeImageDisplay}.//from w w w. j a va2s . c om * * @param nodes The collection of nodes to add. * @param parent The parent of the nodes. */ void setLeavesViews(Collection nodes, TreeImageSet parent) { DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); parent.removeAllChildren(); parent.removeAllChildrenDisplay(); parent.setChildrenLoaded(Boolean.TRUE); if (nodes.size() != 0) { Iterator i = nodes.iterator(); while (i.hasNext()) parent.addChildDisplay((TreeImageDisplay) i.next()); buildTreeNode(parent, sorter.sort(nodes), dtm); } else buildEmptyNode(parent); dtm.reload(parent); if (!isPartialName()) { model.component.accept(new PartialNameVisitor(isPartialName()), TreeImageDisplayVisitor.TREEIMAGE_NODE_ONLY); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Removes the specified experimenter from the tree. * //from ww w . j a v a 2 s . co m * @param exp The experimenter data to remove. * @param refNode The node to remove the experimenter from. */ void removeExperimenter(ExperimenterData exp, TreeImageDisplay refNode) { if (model.getBrowserType() == Browser.ADMIN_EXPLORER) return; if (refNode == null) refNode = getTreeRoot(); List<TreeImageDisplay> nodesToKeep; List l = refNode.getChildrenDisplay(); if (l == null || l.size() == 0) return; Iterator j = l.iterator(); TreeImageDisplay element, node; Object ho; ExperimenterData expElement; DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); Iterator k; node = null; nodesToKeep = new ArrayList<TreeImageDisplay>(); List<TreeImageDisplay> toExpand = new ArrayList<TreeImageDisplay>(); while (j.hasNext()) { element = (TreeImageDisplay) j.next(); ho = element.getUserObject(); if (ho instanceof ExperimenterData) { expElement = (ExperimenterData) ho; if (expElement.getId() == exp.getId()) node = element; else { nodesToKeep.add(element); if (element.isExpanded()) toExpand.add(element); } } } if (node != null) refNode.removeChildDisplay(node); k = nodesToKeep.iterator(); refNode.removeAllChildren(); while (k.hasNext()) { tm.insertNodeInto((TreeImageSet) k.next(), refNode, refNode.getChildCount()); } tm.reload(refNode); k = toExpand.iterator(); while (k.hasNext()) { expandNode((TreeImageSet) k.next(), false); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Loads the files contained in the passed folder. * /* w w w . ja va2 s . c o m*/ * @param display The directory. */ void loadFile(TreeImageDisplay display) { //if ((uo instanceof File) && (display instanceof TreeImageSet)) { display.removeAllChildren(); display.removeAllChildrenDisplay(); display.setChildrenLoaded(Boolean.TRUE); display.setExpanded(true); transformDirectory((TreeImageSet) display); buildTreeNode(display, prepareSortedList(sorter.sort(display.getChildrenDisplay())), (DefaultTreeModel) treeDisplay.getModel()); DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); tm.reload(display); //model.fireFilesCheck(leaves); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Reloads the specified node.//from w w w . j a va 2s . c o m * * @param node The node to reload. */ void reloadContainer(TreeImageDisplay node) { if (node == null) return; node.removeAllChildren(); node.removeAllChildrenDisplay(); node.setChildrenLoaded(Boolean.FALSE); buildEmptyNode(node); treeDisplay.collapsePath(new TreePath(node.getPath())); treeDisplay.expandPath(new TreePath(node.getPath())); DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); tm.reload(node); }
From source file:ropes.MainWindow.java
private void addFileToList(File path) { DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); //get perent directory to see if such node exist File perentDir = path.getParentFile(); DefaultMutableTreeNode node = findNode(root, perentDir.toString()); if (node != null) node.add(new DefaultMutableTreeNode(path)); else {/*from w ww. j a v a 2 s.c o m*/ root.add(new DefaultMutableTreeNode(path)); } //update jtree model.reload(root); }