List of usage examples for javax.swing.tree MutableTreeNode getChildCount
int getChildCount();
TreeNode
s the receiver contains. From source file:MainClass.java
private int findIndexFor(MutableTreeNode child, MutableTreeNode parent) { int cc = parent.getChildCount(); if (cc == 0) { return 0; }//from ww w .j a v a 2 s . co m if (cc == 1) { return comparator.compare(child, parent.getChildAt(0)) <= 0 ? 0 : 1; } return findIndexFor(child, parent, 0, cc - 1); }
From source file:SortTreeDemo.java
private int findIndexFor(MutableTreeNode child, MutableTreeNode parent) { int cc = parent.getChildCount(); if (cc == 0) { return 0; }//from www .jav a2 s .co m if (cc == 1) { return comparator.compare(child, parent.getChildAt(0)) <= 0 ? 0 : 1; } return findIndexFor(child, parent, 0, cc - 1); // First & last index }
From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java
private MutableTreeNode insertNode(MutableTreeNode parentNode, Object childObject) { MutableTreeNode childNode = new DefaultMutableTreeNode(childObject); model.insertNodeInto(childNode, parentNode, parentNode.getChildCount()); return childNode; }
From source file:org.feistymeow.dragdrop.dragdrop_tree_test.java
public dragdrop_tree_test(String startPath) { super("dragdrop_test"); // create the tree, configure it to show our hashtable nodes, and put it in // a scroll pane. larch = new DraggableDroppableTree(startPath); DefaultTreeModel treeModel = (DefaultTreeModel) larch.getModel(); larch.setCellRenderer(new CustomCellRenderer()); TreeSelectionModel selmod = new DefaultTreeSelectionModel(); selmod.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); larch.setSelectionModel(selmod);//from www .j a v a 2 s. c o m larch.addTreeSelectionListener(this); JScrollPane listScrollPane = new JScrollPane(larch); // get the files that live in the specified directory. String dirName = startPath + "/"; // make sure we think of it as a // directory. String filelist[] = new File(dirName).list(); MutableTreeNode root_node = (MutableTreeNode) treeModel.getRoot(); if (root_node == null) { logger.error("something is not right about tree. has null root."); System.exit(1); } // load up the tree with the files in the directory they passed. for (int i = 0; i < filelist.length; i++) { String thisFileSt = dirName + filelist[i]; File thisFile = new File(thisFileSt); // skip directories for now. if (thisFile.isDirectory()) continue; // skip dot files. if (filelist[i].startsWith(".")) continue; try { // need to trap exceptions from the URI/URL functions. DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(makeNode(thisFile.getName(), thisFile.toURI().toURL().toString(), thisFile.getAbsolutePath())); treeModel.insertNodeInto(newNode, root_node, root_node.getChildCount()); } catch (java.net.MalformedURLException e) { logger.warn("caught an exception while trying to process path: " + thisFile.getAbsolutePath()); } } // set our status bar to have the current path info. fileName = new JTextField(50); // select the root. larch.setSelectionPath(larch.getPathForRow(0)); // pop out all the nodes. larch.expandAll(); // Create a panel that uses FlowLayout (the default). JPanel buttonPane = new JPanel(); buttonPane.add(fileName); Container contentPane = getContentPane(); contentPane.add(listScrollPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.NORTH); }
From source file:org.openconcerto.erp.model.FamilleArticleTree.java
/** * Ajoute un noeud dans l'arbre dans l'ordre alphabtique * /*www . jav a 2 s . c om*/ * @param nodeToAdd * @param nodeParent */ private void addNode(FamilleTreeNode nodeToAdd, MutableTreeNode nodeParent) { int n = 0; for (; n < nodeParent.getChildCount(); n++) { if (nodeToAdd.toString().compareToIgnoreCase(nodeParent.getChildAt(n).toString()) < 0) { break; } } model.insertNodeInto(nodeToAdd, nodeParent, n); }
From source file:org.openconcerto.erp.model.FamilleArticleTree.java
/** * // w w w. j av a 2s.c om * @param row * @param nodeParent */ private void modifyNode(SQLRow row, MutableTreeNode nodeParent) { for (int i = 0; i < nodeParent.getChildCount(); i++) { Object o = nodeParent.getChildAt(i); if (o instanceof VariableRowTreeNode) { VariableRowTreeNode v = (VariableRowTreeNode) o; if (v.getID() == row.getID()) { v.setRow(row); model.nodeChanged(v); } } } }
From source file:org.openconcerto.erp.model.FamilleArticleTree.java
private void setTableListener() { SQLTableListener listener = new SQLTableListener() { public void rowModified(SQLTable table, int id) { System.err.println("row modified --> " + table.getName() + ", " + id); MutableTreeNode node = mapNode.get(Integer.valueOf(id)); if (node != null && node instanceof FamilleTreeNode) { modifyNode(table.getRow(id), node); }//w w w . j a v a 2 s .com } public void rowAdded(SQLTable table, int id) { System.err.println("row added --> " + table.getName() + ", " + id); // Thread.dumpStack(); SQLRow row = table.getRow(id); int idPere = row.getInt("ID_FAMILLE_ARTICLE_PERE"); addFamille(id, idPere); } public void rowDeleted(SQLTable table, int id) { System.err.println("row deleted --> " + table.getName() + ", " + id); MutableTreeNode node = mapNode.get(Integer.valueOf(id)); for (int i = 0; i < node.getChildCount(); i++) { removeNode(table.getRow(id), node); } } }; familleElt.getTable().addTableListener(listener); }
From source file:org.openconcerto.erp.model.FamilleArticleTree.java
private void removeNode(SQLRow row, MutableTreeNode nodeParent) { for (int i = 0; i < nodeParent.getChildCount(); i++) { Object o = nodeParent.getChildAt(i); if (o instanceof FamilleTreeNode) { FamilleTreeNode v = (FamilleTreeNode) o; if (v.getId() == row.getID()) { model.removeNodeFromParent(v); }//from ww w .ja v a2 s . c o m } } }
From source file:org.openconcerto.erp.model.RubriquePayeTree.java
private static void addNode(VariableRowTreeNode nodeToAdd, MutableTreeNode nodeParent) { int n = 0;//w w w . j a v a 2s . c o m for (; n < nodeParent.getChildCount(); n++) { if (nodeToAdd.toString().compareToIgnoreCase(nodeParent.getChildAt(n).toString()) < 0) { break; } } model.insertNodeInto(nodeToAdd, nodeParent, n); }
From source file:org.openconcerto.erp.model.RubriquePayeTree.java
private static void modifyNode(SQLRow row, MutableTreeNode nodeParent) { for (int i = 0; i < nodeParent.getChildCount(); i++) { Object o = nodeParent.getChildAt(i); if (o instanceof VariableRowTreeNode) { VariableRowTreeNode v = (VariableRowTreeNode) o; if (v.getID() == row.getID()) { v.setRow(row);/* ww w . ja va 2 s . c om*/ model.nodeChanged(v); } } } }