Author: tchemit Date: 2010-06-22 20:16:01 +0200 (Tue, 22 Jun 2010) New Revision: 1980 Url: http://nuiton.org/repositories/revision/jaxx/1980 Log: add more override method Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-22 16:53:04 UTC (rev 1979) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-22 18:16:01 UTC (rev 1980) @@ -29,6 +29,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; import java.util.Enumeration; /** @@ -45,6 +46,22 @@ * When node was loaded, a leaf node will be then displayed as required. * </i></p> * <p/> + * <h2>Why JaxxNode is generic ?</h2> + * In a project, you should implements your own Node extending with one like this : + * <pre> + * class MyNode extends JaxxNode<MyNode> { ... } + * </pre> + * While in this class, you overrides every method with a node return type, + * co-variance you'll be able to use this code : + * <pre> + * MyNode parentNode = new MyNode(); + * MyNode node = parentNode.getFirstNode(); + * </pre> + * So for final application this generic type avoid any cast for your own node + * type, this is quite convinient. + * <p/> + * Even if in your project, you wants to have a heriarchy of nodes, this will + * still works (if you use a genercic type on your abstract nodes). * <h2>Internal states</h2> * <ul> * <li><b>internalClass</b> : the type of data associated with the node</li> @@ -145,42 +162,6 @@ return dirty; } - @Override - public Object getUserObject() { - return id; - } - - @Override - public N getParent() { - return (N) super.getParent(); - } - - @Override - public N getRoot() { - return (N) super.getRoot(); - } - - @Override - public N getChildAt(int index) { - return (N) super.getChildAt(index); - } - - @Override - public Enumeration<N> children() { - return (Enumeration<N>) super.children(); - } - - @Override - public boolean isLeaf() { - // there is two behaviours for the test : - // 1 - when the node is static, then can directly use his number of child - // to determine if node is a leaf (no child) - // 2 - when the node is dynamic, then ALWAYS says the node is NOT a leaf until - // it was loaded, otherwise the WillExpand listener will not load the childs... - // Once the node is loaded, use back the normal behaviour (count number of childs) - return isStaticNode() ? super.isLeaf() : isLoaded() && getChildCount() == 0; - } - /** * Convinient method to known if the node is a {@code String} typed. * @@ -225,18 +206,6 @@ } /** - * Changes the {@link #dirty} state. - * <p/> - * As a side effect, when a renderer will use this node, it will force to - * reload the render from the {@link DataProvider}. - * - * @param dirty the new dirty value - */ - public void setDirty(boolean dirty) { - this.dirty = dirty; - } - - /** * Given an {@code id}, obtain the child with matching id. * <p/> * If node is NOT {@code loaded}, then first loads it (method @@ -289,6 +258,43 @@ } /** + * Changes the {@link #dirty} state. + * <p/> + * As a side effect, when a renderer will use this node, it will force to + * reload the render from the {@link DataProvider}. + * + * @param dirty the new dirty value + */ + public void setDirty(boolean dirty) { + this.dirty = dirty; + } + + @Override + public boolean isLeaf() { + // there is two behaviours for the test : + // 1 - when the node is static, then can directly use his number of child + // to determine if node is a leaf (no child) + // 2 - when the node is dynamic, then ALWAYS says the node is NOT a leaf until + // it was loaded, otherwise the WillExpand listener will not load the childs... + // Once the node is loaded, use back the normal behaviour (count number of childs) + return isStaticNode() ? super.isLeaf() : isLoaded() && getChildCount() == 0; + } + + @Override + public Object getUserObject() { + return id; + } + + @Override + public String toString() { + return System.identityHashCode(this) + "-" + id; + } + + //-------------------------------------------------------------------------- + //-- Populate methods + //-------------------------------------------------------------------------- + + /** * To populate the node. A side-effect of this method is to set {@code dirty} * the node (renderer will recompute the render of the node). * <p/> @@ -344,9 +350,110 @@ } } + //-------------------------------------------------------------------------- + //-- Overrides to use generic type as return + //-------------------------------------------------------------------------- + + @SuppressWarnings({"unchecked"}) @Override - public String toString() { - return System.identityHashCode(this) + "-" + id; + public N getParent() { + return (N) super.getParent(); } + @SuppressWarnings({"unchecked"}) + @Override + public N getRoot() { + return (N) super.getRoot(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getFirstChild() { + return (N) super.getFirstChild(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getLastChild() { + return (N) super.getLastChild(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getChildAfter(TreeNode aChild) { + return (N) super.getChildAfter(aChild); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getChildBefore(TreeNode aChild) { + return (N) super.getChildBefore(aChild); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getNextSibling() { + return (N) super.getNextSibling(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getPreviousSibling() { + return (N) super.getPreviousSibling(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getFirstLeaf() { + return (N) super.getFirstLeaf(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getLastLeaf() { + return (N) super.getLastLeaf(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getNextLeaf() { + return (N) super.getNextLeaf(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getPreviousLeaf() { + return (N) super.getPreviousLeaf(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getNextNode() { + return (N) super.getNextNode(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getPreviousNode() { + return (N) super.getPreviousNode(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getSharedAncestor(DefaultMutableTreeNode aNode) { + return (N) super.getSharedAncestor(aNode); + } + + @SuppressWarnings({"unchecked"}) + @Override + public N getChildAt(int index) { + return (N) super.getChildAt(index); + } + + @SuppressWarnings({"unchecked"}) + @Override + public Enumeration<N> children() { + return (Enumeration<N>) super.children(); + } + }
participants (1)
-
tchemit@users.nuiton.org