You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/03/01 21:53:40 UTC

svn commit: r749094 - in /incubator/click/trunk/click: documentation/docs/ extras/src/org/apache/click/extras/tree/

Author: sabob
Date: Sun Mar  1 20:53:39 2009
New Revision: 749094

URL: http://svn.apache.org/viewvc?rev=749094&view=rev
Log:
added custom TreeNode icon. CLK-494

Modified:
    incubator/click/trunk/click/documentation/docs/roadmap-changes.html
    incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java
    incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/TreeNode.java
    incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.css
    incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.js

Modified: incubator/click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/docs/roadmap-changes.html?rev=749094&r1=749093&r2=749094&view=diff
==============================================================================
--- incubator/click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ incubator/click/trunk/click/documentation/docs/roadmap-changes.html Sun Mar  1 20:53:39 2009
@@ -82,6 +82,12 @@
     </div>
     <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
       <li class="change">
+          Added ability to specify a custom TreeNode icon through the new method
+          TreeNode.<a href="extras-api/org/apache/click/extras/tree/TreeNode.html#setIcon(java.lang.String)">setIcon(String)</a>.
+          This issue was raised and fixed by Tim Hooper
+          [<a target='_blank' href="https://issues.apache.org/click/browse/CLK-494">494</a>].
+      </li>
+      <li class="change">
           Improved PickList methods <a href="extras-api/org/apache/click/extras/control/PickList.html#getValueObject()">getValueObject()</a>
           and <a href="extras-api/org/apache/click/extras/control/PickList.html#setValueObject(java.lang.Object)">setValueObject(Object)</a>
           to delegate to <a href="extras-api/org/apache/click/extras/control/PickList.html#getSelectedValues()">getSelectedValues()</a>

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java?rev=749094&r1=749093&r2=749094&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java Sun Mar  1 20:53:39 2009
@@ -1134,22 +1134,31 @@
      * @param treeNode treeNode to render
      */
     protected void renderIcon(HtmlStringBuffer buffer, TreeNode treeNode) {
-        //render the icon to display
-        buffer.elementStart("span");
-        buffer.appendAttribute("class", getIconClass(treeNode));
+        if (treeNode.getIcon() == null) {
 
-        if (isJavascriptEnabled()) {
-            //An id is needed on the element to do quick lookup using javascript
-            //document.getElementById(id)
-            javascriptHandler.getJavascriptRenderer().renderIcon(buffer);
-        }
-        buffer.append(">");
+            //render the icon to display
+            buffer.elementStart("span");
+            buffer.appendAttribute("class", getIconClass(treeNode));
+
+            if (isJavascriptEnabled()) {
+                //An id is needed on the element to do quick lookup using javascript
+                //document.getElementById(id)
+                javascriptHandler.getJavascriptRenderer().renderIcon(buffer);
+            }
+            buffer.append(">");
+
+            //TODO IE HACK. With a empty span <span></span> IE does not render the
+            //icons. Putting a '&nbsp;' in the span seemed to work. Perhaps there is a
+            //better workaround.
+            buffer.append("&nbsp;");
+            buffer.append("</span>");
 
-        //TODO IE HACK. With a empty span <span></span> IE does not render the
-        //icons. Putting a '&nbsp;' in the span seemed to work. Perhaps there is a
-        //better workaround.
-        buffer.append("&nbsp;");
-        buffer.append("</span>");
+        } else {
+            buffer.elementStart("img");
+            buffer.appendAttribute("class", "customIcon");
+            buffer.appendAttribute("src", treeNode.getIcon());
+            buffer.closeTag();
+        }
     }
 
     /**

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/TreeNode.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/TreeNode.java?rev=749094&r1=749093&r2=749094&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/TreeNode.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/TreeNode.java Sun Mar  1 20:53:39 2009
@@ -31,8 +31,8 @@
  * TreeNode's are used to store hierarchical data representations for example
  * directories, subdirectories and files.
  * <p/>
- * Nodes <strong>must</strong> have an <strong>unique</strong> id. If nodes
- * do not have an unique id's, the tree might be behave erratic.
+ * Nodes <strong>must</strong> have a <strong>unique</strong> id. If nodes
+ * do not have a unique id, the tree might behave erratic.
  * <p/>
  * Each node can store a user defined value of type {@link java.lang.Object}.
  * <p/>
@@ -95,6 +95,9 @@
     /** List containing this nodes children. */
     private List children;
 
+    /** A custom icon the Tree will render for this node. */
+    private String icon;
+
     // ---------------------------------------------------- Public Constructors
 
     /**
@@ -282,6 +285,47 @@
         return expanded;
     }
 
+    /**
+     * Returns the TreeNode's custom icon.
+     *
+     * @see #setIcon(java.lang.String)
+     *
+     * @return the TreeNode's custom icon
+     */
+    public String getIcon() {
+    		return icon;
+    }
+
+    /**
+     * Set a custom icon for this TreeNode.
+     * <p/>
+     * The icon will be set as the <tt>src</tt> attribute of an HTML <tt>img</tt>
+     * element. Ensure the icon value specifies the full path to the actual
+     * icon resource.
+     * <p/>
+     * For example:
+     * <pre class="prettyprint">
+     * public TreeNode createNodes() {
+     *     // Retrieve the web application context path
+     *     String contextPath = getContext().getRequest().getContextPath();
+     *
+     *     TreeNode book = new TreeNode("book");
+     *
+     *     TreeNode chapter = new TreeNode("chapter", "1", book);
+     *
+     *     // Specify the full path to the chapter.png icon
+     *     chapter.setIcon(contextPath + "/assets/chapter.png");
+     *     ...
+     *
+     *     return book;
+     * } </pre>
+     *
+     * @param icon the TreeNode icon
+     */
+    public void setIcon(String icon) {
+        this.icon = icon;
+    }
+
     // -------------------------------------------------------- Public Behavior
 
     /**

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.css
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.css?rev=749094&r1=749093&r2=749094&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.css (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.css Sun Mar  1 20:53:39 2009
@@ -127,7 +127,14 @@
 .treestyle span.leafIcon,
 .treestyle span.expandedIcon,
 .treestyle span.collapsedIcon,
-.treestyle .spacer {
+.treestyle .spacer,
+.treestyle img.customIcon {
     clear: both;
     _float: none; /*IE only*/
-}
\ No newline at end of file
+}
+
+/* Style for a custom TreeNode icon. Tweak it if further customization is needed */
+.treestyle img.customIcon {
+    margin-right: 2px;
+    vertical-align: top;
+}

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.js
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.js?rev=749094&r1=749093&r2=749094&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.js (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/tree/tree.js Sun Mar  1 20:53:39 2009
@@ -152,6 +152,9 @@
 function handleIcons(iconId, newClassName) {
     var span = document.getElementById(iconId);
 
+    if(span==null) {
+        return; //skip iconId target is null. This occurs when customIcon is set
+    }
     if(isLeaf(span)) {
         return; //we do not handle leaf nodes
     }