click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r929089 - in /click/trunk/click/extras/src/org/apache/click/extras: control/VirtualKeyboard.java tree/CheckboxTree.java tree/Tree.java
Date Tue, 30 Mar 2010 11:27:27 GMT
Author: sabob
Date: Tue Mar 30 11:27:26 2010
New Revision: 929089

URL: http://svn.apache.org/viewvc?rev=929089&view=rev
Log:
migrated html imports to head elements

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/control/VirtualKeyboard.java
    click/trunk/click/extras/src/org/apache/click/extras/tree/CheckboxTree.java
    click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/VirtualKeyboard.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/VirtualKeyboard.java?rev=929089&r1=929088&r2=929089&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/VirtualKeyboard.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/VirtualKeyboard.java Tue
Mar 30 11:27:26 2010
@@ -18,8 +18,14 @@
  */
 package org.apache.click.extras.control;
 
+import java.util.List;
+import org.apache.click.Context;
 import org.apache.click.control.TextField;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.JsImport;
+import org.apache.click.element.JsScript;
 import org.apache.click.util.ClickUtils;
+import org.apache.click.util.HtmlStringBuffer;
 
 /**
  * Provides a graphical Virtual Keyboard interface text field control:   <input
type='text'>.
@@ -71,12 +77,6 @@ public class VirtualKeyboard extends Tex
 
     private static final long serialVersionUID = 1L;
 
-     /** The VirtualKeyboard imports statement. */
-    public static final String HTML_IMPORTS =
-          "<script type=\"text/javascript\">var keyboard_png_path=\"{0}/click/keyboard{1}.png\";</script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/click/keyboard{1}.js\" charset=\"UTF-8\"></script>\n"
-        + "<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/click/keyboard{1}.css\"/>\n";
-
     // ----------------------------------------------------------- Constructors
 
     /**
@@ -113,7 +113,7 @@ public class VirtualKeyboard extends Tex
     // --------------------------------------------------------- Public Methods
 
     /**
-     * Return the VirtualKeyboard HTML head imports statements for the following
+     * Return the VirtualKeyboard HTML HEAD elements for the following
      * resources:
      * <p/>
      * <ul>
@@ -122,11 +122,38 @@ public class VirtualKeyboard extends Tex
      * <li><tt>click/keyboard.png</tt></li>
      * </ul>
      *
-     * @see org.apache.click.Control#getHtmlImports()
+     * @see org.apache.click.Control#getHeadElements()
      *
-     * @return the HTML head import statements for the control
+     * @return the HTML HEAD elements for the control
      */
-    public String getHtmlImports() {
-        return ClickUtils.createHtmlImport(HTML_IMPORTS, getContext());
+    @Override
+    public List getHeadElements() {
+        Context context = getContext();
+        String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+
+            JsImport jsImport = new JsImport("/click/keyboard.js", versionIndicator);
+            jsImport.setAttribute("charset", "UTF-8");
+            headElements.add(jsImport);
+            headElements.add(new CssImport("/click/keyboard.css", versionIndicator));
+        }
+
+        String fieldId = getId();
+        JsScript script = new JsScript();
+        script.setId(fieldId + "_js_setup");
+
+        if (!headElements.contains(script)) {
+            HtmlStringBuffer buffer = new HtmlStringBuffer(150);
+            buffer.append("var keyboard_png_path=\"");
+            buffer.append(context.getRequest().getContextPath());
+            buffer.append("/click/keyboard");
+            buffer.append(versionIndicator);
+            buffer.append(".png\"");
+            script.setContent(buffer.toString());
+            headElements.add(script);
+        }
+        return headElements;
     }
 }

Modified: click/trunk/click/extras/src/org/apache/click/extras/tree/CheckboxTree.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/tree/CheckboxTree.java?rev=929089&r1=929088&r2=929089&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/tree/CheckboxTree.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/tree/CheckboxTree.java Tue Mar 30
11:27:26 2010
@@ -30,6 +30,7 @@ import java.util.Set;
 import org.apache.click.Context;
 import org.apache.click.control.Decorator;
 import org.apache.click.control.Form;
+import org.apache.click.element.JsImport;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.ContainerUtils;
 import org.apache.click.util.HtmlStringBuffer;
@@ -125,16 +126,12 @@ import org.apache.commons.lang.ArrayUtil
  */
 public class CheckboxTree extends Tree {
 
-    // -------------------------------------------------------------- Constants
-
-    /** Client side javascript import. This extends on the functions available in {@link
Tree}. */
-    public static final String HTML_IMPORTS =
-            "<script type=\"text/javascript\" src=\"{0}/click/tree/checkbox-tree{1}.js\"></script>\n";
+    // Constants --------------------------------------------------------------
 
     /** default serial version id. */
     private static final long serialVersionUID = 1L;
 
-    // ---------------------------------------------------- Private variables
+    // Private variables ----------------------------------------------------
 
     /**
      * Determines if the checkboxes of child nodes should also be
@@ -142,7 +139,7 @@ public class CheckboxTree extends Tree {
      */
     private boolean selectChildNodes = false;
 
-   // ---------------------------------------------------- Public Constructors
+   // Public Constructors ----------------------------------------------------
 
     /**
      * Create an Tree control for the given name.
@@ -162,7 +159,7 @@ public class CheckboxTree extends Tree {
     public CheckboxTree() {
     }
 
-    // --------------------------------------------------------- Public getters and setters
+    // Public Properties ------------------------------------------------------
 
     /**
      * Create and set the Tree's decorator that will render a Checkbox for
@@ -171,6 +168,7 @@ public class CheckboxTree extends Tree {
      * @see #createDecorator()
      * @see org.apache.click.Control#onInit()
      */
+    @Override
     public void onInit() {
         setDecorator(createDecorator());
     }
@@ -197,31 +195,38 @@ public class CheckboxTree extends Tree {
         this.selectChildNodes = selectChildNodes;
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
-     * Return the CheckboxTree HTML head imports statements for the following
-     * resources:
-     * <p/>
+     * Return the CheckboxTree HTML HEAD elements for the following resource:
+     *
      * <ul>
      * <li><tt>click/tree/checkbox-tree.js</tt></li>
      * </ul>
-     * <p/>
-     * Additionally all the {@link Tree#getHtmlImports() Tree import statements}
+     *
+     * Additionally all the {@link Tree#getHeadElements() Tree import statements}
      * are also returned.
      *
-     * @see org.apache.click.Control#getHtmlImports()
+     * @see org.apache.click.Control#getHeadElements()
      *
-     * @return the HTML head import statements for the control
+     * @return the HTML HEAD elements for the control
      */
-    public String getHtmlImports() {
-        HtmlStringBuffer buffer = new HtmlStringBuffer(256);
-        if (isJavascriptEnabled()) {
-            buffer.append(ClickUtils.createHtmlImport(HTML_IMPORTS,
-                getContext()));
+    @Override
+    public List getHeadElements() {
+
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+
+            Context context = getContext();
+            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+
+            if (isJavascriptEnabled()) {
+                headElements.add(new JsImport("/click/tree/checkbox-tree.js",
+                    versionIndicator));
+            }
         }
-        buffer.append(super.getHtmlImports());
-        return buffer.toString();
+
+        return headElements;
     }
 
     /**
@@ -258,6 +263,7 @@ public class CheckboxTree extends Tree {
      *     addControl(form);
      * } </pre>
      */
+    @Override
     public void bindSelectOrDeselectValues() {
         // With html forms, only "checked" checkbox values are submitted
         // to the server. So the request does not supply us the information
@@ -314,6 +320,7 @@ public class CheckboxTree extends Tree {
      *
      * @see #bindExpandOrCollapseValues()
      */
+    @Override
     public void bindRequestValue() {
         bindExpandOrCollapseValues();
     }
@@ -328,7 +335,7 @@ public class CheckboxTree extends Tree {
         bindSelectOrDeselectValues();
     }
 
-    //------------------------------------------------------------Inner classes
+    // Inner classes ----------------------------------------------------------
 
     /**
      * Creates and returns a custom {@link Decorator} that will render a Checkbox
@@ -560,6 +567,7 @@ public class CheckboxTree extends Tree {
          *
          * @param treeNode the current node rendered
          */
+        @Override
         public void init(TreeNode treeNode) {
             super.init(treeNode);
             selectId = buildString("s_", treeNode.getId(), "");
@@ -628,6 +636,7 @@ public class CheckboxTree extends Tree {
          *
          * @param treeNode the current node rendered
          */
+        @Override
         public void init(TreeNode treeNode) {
             super.init(treeNode);
             checkboxRenderer.init(treeNode);
@@ -689,6 +698,7 @@ public class CheckboxTree extends Tree {
          *
          * @param treeNode the current node rendered
          */
+        @Override
         public void init(TreeNode treeNode) {
             super.init(treeNode);
             checkboxRenderer.init(treeNode);
@@ -717,6 +727,7 @@ public class CheckboxTree extends Tree {
          *
          * @return currently installed javascript renderer
          */
+        @Override
         public JavascriptRenderer getJavascriptRenderer() {
             if (javascriptRenderer == null) {
                 javascriptRenderer = new CheckboxSessionJavascriptRenderer();
@@ -747,6 +758,7 @@ public class CheckboxTree extends Tree {
          *
          * @return currently installed javascript renderer
          */
+        @Override
         public JavascriptRenderer getJavascriptRenderer() {
             if (javascriptRenderer == null) {
                 javascriptRenderer = new CheckboxCookieJavascriptRenderer(expandedCookieName,
collapsedCookieName);
@@ -763,6 +775,7 @@ public class CheckboxTree extends Tree {
      * @param javascriptPolicy the current javascript policy
      * @return newly created JavascriptHandler
      */
+    @Override
     protected JavascriptHandler createJavascriptHandler(int javascriptPolicy) {
         if (javascriptPolicy == JAVASCRIPT_SESSION_POLICY) {
             return new CheckboxSessionHandler(getContext());
@@ -771,13 +784,14 @@ public class CheckboxTree extends Tree {
         }
     }
 
-    // ------------------------------------------------ Package Private Methods
+    // Package Private Methods ------------------------------------------------
 
     /**
      * Expand / collapse the tree nodes.
      *
      * @return true to continue Page event processing or false otherwise
      */
+    @Override
     boolean postProcess() {
         if (isJavascriptEnabled()) {
             javascriptHandler.init(getContext());

Modified: click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java?rev=929089&r1=929088&r2=929089&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/tree/Tree.java Tue Mar 30 11:27:26
2010
@@ -39,6 +39,8 @@ import org.apache.click.ActionEventDispa
 import org.apache.click.control.AbstractControl;
 import org.apache.click.control.ActionLink;
 import org.apache.click.control.Decorator;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.JsImport;
 import org.apache.click.extras.control.SubmitLink;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
@@ -164,7 +166,7 @@ import org.apache.commons.lang.StringUti
  */
 public class Tree extends AbstractControl {
 
-    // -------------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     /** The tree's expand/collapse parameter name: <tt>"expandTreeNode"</tt>.
*/
     public static final String EXPAND_TREE_NODE_PARAM = "expandTreeNode";
@@ -172,18 +174,6 @@ public class Tree extends AbstractContro
     /** The tree's select/deselect parameter name: <tt>"selectTreeNode"</tt>.
*/
     public static final String SELECT_TREE_NODE_PARAM = "selectTreeNode";
 
-    /** The Tree imports statement. */
-    public static final String TREE_IMPORTS =
-            "<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}/click/tree/tree{1}.css\"/>\n";
-
-    /** Client side javascript imports statement. */
-    public static final String JAVASCRIPT_IMPORTS =
-            "<script type=\"text/javascript\" src=\"{0}/click/tree/tree{1}.js\"></script>\n";
-
-    /** Client side javascript cookie imports statement. */
-    public static final String JAVASCRIPT_COOKIE_IMPORTS =
-            "<script type=\"text/javascript\" src=\"{0}/click/tree/cookie-helper{1}.js\"></script>\n";
-
     /** Indicator for using cookies to implement client side behavior. */
     public final static int JAVASCRIPT_COOKIE_POLICY = 1;
 
@@ -202,7 +192,7 @@ public class Tree extends AbstractContro
     /** default serial version id. */
     private static final long serialVersionUID = 1L;
 
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /** The tree's hierarchical data model. */
     protected TreeNode rootNode;
@@ -240,7 +230,7 @@ public class Tree extends AbstractContro
     /** Flag indicates if listeners should be notified of any state changes. */
     private boolean notifyListeners = true;
 
-    // ---------------------------------------------------- Public Constructors
+    // Public Constructors ----------------------------------------------------
 
     /**
      * Create an Tree control for the given name.
@@ -277,7 +267,7 @@ public class Tree extends AbstractContro
         setAttribute("class", "treestyle");
     }
 
-    // --------------------------------------------- Public Getters and Setters
+    // Public Properties ------------------------------------------------------
 
     /**
      * @see Control#setName(String)
@@ -285,6 +275,7 @@ public class Tree extends AbstractContro
      * @param name of the control
      * @throws IllegalArgumentException if the name is null
      */
+    @Override
     public void setName(String name) {
         super.setName(name);
         getExpandLink().setName(name + "-expandLink");
@@ -495,8 +486,7 @@ public class Tree extends AbstractContro
     }
 
     /**
-     * Return the Tree HTML head imports statements for the following
-     * resources:
+     * Return the Tree HTML HEAD elements for the following resources:
      * <p/>
      * <ul>
      * <li><tt>click/tree/tree.css</tt></li>
@@ -504,36 +494,34 @@ public class Tree extends AbstractContro
      * <li><tt>click/tree/cookie-helper.js</tt></li>
      * </ul>
      *
-     * @see org.apache.click.Control#getHtmlImports()
-     *
-     * @return the HTML head import statements for the control
-     */
-    public String getHtmlImports() {
-        Context context = getContext();
-        HtmlStringBuffer buffer = new HtmlStringBuffer(256);
-        if (isJavascriptEnabled()) {
-            buffer.append(ClickUtils.createHtmlImport(JAVASCRIPT_IMPORTS,
-                context));
-            if (javascriptPolicy == JAVASCRIPT_COOKIE_POLICY) {
-                buffer.append(ClickUtils.createHtmlImport(JAVASCRIPT_COOKIE_IMPORTS,
-                    context));
-            }
-        }
-        buffer.append(ClickUtils.createHtmlImport(TREE_IMPORTS, context));
-        return buffer.toString();
-    }
-
-   /**
      * @see org.apache.click.Control#getHeadElements()
      *
-     * @return the list of HEAD elements to be included in the page
+     * @return the HTML HEAD elements for the control
      */
+    @Override
     public List getHeadElements() {
+
         if (headElements == null) {
             headElements = super.getHeadElements();
+
+            Context context = getContext();
+            String versionIndicator = ClickUtils.getResourceVersionIndicator(context);
+
+            headElements.add(new CssImport("/click/tree/tree.css", versionIndicator));
+
+            if (isJavascriptEnabled()) {
+                headElements.add(new JsImport("/click/tree/tree.js", versionIndicator));
+
+                if (javascriptPolicy == JAVASCRIPT_COOKIE_POLICY) {
+                    headElements.add(new JsImport("/click/tree/cookie-helper.js",
+                        versionIndicator));
+                }
+            }
+
             headElements.addAll(getExpandLink().getHeadElements());
             headElements.addAll(getSelectLink().getHeadElements());
         }
+
         return headElements;
     }
 
@@ -569,7 +557,7 @@ public class Tree extends AbstractContro
         return selectLink;
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * This method binds the users request of expanded and collapsed nodes to
@@ -901,6 +889,7 @@ public class Tree extends AbstractContro
      *
      * @return true to continue Page event processing or false otherwise
      */
+    @Override
     public boolean onProcess() {
         getExpandLink().onProcess();
         getSelectLink().onProcess();
@@ -918,6 +907,7 @@ public class Tree extends AbstractContro
      * This method cleans up the {@link #expandLink} and {@link #selectLink}.
      * @see org.apache.click.Control#onDestroy()
      */
+    @Override
     public void onDestroy() {
         super.onDestroy();
         getExpandLink().onDestroy();
@@ -933,6 +923,7 @@ public class Tree extends AbstractContro
      * @param listener the listener object with the named method to invoke
      * @param method the name of the method to invoke
      */
+    @Override
     public void setListener(Object listener, String method) {
         super.setListener(listener, method);
     }
@@ -945,6 +936,7 @@ public class Tree extends AbstractContro
      *
      * @param listener the control's action listener
      */
+    @Override
     public void setActionListener(ActionListener listener) {
         super.setActionListener(listener);
     }
@@ -967,13 +959,14 @@ public class Tree extends AbstractContro
         listeners.remove(listener);
     }
 
-    // ------------------------------------------------------ Default Rendering
+    // Default Rendering ------------------------------------------------------
 
     /**
      * @see AbstractControl#getControlSizeEst()
      *
      * @return the estimated rendered control size in characters
      */
+    @Override
     public int getControlSizeEst() {
         return 256;
     }
@@ -999,6 +992,7 @@ public class Tree extends AbstractContro
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         buffer.elementStart("div");
         buffer.appendAttribute("id", getId());
@@ -1038,6 +1032,7 @@ public class Tree extends AbstractContro
      * @see java.lang.Object#toString()
      * @return a HTML rendered Tree string
      */
+    @Override
     public String toString() {
         HtmlStringBuffer buffer = new HtmlStringBuffer(getControlSizeEst());
         render(buffer);
@@ -1334,7 +1329,7 @@ public class Tree extends AbstractContro
         return (treeNode.isExpanded() && treeNode.hasChildren());
     }
 
-    // -------------------------------------------- Protected observer behavior
+    // Protected observer behavior --------------------------------------------
 
     /**
      * Notifies all listeners currently registered with the tree, about any
@@ -1392,7 +1387,7 @@ public class Tree extends AbstractContro
         }
     }
 
-    // ----------------------------------------------------- Protected behavior
+    // Protected behavior -----------------------------------------------------
 
     /**
      * Sets the TreeNode expand state to the new value.
@@ -1640,7 +1635,7 @@ public class Tree extends AbstractContro
         return context.getResponse().encodeURL(buffer.toString());
     }
 
-    // ------------------------------------------------ Package Private Methods
+    // Package Private Methods ------------------------------------------------
 
     /**
      * Expand / collapse and select / deselect the tree nodes.
@@ -1664,7 +1659,7 @@ public class Tree extends AbstractContro
         return true;
     }
 
-    //----------------------------------------------------------- Inner classes
+    // Inner classes ----------------------------------------------------------
 
     /**
      * Iterate over all the nodes in the tree in a breadth first manner.
@@ -1775,7 +1770,7 @@ public class Tree extends AbstractContro
         }
     }
 
-    // ------------------------------------------------------- Private behavior
+    // Private behavior -------------------------------------------------------
 
     /**
      * Returns whether the specified node is visible. The semantics of visible
@@ -1816,7 +1811,7 @@ public class Tree extends AbstractContro
         return nodes;
     }
 
-    // ------------------------------------------- Javascript specific behavior
+    // Javascript behavior ----------------------------------------------------
 
     /**
      * Creates a new JavascriptHandler based on the specified policy.
@@ -2015,6 +2010,7 @@ public class Tree extends AbstractContro
          * @param treeNode the current node rendered
          * @see #init(TreeNode)
          */
+        @Override
         public void init(TreeNode treeNode) {
             super.init(treeNode);
             StringBuffer tmp = new StringBuffer();
@@ -2042,6 +2038,7 @@ public class Tree extends AbstractContro
          * @param treeNode the current node rendered
          * @see #init(TreeNode)
          */
+        @Override
         public void init(TreeNode treeNode) {
             super.init(treeNode);
             String tmp = buildString("handleNodeExpansion(this,event,'", expandId, "','");
@@ -2700,24 +2697,6 @@ public class Tree extends AbstractContro
          */
         public void nodeCollapsed(Tree tree, TreeNode node, Context context,
                 boolean oldValue) { /*noop*/ }
-
-        /**
-         * Provides debug information about the map storing the tracked paths.
-         */
-//        private void dumpPathTracker() {
-//            System.out.println("--------------------------------------Printing Path Tracker
map\n");
-//            if (selectTracker == null) {
-//                System.out.println("Path tracker is null");
-//                return;
-//            }
-//            for (Iterator it = selectTracker.keySet().iterator(); it.hasNext();) {
-//                String key = (String) it.next();
-//                System.out.println("ids -> [" + key + "]  value count -> ["
-//                        + ((Entry) selectTracker.get(key)).count + "] : last node ->
["
-//                        + ((Entry) selectTracker.get(key)).lastNodeInPath + "]");
-//            }
-//            System.out.println("--------------------------------------Done");
-//        }
     }
 
     /**
@@ -2745,6 +2724,7 @@ public class Tree extends AbstractContro
          *
          * @return a string representation
          */
+        @Override
         public String toString() {
             StringBuffer buffer = new StringBuffer("Entry value -> (").append(count).
                     append(")");



Mime
View raw message