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/webapps/examples/web/images line-last.gif line-middle.gif line-trunk.gif spacer.gif
Date Thu, 10 Mar 2005 15:59:06 GMT
matzew      2005/03/10 07:59:06

  Modified:    src/components/org/apache/myfaces/custom/tree2
                        HtmlTreeRenderer.java
  Removed:     webapps/examples/web/images line-last.gif line-middle.gif
                        line-trunk.gif spacer.gif
  Log:
  Patch for tree2 form Sean Schofield
  
  Revision  Changes    Path
  1.12      +96 -53    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- HtmlTreeRenderer.java	10 Mar 2005 09:24:19 -0000	1.11
  +++ HtmlTreeRenderer.java	10 Mar 2005 15:59:05 -0000	1.12
  @@ -52,7 +52,7 @@
   {
       protected static final String TOGGLE_SPAN = "org.apache.myfaces.tree.TOGGLE_SPAN";
       protected static final String ROOT_NODE_ID = "0";
  -    
  +
       private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.tree.JAVASCRIPT_ENCODED";
       private static final String NAV_COMMAND = "org.apache.myfaces.tree.NAV_COMMAND";
       private static final String ENCODING = "UTF-8";
  @@ -61,7 +61,7 @@
       private static final String NODE_STATE_EXPANDED = "x";
       private static final String NODE_STATE_CLOSED = "c";
       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;
  @@ -138,7 +138,7 @@
       public void encodeBegin(FacesContext context, UIComponent component) throws IOException
       {
           // write javascript functions
  -        encodeJavascript(context);
  +        encodeJavascript(context, component);
       }
   
       /**
  @@ -188,7 +188,7 @@
               List rootChildren = rootNode.getChildren();
               int kidId = 0;
   
  -            for (int i = 0; i < rootChildren.size(); i++) 
  +            for (int i = 0; i < rootChildren.size(); i++)
               {
                   encodeTree(context, out, tree, ROOT_NODE_ID, kidId++);
               }
  @@ -204,12 +204,12 @@
   
       /**
        * 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 
  +     * @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
        */
  @@ -217,19 +217,19 @@
           throws IOException
       {
           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();       
  -        
  +        TreeNode node = tree.getNode();
  +
           // encode the current node
           HtmlRendererUtils.writePrettyLineSeparator(context);
           beforeNodeEncode(context, out, tree);
           encodeCurrentNode(context, out, tree);
           afterNodeEncode(context, out);
  -        
  +
           // only encode the children if clientSideToggle is true or if this node is expanded
(regardless of clientSideToggle)
           if (clientSideToggle == true || tree.isNodeExpanded())
           {
  @@ -266,19 +266,19 @@
       }
   
       /**
  -     * 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.
 
  -     * 
  +     * 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    
  +        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);
  @@ -302,13 +302,13 @@
           // render node padding
           String[] pathInfo = tree.getPathInformation(tree.getNodeId());
           int paddingLevel = pathInfo.length - 1;
  -        
  +
           for (int i = (showRootNode ? 0 : 1); i < paddingLevel; i++)
           {
               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);
  +                             ? getImageSrc(context, tree, "line-trunk.gif")
  +                             : getImageSrc(context, tree, "spacer.gif");
   
               out.startElement(HTML.TD_ELEM, tree);
               out.writeAttribute(HTML.WIDTH_ATTR, "19", null);
  @@ -347,28 +347,28 @@
           out.writeAttribute(HTML.BORDER_ATTR, "0", null);
           out.startElement(HTML.TR_ELEM, null);
       }
  -    
  +
       protected void afterNodeEncode(FacesContext context, ResponseWriter out)
           throws IOException
       {
           out.endElement(HTML.TR_ELEM);
           out.endElement(HTML.TABLE_ELEM);
  -    }    
  -    
  +    }
  +
       /**
  -     * Handles the encoding related to the navigation functionality.  
  -     * 
  +     * 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 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);
  @@ -376,7 +376,7 @@
           String navSrc = null;
           String altSrc = null;
           UIComponent nodeImgFacet = null;
  -        
  +
           int bitMask = NOTHING;
           bitMask += (node.getChildCount()>0) ? CHILDREN : NOTHING;
           bitMask += (tree.isNodeExpanded()) ? EXPANDED : NOTHING;
  @@ -388,51 +388,51 @@
               case (NOTHING):
   
               case (LAST):
  -                navSrc = "images/spacer.gif";
  +                navSrc = "spacer.gif";
                   break;
   
               case (LINES):
  -                navSrc = "images/line-middle.gif";
  +                navSrc = "line-middle.gif";
                   break;
   
               case (LINES + LAST):
  -                navSrc = "images/line-last.gif";
  +                navSrc = "line-last.gif";
                   break;
   
               case (CHILDREN):
   
               case (CHILDREN + LAST):
  -                navSrc = "images/nav-plus.gif";
  -                altSrc = "images/nav-minus.gif";
  +                navSrc = "nav-plus.gif";
  +                altSrc = "nav-minus.gif";
                   break;
   
               case (CHILDREN + LINES):
   
  -                navSrc = "images/nav-plus-line-middle.gif";
  -                altSrc = "images/nav-minus-line-middle.gif";
  +                navSrc = "nav-plus-line-middle.gif";
  +                altSrc = "nav-minus-line-middle.gif";
                   break;
   
               case (CHILDREN + LINES + LAST):
   
  -                navSrc = "images/nav-plus-line-last.gif";
  -                altSrc = "images/nav-minus-line-last.gif";
  +                navSrc = "nav-plus-line-last.gif";
  +                altSrc = "nav-minus-line-last.gif";
                   break;
   
               case (CHILDREN + EXPANDED):
   
               case (CHILDREN + EXPANDED + LAST):
  -                navSrc = "images/nav-minus.gif";
  -                altSrc = "images/nav-plus.gif";
  +                navSrc = "nav-minus.gif";
  +                altSrc = "nav-plus.gif";
                   break;
   
               case (CHILDREN + EXPANDED + LINES):
  -                navSrc = "images/nav-minus-line-middle.gif";
  -                altSrc = "images/nav-plus-line-middle.gif";
  +                navSrc = "nav-minus-line-middle.gif";
  +                altSrc = "nav-plus-line-middle.gif";
                   break;
   
               case (CHILDREN + EXPANDED + LINES + LAST):
  -                navSrc = "images/nav-minus-line-last.gif";
  -                altSrc = "images/nav-plus-line-last.gif";
  +                navSrc = "nav-minus-line-last.gif";
  +                altSrc = "nav-plus-line-last.gif";
                   break;
   
               default:
  @@ -440,9 +440,9 @@
           }
   
           // 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);
  +        String navSrcUrl = getImageSrc(null, tree, navSrc);
  +        navSrc = getImageSrc(context, tree, navSrc);
  +        altSrc = getImageSrc(context, tree, altSrc);
   
           // render nav cell
           out.startElement(HTML.TD_ELEM, tree);
  @@ -452,9 +452,7 @@
   
           if ((bitMask & LINES)!=0 && (bitMask & LAST)==0)
           {
  -            out.writeURIAttribute("background",
  -                    AddResource.getResourceMappedPath(HtmlTreeRenderer.class, "images/line-trunk.gif",
context),
  -                    null);
  +            out.writeURIAttribute("background", getImageSrc(context, tree, "line-trunk.gif"),
null);
           }
   
           // add the appropriate image for the nav control
  @@ -547,7 +545,7 @@
               encodeRecursive(context, expandControl);
           }
           out.endElement(HTML.TD_ELEM);
  -        
  +
           return nodeImgFacet;
       }
   
  @@ -577,12 +575,14 @@
       }
   
       /**
  -     * Encodes any stand-alone javascript functions that are needed.
  +     * Encodes any stand-alone javascript functions that are needed.  Uses either the extension
filter, or a
  +     * user-supplied location for the javascript files.
        *
        * @param context FacesContext
  +     * @param component UIComponent
        * @throws IOException
        */
  -    private void encodeJavascript(FacesContext context) throws IOException
  +    private void encodeJavascript(FacesContext context, UIComponent component) throws IOException
       {
           // check to see if javascript has already been written (which could happen if more
than one tree on the same page)
           if (context.getExternalContext().getRequestMap().containsKey(JAVASCRIPT_ENCODED))
  @@ -591,13 +591,56 @@
           }
   
           // render javascript function for client-side toggle (it won't be used if user
has opted for server-side toggle)
  -        AddResource.addJavaScriptHere(HtmlTreeRenderer.class, "javascript/tree.js", context);
  -        AddResource.addJavaScriptHere(HtmlTreeRenderer.class, "javascript/cookielib.js",
context);
  +        ResponseWriter out = context.getResponseWriter();
  +        String javascriptLocation = (String)component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
  +        if (javascriptLocation == null)
  +        {
  +            AddResource.addJavaScriptHere(HtmlTreeRenderer.class, "javascript/tree.js",
context);
  +            AddResource.addJavaScriptHere(HtmlTreeRenderer.class, "javascript/cookielib.js",
context);
  +        }
  +        else
  +        {
  +            out.startElement(HTML.SCRIPT_ELEM, null);
  +            out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
  +            out.writeAttribute(HTML.SRC_ATTR,
  +                               javascriptLocation + "/tree.js", null);
  +            out.endElement(HTML.SCRIPT_ELEM);
  +
  +            out.startElement(HTML.SCRIPT_ELEM, null);
  +            out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
  +            out.writeAttribute(HTML.SRC_ATTR,
  +                               javascriptLocation + "/cookielib.js", null);
  +            out.endElement(HTML.SCRIPT_ELEM);
  +        }
   
           context.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
       }
   
       /**
  +     * Get the appropriate image src location.  Uses the extension filter mechanism for
images if no image
  +     * location has been specified.
  +     *
  +     * @param context The {@link FacesContex}.  NOTE: If <code>null</code>
then context path information
  +     *    will not be used with extensions filter (assuming no imageLocation specified.)
  +     * @param component UIComponent
  +     * @param imageName The name of the image file to use.
  +     * @return The image src information.
  +     */
  +    private String getImageSrc(FacesContext context, UIComponent component, String imageName)
  +    {
  +        String imageLocation = (String)component.getAttributes().get(JSFAttr.IMAGE_LOCATION);
  +        if (imageLocation == null)
  +        {
  +            return AddResource.getResourceMappedPath(HtmlTreeRenderer.class,
  +                "images/" + imageName, context);
  +        }
  +        else
  +        {
  +            return imageLocation + "/" + imageName;
  +        }
  +    }
  +
  +    /**
        * Helper method for getting the boolean value of an attribute.  If the attribute is
not specified,
        * then return the default value.
        *
  
  
  

Mime
View raw message