Author: sletellier Date: 2011-05-16 11:24:13 +0200 (Mon, 16 May 2011) New Revision: 891 Url: http://nuiton.org/repositories/revision/wikitty/891 Log: #1519 TreeNodeResult has null id in proxy Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/TreeNodeResult.java Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java 2011-05-14 11:45:33 UTC (rev 890) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyProxy.java 2011-05-16 09:24:13 UTC (rev 891) @@ -25,6 +25,7 @@ package org.nuiton.wikitty; +import java.io.Serializable; import java.lang.reflect.Array; import java.util.AbstractMap.SimpleEntry; import org.apache.commons.logging.Log; @@ -1032,7 +1033,7 @@ * @param <TARGET> le type d'objet pour le nouvel arbre * @since 3.1 */ - static private class ConvertTreeVisitor<TARGET> implements TreeNodeResult.Visitor<String> { + static private class ConvertTreeVisitor<TARGET extends Serializable> implements TreeNodeResult.Visitor<String> { static private interface Converter<SOURCE, TARGET> { public TARGET convert(SOURCE o); Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/TreeNodeResult.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/TreeNodeResult.java 2011-05-14 11:45:33 UTC (rev 890) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/search/TreeNodeResult.java 2011-05-16 09:24:13 UTC (rev 891) @@ -25,12 +25,12 @@ package org.nuiton.wikitty.search; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; import java.util.List; -import java.util.Vector; import javax.swing.tree.DefaultMutableTreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,18 +45,21 @@ * Last update: $Date$ * by : $Author$ */ -public class TreeNodeResult<T> extends DefaultMutableTreeNode implements Iterable<TreeNodeResult<T>> { +public class TreeNodeResult<T extends Serializable> extends DefaultMutableTreeNode implements Iterable<TreeNodeResult<T>> { /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(TreeNodeResult.class); private static final long serialVersionUID = 31L; + /** optional user object */ + protected T object; + /** * Visitor for TreeNodeResult * @param <T> */ - static public interface Visitor<T> { + static public interface Visitor<T extends Serializable> { /** * * @param node node to visit @@ -79,11 +82,82 @@ * @param attCount le nombre d'attachment pour ce noeud (avec les sous noeud) */ public TreeNodeResult(T object, int attCount) { - super(object); + this(object); this.attCount = attCount; } /** + * sletellier 20110516 : override all methods using userObject, + * because this one is transient and getter and setters are not used + */ + + /** + * Creates a tree node with no parent, no children, but which allows + * children, and initializes it with the specified user object. + * + * @param userObject an Object provided by the user that constitutes + * the node's data + */ + public TreeNodeResult(T userObject) { + this(userObject, true); + } + + /** + * Creates a tree node with no parent, no children, initialized with + * the specified user object, and that allows children only if + * specified. + * + * @param userObject an Object provided by the user that constitutes + * the node's data + * @param allowsChildren if true, the node is allowed to have child + * nodes -- otherwise, it is always a leaf node + */ + public TreeNodeResult(T userObject, boolean allowsChildren) { + super(userObject, allowsChildren); + this.object = userObject; + } + + /** + * Sets the user object for this node to <code>userObject</code>. + * + * @param userObject the Object that constitutes this node's + * user-specified data + * @see #getUserObject + * @see #toString + */ + public void setUserObject(T userObject) { + super.setUserObject(userObject); + this.object = userObject; + } + + /** + * Returns this node's user object. + * + * @return the Object stored at this node by the user + * @see #toString + */ + @Override + public T getUserObject() { + return object; + } + + /** + * Returns the result of sending <code>toString()</code> to this node's + * user object, or null if this node has no user object. + * + * @see #getUserObject + */ + @Override + public String toString() { + T userObject = getUserObject(); + if (userObject == null) { + return null; + } else { + return userObject.toString(); + } + } + + /** * Visite en profondeur de l'arbre, il est possible d'arreter la visite * soit en entrant dans le noeud soit en sortant du noeud, si respectivement * visitEnter ou visitLeave retourne false. @@ -153,7 +227,7 @@ * @return l'objet associe avec ce noeud (id, wikitty ou BusinessEntity) */ public T getObject() { - return (T)getUserObject(); + return getUserObject(); } /**