click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r931105 - in /click/trunk/click/examples: src/org/apache/click/examples/control/ src/org/apache/click/examples/control/exporter/ src/org/apache/click/examples/control/html/cssform/ webapp/control/
Date Tue, 06 Apr 2010 11:58:23 GMT
Author: sabob
Date: Tue Apr  6 11:58:23 2010
New Revision: 931105

URL: http://svn.apache.org/viewvc?rev=931105&view=rev
Log:
migrated getHtmlImports to getHeadElements

Modified:
    click/trunk/click/examples/src/org/apache/click/examples/control/RichTextArea.java
    click/trunk/click/examples/src/org/apache/click/examples/control/exporter/TableExportContainer.java
    click/trunk/click/examples/src/org/apache/click/examples/control/html/cssform/CssForm.java
    click/trunk/click/examples/webapp/control/email-form.htm

Modified: click/trunk/click/examples/src/org/apache/click/examples/control/RichTextArea.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/control/RichTextArea.java?rev=931105&r1=931104&r2=931105&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/control/RichTextArea.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/control/RichTextArea.java Tue
Apr  6 11:58:23 2010
@@ -18,10 +18,12 @@
  */
 package org.apache.click.examples.control;
 
-import java.text.MessageFormat;
-import java.util.Map;
+import java.util.List;
 
 import org.apache.click.control.TextArea;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.JsImport;
+import org.apache.click.element.JsScript;
 import org.apache.click.util.HtmlStringBuffer;
 
 /**
@@ -37,15 +39,6 @@ public class RichTextArea extends TextAr
 
     private static final long serialVersionUID = 1L;
 
-    /** The YUI editor JavaScript import. */
-    protected static final String HTML_IMPORTS =
-        "<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/yui/fonts/fonts-min.css\"/>\n"
-        + "<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/yui/editor/skins/sam/simpleeditor.css\"/>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/yui/yahoo-dom-event/yahoo-dom-event.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/yui/element/element-beta-min.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/yui/container/container_core-min.js\"></script>\n"
-        + "<script type=\"text/javascript\" src=\"{0}/yui/editor/simpleeditor-min.js\"></script>\n";
-
     /**
      * The textarea YUI editor theme [<tt>yui-skin-sam</tt>].
      */
@@ -106,24 +99,41 @@ public class RichTextArea extends TextAr
     }
 
     /**
-     * Return the JavaScript include: &nbsp; {@link #HTML_IMPORTS}, and YUI
+     * Return the Control HEAD elements for YUI libraries and YUI
      * editor JavaScript initialization code.
      *
-     * @see org.apache.click.control.Field#getHtmlImports()
+     * @see org.apache.click.control.Field#getHeadElements()
      */
-    public String getHtmlImports() {
-        HtmlStringBuffer buffer = new HtmlStringBuffer();
-
-        Object[] args = { getContext().getRequest().getContextPath() };
-        buffer.append(MessageFormat.format(HTML_IMPORTS, args));
+    @Override
+    public List getHeadElements() {
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+            headElements.add(new CssImport("/yui/fonts/fonts-min.css"));
+            headElements.add(new CssImport("/yui/editor/skins/sam/simpleeditor.css"));
+            headElements.add(new JsImport("/yui/yahoo-dom-event/yahoo-dom-event.js"));
+            headElements.add(new JsImport("/yui/element/element-beta-min.js"));
+            headElements.add(new JsImport("/yui/container/container_core-min.js"));
+            headElements.add(new JsImport("/yui/editor/simpleeditor-min.js"));
+        }
+
+        JsScript script = new JsScript();
+        script.setId(getId() + "_js_setup");
+
+        if (!headElements.contains(script)) {
+            script.setExecuteOnDomReady(true);
+
+            HtmlStringBuffer buffer = new HtmlStringBuffer();
+            buffer.append("var myConfig = {").append(getConfig()).append("};\n");
+            buffer.append("var myEditor = new YAHOO.widget.SimpleEditor('");
+            buffer.append(getId()).append("', myConfig);\n");
+            buffer.append("if(myConfig.titlebar) {");
+            buffer.append(" myEditor._defaultToolbar.titlebar=myConfig.titlebar; }\n");
+            buffer.append("myEditor.render();\n");
+            script.setContent(buffer.toString());
+            headElements.add(script);
+        }
 
-        args = new String[] { getId(), getConfig() };
-        String javascript = "<script type=\"text/javascript\">(function() '{' " +
-            "var myConfig = '{' {1} '}'; var myEditor = new YAHOO.widget.SimpleEditor(''{0}'',
myConfig);" +
-            "if(myConfig.titlebar) '{' myEditor._defaultToolbar.titlebar=myConfig.titlebar;
'}'" +
-            "myEditor.render(); '}')();</script>\n";
-        buffer.append(MessageFormat.format(javascript, args));
-        return buffer.toString();
+        return headElements;
     }
 
     /**
@@ -136,6 +146,7 @@ public class RichTextArea extends TextAr
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         buffer.elementStart("span");
         buffer.appendAttribute("class", getTheme());
@@ -144,17 +155,4 @@ public class RichTextArea extends TextAr
         super.render(buffer);
         buffer.elementEnd("span");
     }
-
-    // -------------------------------------------------------- Protected Methods
-
-    /**
-     * Render a Velocity template for the given data model.
-     *
-     * @param buffer the specified buffer to render the template output to
-     * @param model the model data to merge with the template
-     */
-    protected void renderTemplate(HtmlStringBuffer buffer, Map model) {
-        buffer.append(getContext().renderTemplate(RichTextArea.class, model));
-    }
-
 }

Modified: click/trunk/click/examples/src/org/apache/click/examples/control/exporter/TableExportContainer.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/control/exporter/TableExportContainer.java?rev=931105&r1=931104&r2=931105&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/control/exporter/TableExportContainer.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/control/exporter/TableExportContainer.java
Tue Apr  6 11:58:23 2010
@@ -108,6 +108,7 @@ public class TableExportContainer implem
         exporter.export(table, context);
     }
 
+    @Override
     public String toString() {
         HtmlStringBuffer buffer = new HtmlStringBuffer();
 
@@ -139,7 +140,7 @@ public class TableExportContainer implem
                 banner.append(getSeparator());
             }
         }
-        String[] args = { getStyleClass(), banner.toString()};
+        Object[] args = { getStyleClass(), banner.toString()};
         buffer.append(table.getMessage("table-export-banner", args));
     }
 

Modified: click/trunk/click/examples/src/org/apache/click/examples/control/html/cssform/CssForm.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/control/html/cssform/CssForm.java?rev=931105&r1=931104&r2=931105&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/control/html/cssform/CssForm.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/control/html/cssform/CssForm.java
Tue Apr  6 11:58:23 2010
@@ -18,9 +18,9 @@
  */
 package org.apache.click.examples.control.html.cssform;
 
+import java.util.List;
+import org.apache.click.element.CssImport;
 import org.apache.click.extras.control.HtmlForm;
-import org.apache.click.util.ClickUtils;
-import org.apache.click.util.HtmlStringBuffer;
 
 /**
  * A custom Form that adds the Html import, "cssform.css", to the page.
@@ -34,18 +34,12 @@ public class CssForm extends HtmlForm {
     }
 
     @Override
-    public String getHtmlImports() {
-        HtmlStringBuffer buffer = new HtmlStringBuffer(512);
-
-        // Include the Form default imports
-        String htmlImports = super.getHtmlImports();
-        if (htmlImports != null) {
-            buffer.append(htmlImports);
+    public List getHeadElements() {
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+            headElements.add(new CssImport("/assets/css/cssform.css"));
         }
 
-        // Include CSS for ContactDetailsForm
-        String imports = "<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}/assets/css/cssform{1}.css\"/>\n";
-        buffer.append(ClickUtils.createHtmlImport(imports, getContext()));
-        return buffer.toString();
+        return headElements;
     }
 }

Modified: click/trunk/click/examples/webapp/control/email-form.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/control/email-form.htm?rev=931105&r1=931104&r2=931105&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/control/email-form.htm (original)
+++ click/trunk/click/examples/webapp/control/email-form.htm Tue Apr  6 11:58:23 2010
@@ -26,55 +26,25 @@ $form
 <p>&nbsp;</p>
 
 The form demonstrates a custom 
-<a href="$context/javadoc/org/apache/click/examples/control/RichTextArea.html">RichTextArea</a>
+<a href="$context/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/control/RichTextArea.java">RichTextArea</a>
 control using the 
 <a target="blank" href="http://developer.yahoo.com/yui/editor/">YUI editor</a>.
-The control overrides the Field method <tt>getHtmlImports()</tt> to include its

+The control overrides the Field method <tt>getHeadElements()</tt> to include
its
 JavaScript imports automatically:
 
 <pre class="codeJava">
+<span class="kw">public</span> List getHeadElements() {
+    if (headElements == <span class="kw">null</span>) {
+        headElements = <span class="kw">super</span>.getHeadElements();
+        headElements.add(<span class="kw">new</span> CssImport(<span class="st">"/yui/fonts/fonts-min.css"</span>));
+        headElements.add(<span class="kw">new</span> CssImport(<span class="st">"/yui/editor/skins/sam/simpleeditor.css"</span>));
+        headElements.add(<span class="kw">new</span> JsImport(<span class="st">"/yui/yahoo-dom-event/yahoo-dom-event.js"</span>));
+        headElements.add(<span class="kw">new</span> JsImport(<span class="st">"/yui/element/element-beta-min.js"</span>));
+        headElements.add(<span class="kw">new</span> JsImport(<span class="st">"/yui/container/container_core-min.js"</span>));
+        headElements.add(<span class="kw">new</span> JsImport(<span class="st">"/yui/editor/simpleeditor-min.js"</span>));
+    }
 
-<span class="kw">protected static final</span> String HTML_IMPORTS =
-          <span class="st">"&lt;link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/yui/fonts/fonts-min.css\"/&gt;\n"</span>
-        + <span class="st">"&lt;link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/yui/editor/skins/sam/simpleeditor.css\"/&gt;\n"</span>
-        + <span class="st">"&lt;script type=\"text/javascript\" src=\"{0}/yui/yahoo-dom-event/yahoo-dom-event.js\"&gt;&lt;/script&gt;\n"</span>
-        + <span class="st">"&lt;script type=\"text/javascript\" src=\"{0}/yui/element/element-beta-min.js\"&gt;&lt;/script&gt;\n"</span>
-        + <span class="st">"&lt;script type=\"text/javascript\" src=\"{0}/yui/container/container_core-min.js\"&gt;&lt;/script&gt;\n"</span>
-        + <span class="st">"&lt;script type=\"text/javascript\" src=\"{0}/yui/editor/simpleeditor-min.js\"&gt;&lt;/script&gt;\n";</span>
+    ...
 
-<span class="kw">public</span> String getHtmlImports() {
-    String[] args = { getContext().getRequest().getContextPath() };
-    <span class="kw">return</span> MessageFormat.format(HTML_IMPORTS, args);
+    <span class="kw">return</span> headElements;
 } </pre>
-
-The control is rendered using a Velocity template 
-<tt>(/examples/control/RichTextArea.htm)</tt> which is loaded from the classpath:
-
-<pre class="codeHtml">
-<span class="st">${textArea}</span>
-&lt;script type="text/javascript"&gt;
-(function() {
-  var myConfig = {
-    <span class="st">${config}</span>
-  };
-
-  var myEditor = new YAHOO.widget.SimpleEditor('<span class="st">${id}</span>',
myConfig);
-  myEditor.render();
-})();
-&lt;/script&gt;
-</pre>
-
-The control's <tt>toString()</tt> method merges the <tt>RichTextArea.htm</tt>
-template and the model returning rendred HTML.
-
-<pre class="codeJava">
-<span class="kw">public</span> String toString() {
-    Map model = <span class="kw">new</span> HashMap();
-    model.put(<span class="st">"textArea"</span>, super.toString());
-    model.put(<span class="st">"config"</span>, getConfig());
-    model.put(<span class="st">"id"</span>, getId());
-
-    <span class="kw">return</span> getContext().renderTemplate(getClass(), model);
-} </pre>
-
-



Mime
View raw message