myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject cvs commit: incubator-myfaces/tlds myfaces_ext.tld
Date Mon, 07 Mar 2005 16:17:21 GMT
matzew      2005/03/07 08:17:20

  Modified:    src/share/org/apache/myfaces/renderkit JSFAttr.java
               src/components/org/apache/myfaces/custom/tree2
                        HtmlTreeRenderer.java TreeTag.java
               tlds     myfaces_ext.tld
  Log:
  Patch for the new tree form Sean Schofield
  
  Revision  Changes    Path
  1.12      +2 -1      incubator-myfaces/src/share/org/apache/myfaces/renderkit/JSFAttr.java
  
  Index: JSFAttr.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/JSFAttr.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JSFAttr.java	7 Mar 2005 09:06:51 -0000	1.11
  +++ JSFAttr.java	7 Mar 2005 16:17:19 -0000	1.12
  @@ -119,6 +119,7 @@
       public static final String SHOW_NAV                    = "org.apache.myfaces.tree.SHOW_NAV";
       public static final String SHOW_LINES                  = "org.apache.myfaces.tree.SHOW_LINES";
       public static final String CLIENT_SIDE_TOGGLE          = "org.apache.myfaces.tree.CLIENT_SIDE_TOGGLE";
  +    public static final String SHOW_ROOT_NODE              = "org.apache.myfaces.tree.SHOW_ROOT_NODE";
   
       // Alternate locations (instead of using AddResource)
       public static final String JAVASCRIPT_LOCATION         = "org.apache.myfaces.JAVASCRIPT_LOCATION";
  
  
  
  1.9       +288 -209  incubator-myfaces/src/components/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java
  
  Index: HtmlTreeRenderer.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HtmlTreeRenderer.java	7 Mar 2005 09:06:51 -0000	1.8
  +++ HtmlTreeRenderer.java	7 Mar 2005 16:17:19 -0000	1.9
  @@ -59,7 +59,9 @@
       private static final String ATTRIB_KEYVAL = "=";
       private static final String NODE_STATE_EXPANDED = "x";
       private static final String NODE_STATE_CLOSED = "c";
  -
  +    private static final String ROOT_NODE_ID = "0";
  +    private final static String SEPARATOR = String.valueOf(NamingContainer.SEPARATOR_CHAR);
  +    
       private static final int NOTHING = 0;
       private static final int CHILDREN = 1;
       private static final int EXPANDED = 2;
  @@ -120,8 +122,7 @@
           }
           else
           {
  -            nodeId = (String)context.getExternalContext().getRequestParameterMap().get(tree.getId()
+
  -                NamingContainer.SEPARATOR_CHAR + NAV_COMMAND);
  +            nodeId = (String)context.getExternalContext().getRequestParameterMap().get(tree.getId()
+ SEPARATOR + NAV_COMMAND);
   
               if (nodeId == null || nodeId.equals(""))
               {
  @@ -150,6 +151,9 @@
        */
       public void encodeChildren(FacesContext context, UIComponent component) throws IOException
       {
  +        HtmlTree tree = (HtmlTree)component;
  +        boolean showRootNode = getBoolean(tree, JSFAttr.SHOW_ROOT_NODE, true);
  +        
           // write javascript functions
           encodeJavascript(context);
   
  @@ -158,7 +162,7 @@
   
           if (!component.isRendered()) return;
   
  -        if (((HtmlTree)component).getValue() == null) return;
  +        if (tree.getValue() == null) return;
   
           ResponseWriter out = context.getResponseWriter();
           String clientId = null;
  @@ -177,9 +181,25 @@
               out.writeAttribute("id", clientId, "id");
           }
   
  -        encodeNodes(context, out, (HtmlTree)component, null, 0);
  +        if (showRootNode)
  +        {
  +            // encode the tree (starting with the root node)
  +            encodeTree(context, out, tree, null, 0);
  +        }
  +        else
  +        {
  +            tree.setNodeId("0");
  +            TreeNode rootNode = tree.getNode();
  +            List rootChildren = rootNode.getChildren();
  +            int kidId = 0;
  +
  +            for (int i = 0; i < rootChildren.size(); i++) 
  +            {
  +                encodeTree(context, out, tree, ROOT_NODE_ID, kidId++);
  +            }
  +        }
   
  -        ((HtmlTree)component).setNodeId(null);
  +        tree.setNodeId(null);
   
           if (isOuterSpanUsed)
           {
  @@ -187,13 +207,90 @@
           }
       }
   
  -    private void encodeNodes(FacesContext context, ResponseWriter out, HtmlTree tree, String
parentId, int childCount)
  +    /**
  +     * Encodes the tree and its children.
  +     * 
  +     * @param context FacesContext
  +     * @param out ResponseWriter
  +     * @param tree HtmlTree
  +     * @param parentId The parent's node id (where parent is the parent of the node we
are about to render.)
  +     * @param childCount If this node is a child of another node, the count indicates which
child number it is 
  +     *  (used to construct the id of the next node to render.)
  +     * @throws IOException
  +     */
  +    private void encodeTree(FacesContext context, ResponseWriter out, HtmlTree tree, String
parentId, int childCount)
           throws IOException
       {
  -        String nodeId = (parentId != null) ? parentId + NamingContainer.SEPARATOR_CHAR
+ childCount : "0";
  +        boolean clientSideToggle = getBoolean(tree, JSFAttr.CLIENT_SIDE_TOGGLE, true);
  +        
  +        String nodeId = (parentId != null) ? parentId + NamingContainer.SEPARATOR_CHAR
+ childCount : ROOT_NODE_ID;
           String spanId = TOGGLE_SPAN + nodeId;
   
  +        tree.setNodeId(nodeId);
  +        TreeNode node = tree.getNode();       
  +        
  +        // encode the current node
  +        encodeCurrentNode(context, out, tree);
  +        
  +        // only encode the children if clientSideToggle is true or if this node is expanded
(regardless of clientSideToggle)
  +        if (clientSideToggle == true || tree.isNodeExpanded())
  +        {
  +            int nodeLevel = ((Integer)tree.getAttributes().get(NODE_LEVEL)).intValue();
  +            nodeLevel++;
  +            tree.getAttributes().put(NODE_LEVEL, new Integer(nodeLevel));
  +
  +            int kidId = 0;
  +            String currId = tree.getNodeId();
  +            List children = node.getChildren();
  +
  +            // if client side toggling is on, add a span to be used for displaying/hiding
children
  +            if (clientSideToggle)
  +            {
  +                out.startElement(HTML.SPAN_ELEM, tree);
  +                out.writeAttribute(HTML.ID_ATTR, spanId, null);
  +
  +                if (tree.isNodeExpanded())
  +                {
  +                    out.writeAttribute(HTML.STYLE_ATTR, "display:block", null);
  +                }
  +                else
  +                {
  +                    out.writeAttribute(HTML.STYLE_ATTR, "display:none", null);
  +                }
  +            }
  +
  +            for (int i = 0; i < children.size(); i++)
  +            {
  +                encodeTree(context, out, tree, currId, kidId++);
  +            }
  +
  +            if (clientSideToggle)
  +            {
  +                out.endElement(HTML.SPAN_ELEM);
  +            }
  +
  +            nodeLevel = ((Integer)tree.getAttributes().get(NODE_LEVEL)).intValue();
  +            nodeLevel--;
  +            tree.getAttributes().put(NODE_LEVEL, new Integer(nodeLevel));
  +        }
  +    }
  +
  +    /**
  +     * Encodes the current node.  It is protected so that custom {@link Renderer}s can
extend it.  That might be useful 
  +     * if you would like to render additional per node information besides the tree node.
 
  +     * 
  +     * @param context FacesContext
  +     * @param out ResponseWriter
  +     * @param tree HtmlTree
  +     * @throws IOException
  +     */
  +    protected void encodeCurrentNode(FacesContext context, ResponseWriter out, HtmlTree
tree)
  +        throws IOException    
  +    {
  +        TreeNode node = tree.getNode();
  +        
           // set configurable values
  +        boolean showRootNode = getBoolean(tree, JSFAttr.SHOW_ROOT_NODE, true);
           boolean showNav = getBoolean(tree, JSFAttr.SHOW_NAV, true);
           boolean showLines = getBoolean(tree, JSFAttr.SHOW_LINES, true);
           boolean clientSideToggle = getBoolean(tree, JSFAttr.CLIENT_SIDE_TOGGLE, true);
  @@ -204,8 +301,6 @@
               showNav = true;
           }
   
  -        tree.setNodeId(nodeId);
  -        TreeNode node = tree.getNode();
           UIComponent nodeTypeFacet = tree.getFacet(node.getType());
           UIComponent nodeImgFacet = null;
   
  @@ -227,9 +322,12 @@
   
           // render node padding
           String[] pathInfo = tree.getPathInformation(tree.getNodeId());
  -        for (int i=0;i<pathInfo.length-1;i++)
  +        int paddingLevel = pathInfo.length - 1;
  +        
  +        for (int i = (showRootNode ? 0 : 1); i < paddingLevel; i++)
           {
  -            String lineSrc = (!tree.isLastChild(pathInfo[i]) && showLines)
  +            boolean lastChild = tree.isLastChild((String)pathInfo[i]);
  +            String lineSrc = (!lastChild && showLines)
                                ? AddResource.getResourceMappedPath(HtmlTreeRenderer.class,
"images/line-trunk.gif", context)
                                : AddResource.getResourceMappedPath(HtmlTreeRenderer.class,
"images/spacer.gif", context);
   
  @@ -246,239 +344,220 @@
               out.endElement(HTML.TD_ELEM);
           }
   
  -        // render navigation
           if (showNav)
           {
  -            String navSrc = null;
  -            String altSrc = null;
  -
  -            int bitMask = NOTHING;
  -            bitMask += (node.getChildCount()>0) ? CHILDREN : NOTHING;
  -            bitMask += (tree.isNodeExpanded()) ? EXPANDED : NOTHING;
  -            bitMask += (tree.isLastChild(tree.getNodeId())) ? LAST : NOTHING;
  -            bitMask += (showLines) ? LINES : NOTHING;
  -
  -            switch (bitMask)
  -            {
  -                case (NOTHING):
  +            nodeImgFacet = encodeNavigation(context, out, tree);
  +        }
   
  -                case (LAST):
  -                    navSrc = "images/spacer.gif";
  -                    break;
  +        // render node
  +        out.startElement(HTML.TD_ELEM, tree);
  +        if (nodeImgFacet != null)
  +        {
  +            encodeRecursive(context, nodeImgFacet);
  +        }
  +        encodeRecursive(context, nodeTypeFacet);
  +        out.endElement(HTML.TD_ELEM);
   
  -                case (LINES):
  -                    navSrc = "images/line-middle.gif";
  -                    break;
  +        // end node table
  +        out.endElement(HTML.TR_ELEM);
  +        out.endElement(HTML.TABLE_ELEM);
  +        HtmlRendererUtils.writePrettyLineSeparator(context);
  +    }
   
  -                case (LINES + LAST):
  -                    navSrc = "images/line-last.gif";
  -                    break;
  +    /**
  +     * Handles the encoding related to the navigation functionality.  
  +     * 
  +     * @param context FacesContext
  +     * @param out ResponseWriter
  +     * @param tree HtmlTree
  +     * @return The additional navigation image to display inside the node (if any).  Only
used with client-side toggle.
  +     * @throws IOException
  +     */    
  +    private UIComponent encodeNavigation(FacesContext context, ResponseWriter out, HtmlTree
tree)
  +        throws IOException
  +    {
  +        TreeNode node = tree.getNode();
  +        String nodeId = tree.getNodeId();        
  +        String spanId = TOGGLE_SPAN + nodeId;
  +        boolean showLines = getBoolean(tree, JSFAttr.SHOW_LINES, true);
  +        boolean clientSideToggle = getBoolean(tree, JSFAttr.CLIENT_SIDE_TOGGLE, true);
  +        UIComponent nodeTypeFacet = tree.getFacet(node.getType());
  +        String navSrc = null;
  +        String altSrc = null;
  +        UIComponent nodeImgFacet = null;
  +        
  +        int bitMask = NOTHING;
  +        bitMask += (node.getChildCount()>0) ? CHILDREN : NOTHING;
  +        bitMask += (tree.isNodeExpanded()) ? EXPANDED : NOTHING;
  +        bitMask += (tree.isLastChild(tree.getNodeId())) ? LAST : NOTHING;
  +        bitMask += (showLines) ? LINES : NOTHING;
   
  -                case (CHILDREN):
  +        switch (bitMask)
  +        {
  +            case (NOTHING):
   
  -                case (CHILDREN + LAST):
  -                    navSrc = "images/nav-plus.gif";
  -                    altSrc = "images/nav-minus.gif";
  -                    break;
  +            case (LAST):
  +                navSrc = "images/spacer.gif";
  +                break;
   
  -                case (CHILDREN + LINES):
  +            case (LINES):
  +                navSrc = "images/line-middle.gif";
  +                break;
   
  -                    navSrc = "images/nav-plus-line-middle.gif";
  -                    altSrc = "images/nav-minus-line-middle.gif";
  -                    break;
  +            case (LINES + LAST):
  +                navSrc = "images/line-last.gif";
  +                break;
   
  -                case (CHILDREN + LINES + LAST):
  +            case (CHILDREN):
   
  -                    navSrc = "images/nav-plus-line-last.gif";
  -                    altSrc = "images/nav-minus-line-last.gif";
  -                    break;
  +            case (CHILDREN + LAST):
  +                navSrc = "images/nav-plus.gif";
  +                altSrc = "images/nav-minus.gif";
  +                break;
   
  -                case (CHILDREN + EXPANDED):
  +            case (CHILDREN + LINES):
   
  -                case (CHILDREN + EXPANDED + LAST):
  -                    navSrc = "images/nav-minus.gif";
  -                    altSrc = "images/nav-plus.gif";
  -                    break;
  +                navSrc = "images/nav-plus-line-middle.gif";
  +                altSrc = "images/nav-minus-line-middle.gif";
  +                break;
   
  -                case (CHILDREN + EXPANDED + LINES):
  -                    navSrc = "images/nav-minus-line-middle.gif";
  -                    altSrc = "images/nav-plus-line-middle.gif";
  -                    break;
  +            case (CHILDREN + LINES + LAST):
   
  -                case (CHILDREN + EXPANDED + LINES + LAST):
  -                    navSrc = "images/nav-minus-line-last.gif";
  -                    altSrc = "images/nav-plus-line-last.gif";
  -                    break;
  +                navSrc = "images/nav-plus-line-last.gif";
  +                altSrc = "images/nav-minus-line-last.gif";
  +                break;
   
  -                default:
  -                    throw new IllegalArgumentException("Invalid bit mask of " + bitMask);
  -            }
  +            case (CHILDREN + EXPANDED):
   
  -            // adjust navSrc and altSrc so that the images can be retrieved using the extensions
filter
  -            String navSrcUrl = AddResource.getResourceMappedPath(HtmlTreeRenderer.class,
navSrc, null);
  -            navSrc = AddResource.getResourceMappedPath(HtmlTreeRenderer.class, navSrc,
context);
  -            altSrc = AddResource.getResourceMappedPath(HtmlTreeRenderer.class, altSrc,
context);
  +            case (CHILDREN + EXPANDED + LAST):
  +                navSrc = "images/nav-minus.gif";
  +                altSrc = "images/nav-plus.gif";
  +                break;
   
  -            // render nav cell
  -            out.startElement(HTML.TD_ELEM, tree);
  -            out.writeAttribute(HTML.WIDTH_ATTR, "19", null);
  -            out.writeAttribute(HTML.HEIGHT_ATTR, "100%", null);
  -            out.writeAttribute("valign", "top", null);
  +            case (CHILDREN + EXPANDED + LINES):
  +                navSrc = "images/nav-minus-line-middle.gif";
  +                altSrc = "images/nav-plus-line-middle.gif";
  +                break;
   
  -            if ((bitMask & LINES)!=0 && (bitMask & LAST)==0)
  -            {
  -                out.writeURIAttribute("background",
  -                        AddResource.getResourceMappedPath(HtmlTreeRenderer.class, "images/line-trunk.gif",
context),
  -                        null);
  -            }
  -
  -            // add the appropriate image for the nav control
  -            UIGraphic image = new UIGraphic();
  -            image.setUrl(navSrcUrl);
  -            Map imageAttrs = image.getAttributes();
  -            imageAttrs.put(HTML.WIDTH_ATTR, "19");
  -            imageAttrs.put(HTML.HEIGHT_ATTR, "18");
  -            imageAttrs.put(HTML.BORDER_ATTR, "0");
  +            case (CHILDREN + EXPANDED + LINES + LAST):
  +                navSrc = "images/nav-minus-line-last.gif";
  +                altSrc = "images/nav-plus-line-last.gif";
  +                break;
   
  -            if (clientSideToggle)
  -            {
  -                /**
  -                 * With client side toggle, user has the option to specify open/closed
images for the node (in addition to
  -                 * the navigtion ones provided by the component.)
  -                 */
  -                String expandImgSrc = "";
  -                String collapseImgSrc = "";
  -                String nodeImageId = "";
  +            default:
  +                throw new IllegalArgumentException("Invalid bit mask of " + bitMask);
  +        }
   
  -                UIComponent expandFacet = nodeTypeFacet.getFacet("expand");
  -                if (expandFacet != null)
  -                {
  -                    UIGraphic expandImg = (UIGraphic)expandFacet;
  -                    expandImgSrc = expandImg.getUrl();
  -                    if (expandImg.isRendered())
  -                    {
  -                        expandImg.setId(null);
  -                        nodeImageId = expandImg.getClientId(context);
  -                        nodeImgFacet = expandFacet;
  -                    }
  -                }
  +        // adjust navSrc and altSrc so that the images can be retrieved using the extensions
filter
  +        String navSrcUrl = AddResource.getResourceMappedPath(HtmlTreeRenderer.class, navSrc,
null);
  +        navSrc = AddResource.getResourceMappedPath(HtmlTreeRenderer.class, navSrc, context);
  +        altSrc = AddResource.getResourceMappedPath(HtmlTreeRenderer.class, altSrc, context);
   
  -                UIComponent collapseFacet = nodeTypeFacet.getFacet("collapse");
  -                if (collapseFacet != null)
  -                {
  -                    UIGraphic collapseImg = (UIGraphic)collapseFacet;
  -                    collapseImgSrc = collapseImg.getUrl();
  -                    if (collapseImg.isRendered())
  -                    {
  -                        collapseImg.setId(null);
  -                        nodeImageId = collapseImg.getClientId(context);
  -                        nodeImgFacet = collapseFacet;
  -                    }
  -                }
  +        // render nav cell
  +        out.startElement(HTML.TD_ELEM, tree);
  +        out.writeAttribute(HTML.WIDTH_ATTR, "19", null);
  +        out.writeAttribute(HTML.HEIGHT_ATTR, "100%", null);
  +        out.writeAttribute("valign", "top", null);
  +
  +        if ((bitMask & LINES)!=0 && (bitMask & LAST)==0)
  +        {
  +            out.writeURIAttribute("background",
  +                    AddResource.getResourceMappedPath(HtmlTreeRenderer.class, "images/line-trunk.gif",
context),
  +                    null);
  +        }
  +
  +        // add the appropriate image for the nav control
  +        UIGraphic image = new UIGraphic();
  +        image.setUrl(navSrcUrl);
  +        Map imageAttrs = image.getAttributes();
  +        imageAttrs.put(HTML.WIDTH_ATTR, "19");
  +        imageAttrs.put(HTML.HEIGHT_ATTR, "18");
  +        imageAttrs.put(HTML.BORDER_ATTR, "0");
   
  -                if (node.getChildCount() > 0)
  +        if (clientSideToggle)
  +        {
  +            /**
  +             * With client side toggle, user has the option to specify open/closed images
for the node (in addition to
  +             * the navigtion ones provided by the component.)
  +             */
  +            String expandImgSrc = "";
  +            String collapseImgSrc = "";
  +            String nodeImageId = "";
  +
  +            UIComponent expandFacet = nodeTypeFacet.getFacet("expand");
  +            if (expandFacet != null)
  +            {
  +                UIGraphic expandImg = (UIGraphic)expandFacet;
  +                expandImgSrc = expandImg.getUrl();
  +                if (expandImg.isRendered())
                   {
  -                    String onClick = new StringBuffer()
  -                        .append("treeNavClick('")
  -                        .append(spanId)
  -                        .append("', '")
  -                        .append(image.getClientId(context))
  -                        .append("', '")
  -                        .append(navSrc)
  -                        .append("', '")
  -                        .append(altSrc)
  -                        .append("', '")
  -                        .append(nodeImageId)
  -                        .append("', '")
  -                        .append(expandImgSrc)
  -                        .append("', '")
  -                        .append(collapseImgSrc)
  -                        .append("', '")
  -                        .append(tree.getId())
  -                        .append("', '")
  -                        .append(nodeId)
  -                        .append("');")
  -                        .toString();
  -
  -                    imageAttrs.put(HTML.ONCLICK_ATTR, onClick);
  -                    imageAttrs.put(HTML.STYLE_ATTR, "cursor:hand;cursor:pointer");
  +                    expandImg.setId(null);
  +                    nodeImageId = expandImg.getClientId(context);
  +                    nodeImgFacet = expandFacet;
                   }
  -                encodeRecursive(context, image);
               }
  -            else
  -            {
  -                // set up the expand control and remove whatever children (if any) this
control had previously
  -                UICommand expandControl = tree.getExpandControl();
  -                expandControl.getChildren().clear();
  -
  -                UIParameter param = new UIParameter();
  -                param.setName(tree.getId() + NamingContainer.SEPARATOR_CHAR + NAV_COMMAND);
  -                param.setValue(tree.getNodeId());
  -                expandControl.getChildren().add(param);
  -                expandControl.getChildren().add(image);
  -
  -                tree.getChildren().add(expandControl);
  -
  -                encodeRecursive(context, expandControl);
  -            }
  -            out.endElement(HTML.TD_ELEM);
  -        }
  -
  -        // render node
  -        out.startElement(HTML.TD_ELEM, tree);
  -        if (nodeImgFacet != null)
  -        {
  -            encodeRecursive(context, nodeImgFacet);
  -        }
  -        encodeRecursive(context, nodeTypeFacet);
  -        out.endElement(HTML.TD_ELEM);
  -
  -        // end node table
  -        out.endElement(HTML.TR_ELEM);
  -        out.endElement(HTML.TABLE_ELEM);
  -        HtmlRendererUtils.writePrettyLineSeparator(context);
  -
  -        // only encode the children if clientSideToggle is true or if this node is expanded
(regardless of clientSideToggle)
  -        if (clientSideToggle == true || tree.isNodeExpanded())
  -        {
  -            int nodeLevel = ((Integer)tree.getAttributes().get(NODE_LEVEL)).intValue();
  -            nodeLevel++;
  -            tree.getAttributes().put(NODE_LEVEL, new Integer(nodeLevel));
   
  -            int kidId = 0;
  -            String currId = tree.getNodeId();
  -            List children = node.getChildren();
  -
  -            // if client side toggling is on, add a span to be used for displaying/hiding
children
  -            if (clientSideToggle)
  +            UIComponent collapseFacet = nodeTypeFacet.getFacet("collapse");
  +            if (collapseFacet != null)
               {
  -                out.startElement(HTML.SPAN_ELEM, tree);
  -                out.writeAttribute(HTML.ID_ATTR, spanId, null);
  -
  -                if (tree.isNodeExpanded())
  +                UIGraphic collapseImg = (UIGraphic)collapseFacet;
  +                collapseImgSrc = collapseImg.getUrl();
  +                if (collapseImg.isRendered())
                   {
  -                    out.writeAttribute(HTML.STYLE_ATTR, "display:block", null);
  -                }
  -                else
  -                {
  -                    out.writeAttribute(HTML.STYLE_ATTR, "display:none", null);
  +                    collapseImg.setId(null);
  +                    nodeImageId = collapseImg.getClientId(context);
  +                    nodeImgFacet = collapseFacet;
                   }
               }
   
  -            for (int i = 0; i < children.size(); i++)
  +            if (node.getChildCount() > 0)
               {
  -                encodeNodes(context, out, tree, currId, kidId++);
  -            }
  +                String onClick = new StringBuffer()
  +                    .append("treeNavClick('")
  +                    .append(spanId)
  +                    .append("', '")
  +                    .append(image.getClientId(context))
  +                    .append("', '")
  +                    .append(navSrc)
  +                    .append("', '")
  +                    .append(altSrc)
  +                    .append("', '")
  +                    .append(nodeImageId)
  +                    .append("', '")
  +                    .append(expandImgSrc)
  +                    .append("', '")
  +                    .append(collapseImgSrc)
  +                    .append("', '")
  +                    .append(tree.getId())
  +                    .append("', '")
  +                    .append(nodeId)
  +                    .append("');")
  +                    .toString();
   
  -            if (clientSideToggle)
  -            {
  -                out.endElement(HTML.SPAN_ELEM);
  +                imageAttrs.put(HTML.ONCLICK_ATTR, onClick);
  +                imageAttrs.put(HTML.STYLE_ATTR, "cursor:hand;cursor:pointer");
               }
  +            encodeRecursive(context, image);
  +        }
  +        else
  +        {
  +            // set up the expand control and remove whatever children (if any) this control
had previously
  +            UICommand expandControl = tree.getExpandControl();
  +            expandControl.getChildren().clear();
  +
  +            UIParameter param = new UIParameter();
  +            param.setName(tree.getId() + NamingContainer.SEPARATOR_CHAR + NAV_COMMAND);
  +            param.setValue(tree.getNodeId());
  +            expandControl.getChildren().add(param);
  +            expandControl.getChildren().add(image);
   
  -            nodeLevel = ((Integer)tree.getAttributes().get(NODE_LEVEL)).intValue();
  -            nodeLevel--;
  -            tree.getAttributes().put(NODE_LEVEL, new Integer(nodeLevel));
  +            tree.getChildren().add(expandControl);
  +
  +            encodeRecursive(context, expandControl);
           }
  +        out.endElement(HTML.TD_ELEM);
  +        
  +        return nodeImgFacet;
       }
   
       private void encodeRecursive(FacesContext context, UIComponent component) throws IOException
  
  
  
  1.6       +10 -2     incubator-myfaces/src/components/org/apache/myfaces/custom/tree2/TreeTag.java
  
  Index: TreeTag.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/tree2/TreeTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TreeTag.java	21 Feb 2005 18:49:59 -0000	1.5
  +++ TreeTag.java	7 Mar 2005 16:17:20 -0000	1.6
  @@ -36,6 +36,7 @@
       private String _showLines;
       private String _showNav;
       private String _clientSideToggle;
  +    private String _showRootNode;
   
       public void release()
       {
  @@ -47,6 +48,7 @@
           _showLines = null;
           _showNav = null;
           _clientSideToggle = null;
  +        _showRootNode = null;
       }
   
       public String getComponentType()
  @@ -91,6 +93,11 @@
       {
           _clientSideToggle = clientSideToggle;
       }
  +    
  +    public void setShowRootNode(String showRootNode)
  +    {
  +        _showRootNode = showRootNode;
  +    }
   
       protected void setProperties(UIComponent component)
       {
  @@ -117,5 +124,6 @@
           setBooleanProperty(component, JSFAttr.SHOW_NAV, _showNav);
           setBooleanProperty(component, JSFAttr.SHOW_LINES, _showLines);
           setBooleanProperty(component, JSFAttr.CLIENT_SIDE_TOGGLE, _clientSideToggle);
  +        setBooleanProperty(component, JSFAttr.SHOW_ROOT_NODE, _showRootNode);
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.173     +6 -0      incubator-myfaces/tlds/myfaces_ext.tld
  
  Index: myfaces_ext.tld
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/tlds/myfaces_ext.tld,v
  retrieving revision 1.172
  retrieving revision 1.173
  diff -u -r1.172 -r1.173
  --- myfaces_ext.tld	7 Mar 2005 09:06:51 -0000	1.172
  +++ myfaces_ext.tld	7 Mar 2005 16:17:20 -0000	1.173
  @@ -1772,6 +1772,12 @@
               <rtexprvalue>false</rtexprvalue>
               <description>Perform client-side toggling of expand/collapse state via
javascript (default is true.)</description>
           </attribute>
  +        <attribute>
  +            <name>showRootNode</name>
  +            <required>false</required>
  +            <rtexprvalue>false</rtexprvalue>
  +            <description>Include the root node when rendering the tree (default is
true.)</description>
  +        </attribute>        
           &alt_location_attributes;
       </tag>
   
  
  
  

Mime
View raw message