List of usage examples for javax.swing.tree DefaultMutableTreeNode getChildCount
public int getChildCount()
From source file:org.codinjutsu.tools.nosql.redis.view.RedisFragmentedKeyTreeModel.java
private static NoSqlTreeNode findNodeByKey(DefaultMutableTreeNode parentTargetNode, String keyFragment) { for (int i = 0; i < parentTargetNode.getChildCount(); i++) { NoSqlTreeNode currentChild = (NoSqlTreeNode) parentTargetNode.getChildAt(i); NodeDescriptor descriptor = currentChild.getDescriptor(); String nodeKey;/* ww w .j a v a2s. c om*/ if (descriptor instanceof FragmentedKeyNodeDescriptor) { nodeKey = ((FragmentedKeyNodeDescriptor) descriptor).getKeyFragment(); } else if (descriptor instanceof RedisKeyValueDescriptor) { nodeKey = ((RedisKeyValueDescriptor) descriptor).getKey(); } else { return null; } if (keyFragment.equals(nodeKey)) { return currentChild; } } return null; }
From source file:org.eclipse.wb.tests.designer.swing.model.component.JTreeTest.java
public void test_JTree_parsing() throws Exception { ContainerInfo panel = parseContainer("import javax.swing.tree.*;", "public class Test extends JPanel {", " public Test() {", " JTree tree = new JTree();", " add(tree);", " tree.setModel(new DefaultTreeModel(", " new DefaultMutableTreeNode('(root)') {", " {", " DefaultMutableTreeNode node1 = new DefaultMutableTreeNode('1');", " DefaultMutableTreeNode node2 = new DefaultMutableTreeNode('11');", " node1.add(node2);", " add(node1);", " node1 = new DefaultMutableTreeNode('2');", " node1.add(new DefaultMutableTreeNode('21'));", " add(node1);", " }", " }", " ));", " }", "}"); panel.refresh();/* w w w . java 2s . co m*/ // ComponentInfo treeInfo = panel.getChildrenComponents().get(0); JTree treeObject = (JTree) treeInfo.getObject(); // validate model { TreeModel model = treeObject.getModel(); assertNotNull(model); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); { assertEquals("(root)", rootNode.getUserObject()); assertEquals(2, rootNode.getChildCount()); } { DefaultMutableTreeNode node_1 = (DefaultMutableTreeNode) rootNode.getChildAt(0); assertEquals("1", node_1.getUserObject()); assertEquals(1, node_1.getChildCount()); { DefaultMutableTreeNode node_2 = (DefaultMutableTreeNode) node_1.getChildAt(0); assertEquals("11", node_2.getUserObject()); assertEquals(0, node_2.getChildCount()); } } { DefaultMutableTreeNode node_1 = (DefaultMutableTreeNode) rootNode.getChildAt(1); assertEquals("2", node_1.getUserObject()); assertEquals(1, node_1.getChildCount()); { DefaultMutableTreeNode node_2 = (DefaultMutableTreeNode) node_1.getChildAt(0); assertEquals("21", node_2.getUserObject()); assertEquals(0, node_2.getChildCount()); } } } // check "model" property { Property modelProperty = treeInfo.getPropertyByTitle("model"); PropertyEditor modelEditor = modelProperty.getEditor(); // text { String text = (String) ReflectionUtils.invokeMethod2(modelEditor, "getText", Property.class, modelProperty); assertEquals("(root), +1, ++11, +2, ++21", text); } // tooltip { String tooltip = getPropertyTooltipText(modelEditor, modelProperty); assertEquals(StringUtils.join( new String[] { "(root)", " 1", " 11", " 2", " 21" }, "\n"), tooltip); // position PropertyTooltipProvider provider = modelEditor.getAdapter(PropertyTooltipProvider.class); assertSame(PropertyTooltipProvider.BELOW, provider.getTooltipPosition()); } } }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
private void addRepositoryNode(DefaultMutableTreeNode pnode, Object repositoryObject) { if (pnode != null) { getModel().insertNodeInto(new RepositoryNode(configuration, repositoryObject), pnode, pnode.getChildCount()); }/* ww w . ja v a2 s .c o m*/ }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
private void addRepositoryNodes(DefaultMutableTreeNode pnode, List repositoryObjects) { if (pnode != null) { DefaultTreeModel model = getModel(); for (Object repositoryObject : repositoryObjects) { model.insertNodeInto(new RepositoryNode(configuration, repositoryObject), pnode, pnode.getChildCount()); }// www. j ava 2 s .c om } }
From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java
private void loadSelectedDbObjects(DefaultMutableTreeNode node, List<TableData> selectedDbObjects) { if (node.getUserObject() instanceof TableData) { TableData td = (TableData) node.getUserObject(); if (hasSelectedColumns(td)) { selectedDbObjects.add(td);//from w ww .j ava2 s.co m } } for (int i = 0; i < node.getChildCount(); ++i) { loadSelectedDbObjects((DefaultMutableTreeNode) node.getChildAt(i), selectedDbObjects); } }
From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java
public void dataNodeChanged(DataNodeEvent e) { DefaultMutableTreeNode node = getProjectModel() .getNodeForObjectPath(new Object[] { mediator.getCurrentDataDomain(), e.getDataNode() }); if (node != null) { if (e.isNameChange()) { positionNode((DefaultMutableTreeNode) node.getParent(), node, Comparators.getDataDomainChildrenComparator()); showNode(node);//from w w w. ja v a 2 s . c om } else { getProjectModel().nodeChanged(node); // check for DataMap additions/removals... Object[] maps = e.getDataNode().getDataMaps().toArray(); int mapCount = maps.length; // DataMap was linked if (mapCount > node.getChildCount()) { for (int i = 0; i < mapCount; i++) { boolean found = false; for (int j = 0; j < node.getChildCount(); j++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(j); if (maps[i] == child.getUserObject()) { found = true; break; } } if (!found) { DefaultMutableTreeNode newMapNode = new DefaultMutableTreeNode(maps[i], false); positionNode(node, newMapNode, Comparators.getNamedObjectComparator()); break; } } } // DataMap was unlinked else if (mapCount < node.getChildCount()) { for (int j = 0; j < node.getChildCount(); j++) { boolean found = false; DefaultMutableTreeNode child; child = (DefaultMutableTreeNode) node.getChildAt(j); Object obj = child.getUserObject(); for (int i = 0; i < mapCount; i++) { if (maps[i] == obj) { found = true; break; } } if (!found) { removeNode(child); break; } } } } } }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Analyser le fichier PUML et initialiser le filtre * * @param jTextAreaFichier Le contenu du fichier PUML * @param jTreeFiltre Le filtre initialiser *///from w ww. j a v a2 s . c om private void analyserFichier(JTextArea jTextAreaFichier, JTree jTreeFiltre) { lines = jTextAreaFichier.getText().split("[\\r\\n]+"); final DefaultMutableTreeNode newFilter = initaliserNodes(); // parcours de chaque ligne du fichier pour analyse for (String line : lines) { if (line.contains(">")) { break; } else { String categ = ""; String noeud = null; // recherche de la catgorie for (String categorie : categories) { if (line.contains(categorie)) { categ = categorie; noeud = line.replaceFirst(categorie, "").replaceAll(" ", ""); // ajout du noeud dans la bonne catgorie de l'arbre for (int i = 0; i < newFilter.getChildCount(); i++) { final DefaultMutableTreeNode dmtr = (DefaultMutableTreeNode) newFilter.getChildAt(i); if (dmtr.toString().equals(categ)) { final DefaultMutableTreeNode node = new DefaultMutableTreeNode(new NodeInfo(noeud)); dmtr.add(node); } } break; } } } } jTreeFiltre.setModel(new DefaultTreeModel(newFilter)); jTextAreaFichier.requestFocus(); }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Analyse une ligne et dtermine si elle est imprimable ou pas * * @param line La ligne analyser//from ww w . ja va 2 s.c om * @param nodeToDelete Liste des noeuds supprimer * @return True si la ligne doit etre imprime, false sinon */ private boolean isLinePrintable(String line, DefaultMutableTreeNode nodeToDelete) { boolean isPrintable = true; // parcours des catgories for (int i = 0; i < nodeToDelete.getChildCount(); i++) { final TreeNode categ = nodeToDelete.getChildAt(i); // parcours des noeuds supprimer for (int j = 0; j < categ.getChildCount(); j++) { final DefaultMutableTreeNode noeudToDelete = (DefaultMutableTreeNode) categ.getChildAt(j); final String nomNoeudToDelete = noeudToDelete.toString(); if (line.contains(nomNoeudToDelete)) { isPrintable = false; break; } } if (!isPrintable) { break; } } return isPrintable; }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Renvoi la liste des noeuds non slectionns * * @param allTreeNode Liste de tous les noeuds * @param selectedPath Chemins slectionns * @return Liste des noeuds non slectionns *///from w w w . j a v a 2s.c o m private DefaultMutableTreeNode getNodeToDelete(DefaultMutableTreeNode allTreeNode, TreePath[] selectedPath) { final DefaultMutableTreeNode nodeToDelete = new DefaultMutableTreeNode("Node to delete"); // Parcours de l'arbre pour supprimer les noeuds slectionns // Parcours des catgories for (int i = 0; i < allTreeNode.getChildCount(); i++) { final DefaultMutableTreeNode tnCateg = (DefaultMutableTreeNode) allTreeNode.getChildAt(i); // les catgories sont systmatiquement ajoutes final DefaultMutableTreeNode newTnCateg = new DefaultMutableTreeNode(tnCateg.toString());//) allTreeNode.getChildAt(i); nodeToDelete.add(newTnCateg); // parcours des noeuds for (int j = 0; j < tnCateg.getChildCount(); j++) { final DefaultMutableTreeNode tnNoeud = (DefaultMutableTreeNode) tnCateg.getChildAt(j); // Ajout du noeud s'il n'est pas slectionn if (!isNoeudSelected(tnNoeud, selectedPath)) { /* Il est impratif de crer un nouveau noeud ! Si on se contente d'ajouter tnNoeud dans newTnCateg, celui-ci est supprim de tnCateg ! Visiblement, un noeud ne peut pas appartenir 2 arbres diffrents. Cela semble logique car la dfinition des anctres risque de poser problme. A approfondir quand j'aurai le temps ... */ final DefaultMutableTreeNode newTnNoeud = new DefaultMutableTreeNode( new NodeInfo(tnNoeud.toString())); newTnCateg.add(newTnNoeud); } } } return nodeToDelete; }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Indique si un noeud est slectionn ou pas * * @param noeudATester Le noeud tester//from w ww . j a va 2s . c o m * @param selectedPath La liste des noeuds slectionns * @return True si le noeud est slectionn, false sinon */ private boolean isNoeudSelected(final DefaultMutableTreeNode noeudATester, final TreePath[] selectedPath) { boolean isSelected = false; // parcours des categories for (TreePath path : selectedPath) { try { // Cette ligne plante quand on slectionne une catgorie complte d'ou le try-catch ! final DefaultMutableTreeNode unNoeudSelectionner = (DefaultMutableTreeNode) path.getPath()[2]; isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString()); } catch (ArrayIndexOutOfBoundsException ex) { // Quand on choisit une catgorie complte, il faut parcourir les noeuds de cette manire : // recup de la categorie final DefaultMutableTreeNode categ = (DefaultMutableTreeNode) path.getLastPathComponent(); // parcours des noeuds dans la catgorie for (int j = 0; j < categ.getChildCount(); j++) { final TreeNode unNoeudSelectionner = categ.getChildAt(j); isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString()); if (isSelected) { break; } } } // on sort de la boucle ds qu'on a la rponse if (isSelected) { break; } } return isSelected; }