r2109 - in trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav: . tree treetable
Author: sletellier Date: 2010-10-13 17:21:24 +0200 (Wed, 13 Oct 2010) New Revision: 2109 Url: http://nuiton.org/repositories/revision/jaxx/2109 Log: Add method to get child with node id Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavNode.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/tree/NavTreeNode.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/treetable/NavTreeTableNode.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavHelper.java 2010-10-08 23:50:22 UTC (rev 2108) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavHelper.java 2010-10-13 15:21:24 UTC (rev 2109) @@ -874,6 +874,24 @@ } /** + * Finds a node from the given root {@code node}, and return child searched + * + * @param node the starting node + * @param id of child searched + * @return the find node or {@code null} if no node matchs. + */ + public N getChild(N node, String id) { + if (!checkModel()) { + + // no model + return null; + } + N result = node.getChild(id, getBridge(), getDataProvider()); + + return result; + } + + /** * Checks if internal model was created. * * @return {@code true} if model was created, {@code false} otherwise. Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavNode.java 2010-10-08 23:50:22 UTC (rev 2108) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/NavNode.java 2010-10-13 15:21:24 UTC (rev 2109) @@ -131,7 +131,7 @@ * <p/> * If node is NOT {@code loaded}, then first loads it (method * {@link #populateChilds(NavBridge , NavDataProvider)}) then do search - * on direct childs of the node. + * on direct childs of the node recursivly. * * @param id the id of the researched node * @param bridge model owner of nodes @@ -143,6 +143,22 @@ NavDataProvider provider); /** + * Given an {@code id}, obtain the child with matching id. + * <p/> + * If node is NOT {@code loaded}, then first loads it (method + * {@link #populateChilds(NavBridge , NavDataProvider)}) then return + * on direct childs of the node. + * + * @param id the id of the researched node + * @param bridge model owner of nodes + * @param provider data provider + * @return the found node or {@code null} if not found + */ + N getChild(String id , + NavBridge<M, N> model, + NavDataProvider provider); + + /** * Changes the {@link #isDirty} state. * <p/> * As a side effect, when a renderer will use this node, it will force to Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/tree/NavTreeNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/tree/NavTreeNode.java 2010-10-08 23:50:22 UTC (rev 2108) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/tree/NavTreeNode.java 2010-10-13 15:21:24 UTC (rev 2109) @@ -188,6 +188,42 @@ } @Override + public N getChild(String id , + NavBridge<DefaultTreeModel, N> model, + NavDataProvider provider) { + + if (id == null) { + + // id null ? donc rien a faire + return null; + } + + if (!isLoaded()) { + + // il faut charger les fils du noeud pour effectuer la recherche + populateChilds(model, provider); + } + + if (isLeaf()) { + + // au final le noeud est une feuille, donc ne convient pas + return null; + } + + // on recherche dans les fils + Enumeration<N> enumeration = children(); + while (enumeration.hasMoreElements()) { + N child = enumeration.nextElement(); + if (id.equals(child.getId())) { + return child; + } + } + + // aucun des noeud fils ne convient + return null; + } + + @Override public void setDirty(boolean dirty) { this.dirty = dirty; } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/treetable/NavTreeTableNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/treetable/NavTreeTableNode.java 2010-10-08 23:50:22 UTC (rev 2108) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/nav/treetable/NavTreeTableNode.java 2010-10-13 15:21:24 UTC (rev 2109) @@ -196,6 +196,42 @@ } @Override + public N getChild(String id , + NavBridge<NavTreeTableModel, N> model, + NavDataProvider provider) { + + if (id == null) { + + // id null ? donc rien a faire + return null; + } + + if (!isLoaded()) { + + // il faut charger les fils du noeud pour effectuer la recherche + populateChilds(model, provider); + } + + if (isLeaf()) { + + // au final le noeud est une feuille, donc ne convient pas + return null; + } + + // on recherche dans les fils + Enumeration<N> enumeration = children(); + while (enumeration.hasMoreElements()) { + N node = enumeration.nextElement(); + if (id.equals(node.getId())) { + return node; + } + } + + // aucun des noeud fils ne convient + return null; + } + + @Override public void setDirty(boolean dirty) { this.dirty = dirty; }
participants (1)
-
sletellier@users.nuiton.org