List of usage examples for javax.swing.tree DefaultTreeModel insertNodeInto
public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Removes the specified group from the tree. * //from ww w .j a v a 2s . c om * @param group The data to remove. */ void removeGroup(GroupData group) { if (model.getBrowserType() == Browser.ADMIN_EXPLORER) return; TreeImageDisplay root = getTreeRoot(); List<TreeImageDisplay> nodesToKeep; List l = root.getChildrenDisplay(); if (l == null || l.size() == 0) return; Iterator j = l.iterator(); TreeImageDisplay element, n, node; Object ho; ExperimenterData expElement; DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); Iterator k; GroupData g; nodesToKeep = new ArrayList<TreeImageDisplay>(); node = null; while (j.hasNext()) { element = (TreeImageDisplay) j.next(); if (element.getUserObject() instanceof GroupData) { g = (GroupData) element.getUserObject(); if (g.getId() == group.getId()) node = element; else nodesToKeep.add(element); } } if (node != null) root.removeChildDisplay(node); k = nodesToKeep.iterator(); root.removeAllChildren(); while (k.hasNext()) { tm.insertNodeInto((TreeImageSet) k.next(), root, root.getChildCount()); } tm.reload(); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java
/** * Creates a new container corresponding to {@link #containerType}. * //from www . j a v a 2 s . c o m * @param name The name of the container. */ private void create(String name) { if (containerType == null) return; if (ProjectData.class.equals(containerType)) { toCreate = new ProjectData(); ((ProjectData) toCreate).setName(name); } else if (ScreenData.class.equals(containerType)) { toCreate = new ScreenData(); ((ScreenData) toCreate).setName(name); } else if (DatasetData.class.equals(containerType)) { toCreate = new DatasetData(); ((DatasetData) toCreate).setName(name); } DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); TreeImageDisplay root = (TreeImageDisplay) dtm.getRoot(); TreeImageSet node = new TreeImageSet(toCreate); node.setDisplayItems(false); dtm.insertNodeInto(node, root, root.getChildCount()); node = (TreeImageSet) root.getChildAt(root.getChildCount() - 1); treeDisplay.setSelectionPath(new TreePath(node.getPath())); if (noDisplay) { noDisplay = false; Container c = getContentPane(); c.remove(body); c.remove(1); c.add(new JScrollPane(treeDisplay), BorderLayout.CENTER); c.add(buildToolBar(), BorderLayout.SOUTH); validate(); repaint(); } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java
/** * Adds the nodes to the specified parent. * // w ww . ja va2 s. co m * @param parent The parent node. * @param nodes The list of nodes to add. * @param tm The tree model. */ private void buildTreeNode(TreeImageDisplay parent, Collection<TreeImageDisplay> nodes, DefaultTreeModel tm) { Iterator<TreeImageDisplay> i = nodes.iterator(); TreeImageDisplay display; List<TreeImageDisplay> children; while (i.hasNext()) { display = (TreeImageDisplay) i.next(); display.setDisplayItems(false); tm.insertNodeInto(display, parent, parent.getChildCount()); if (display instanceof TreeImageSet) { children = display.getChildrenDisplay(); if (children.size() > 0) { buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm); } } } }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java
/** * Updates the specified tree./*w w w. j a v a 2s . c o m*/ * * @param tree The tree to update. * @param nodes The collection of nodes to handle. */ private void populateTreeItems(JTree tree, List<TreeImageDisplay> nodes) { DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); TreeImageDisplay parent = (TreeImageDisplay) dtm.getRoot(); parent.removeAllChildrenDisplay(); parent.removeAllChildren(); Iterator<TreeImageDisplay> i = nodes.iterator(); TreeImageDisplay node, child; Iterator<TreeImageDisplay> j; Set<TreeImageDisplay> toExpand = new HashSet<TreeImageDisplay>(); while (i.hasNext()) { node = i.next(); node.setDisplayItems(false); Object ho = node.getUserObject(); if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; if (!TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()) || node.hasChildrenDisplay()) { dtm.insertNodeInto(node, parent, parent.getChildCount()); } } else { dtm.insertNodeInto(node, parent, parent.getChildCount()); } if (node.hasChildrenDisplay()) { node.removeAllChildren(); tree.expandPath(new TreePath(node.getPath())); Collection<TreeImageDisplay> l = node.getChildrenDisplay(); l = sorter.sort(l); j = l.iterator(); while (j.hasNext()) { child = j.next(); child.setDisplayItems(false); if (!isSelected(child) && !isFiltered(child)) { dtm.insertNodeInto(child, node, node.getChildCount()); toExpand.add(node); tree.expandPath(new TreePath(node.getPath())); } } } } dtm.reload(); i = toExpand.iterator(); while (i.hasNext()) { tree.expandPath(new TreePath(i.next().getPath())); } }
From source file:ser321.media.MediaJavaClient.java
public void rebuildTree() { //String[] musicList = {"Come Monday","Fins","Crazy"}; //String[] musicAlbum = {"Greatest Hits","Greatest Hits","Single"}; //String[] videoList = {"Minions Banana Song","Minions Banana"}; //String[] videoGenre = {"Animation","Animation"}; cc.clear();//from w w w .ja v a 2 s. c om cc.getTitles(); cc.getVideoTitles(); cc.getMusicTitles(); tree.removeTreeSelectionListener(this); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); clearTree(root, model); DefaultMutableTreeNode musicNode = new DefaultMutableTreeNode("Music"); model.insertNodeInto(musicNode, root, model.getChildCount(root)); DefaultMutableTreeNode videoNode = new DefaultMutableTreeNode("Video"); model.insertNodeInto(videoNode, root, model.getChildCount(root)); // put nodes in the tree for all registered with the library for (int i = 0; i < cc.musicTitles.size(); i++) { String aMTitle = cc.musicTitles.get(i); DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(aMTitle); model.insertNodeInto(toAdd, musicNode, i); } // put nodes in the tree for all video registered with the library for (int i = 0; i < cc.videoTitles.size(); i++) { String aTitle = cc.videoTitles.get(i); DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(aTitle); model.insertNodeInto(toAdd, videoNode, i); } // expand all the nodes in the JTree for (int r = 0; r < tree.getRowCount(); r++) { tree.expandRow(r); } tree.addTreeSelectionListener(this); }