You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by me...@apache.org on 2010/02/26 07:22:45 UTC

svn commit: r916580 - in /click/trunk/click/framework/src/org/apache/click/control: AbstractContainer.java AbstractControl.java Container.java Field.java Table.java

Author: medgar
Date: Fri Feb 26 06:22:44 2010
New Revision: 916580

URL: http://svn.apache.org/viewvc?rev=916580&view=rev
Log:
CLK-633

Modified:
    click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java
    click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java
    click/trunk/click/framework/src/org/apache/click/control/Container.java
    click/trunk/click/framework/src/org/apache/click/control/Field.java
    click/trunk/click/framework/src/org/apache/click/control/Table.java

Modified: click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java?rev=916580&r1=916579&r2=916580&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java Fri Feb 26 06:22:44 2010
@@ -20,7 +20,6 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -44,25 +43,24 @@
  *         // Return the HTML tag
  *         return "div";
  *     }
- * }
- * </pre>
+ * } </pre>
  */
 public abstract class AbstractContainer extends AbstractControl implements
     Container {
 
-    // -------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     private static final long serialVersionUID = 1L;
 
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /** The list of controls. */
-    protected List controls;
+    protected List<Control> controls;
 
     /** The map of controls keyed by field name. */
-    protected Map controlMap;
+    protected Map<String, Control> controlMap;
 
-    // ---------------------------------------------------------- Constructorrs
+    // Constructors -----------------------------------------------------------
 
     /**
      * Create a container with no name defined.
@@ -79,7 +77,7 @@
         super(name);
     }
 
-    // --------------------------------------------------------- Public methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * @see org.apache.click.control.Container#add(org.apache.click.Control).
@@ -134,9 +132,9 @@
      *
      * @return the sequential list of controls held by the container
      */
-    public List getControls() {
+    public List<Control> getControls() {
         if (controls == null) {
-            controls = new ArrayList();
+            controls = new ArrayList<Control>();
         }
         return controls;
     }
@@ -182,9 +180,9 @@
      *
      * @return the map of controls
      */
-    public Map getControlMap() {
+    public Map<String, Control> getControlMap() {
         if (controlMap == null) {
-            controlMap = new HashMap();
+            controlMap = new HashMap<String, Control>();
         }
         return controlMap;
     }
@@ -217,12 +215,9 @@
 
         boolean continueProcessing = true;
 
-        if (hasControls()) {
-            for (Iterator it = getControls().iterator(); it.hasNext();) {
-                Control control = (Control) it.next();
-                if (!control.onProcess()) {
-                    continueProcessing = false;
-                }
+        for (Control control : getControls()) {
+            if (!control.onProcess()) {
+                continueProcessing = false;
             }
         }
 
@@ -235,14 +230,11 @@
      * @see org.apache.click.Control#onDestroy()
      */
     public void onDestroy() {
-        if (hasControls()) {
-            for (int i = 0, size = getControls().size(); i < size; i++) {
-                Control control = (Control) getControls().get(i);
-                try {
-                    control.onDestroy();
-                } catch (Throwable t) {
-                    ClickUtils.getLogService().error("onDestroy error", t);
-                }
+        for (Control control : getControls()) {
+            try {
+                control.onDestroy();
+            } catch (Throwable t) {
+                ClickUtils.getLogService().error("onDestroy error", t);
             }
         }
     }
@@ -252,11 +244,8 @@
     */
     public void onInit() {
         super.onInit();
-        if (hasControls()) {
-            for (int i = 0, size = getControls().size(); i < size; i++) {
-                Control control = (Control) getControls().get(i);
-                control.onInit();
-            }
+        for (Control control : getControls()) {
+            control.onInit();
         }
     }
 
@@ -264,11 +253,8 @@
     * @see org.apache.click.Control#onRender()
     */
     public void onRender() {
-        if (hasControls()) {
-            for (int i = 0, size = getControls().size(); i < size; i++) {
-                Control control = (Control) getControls().get(i);
-                control.onRender();
-            }
+        for (Control control : getControls()) {
+            control.onRender();
         }
     }
 
@@ -283,8 +269,7 @@
     public String getHtmlImports() {
         if (hasControls()) {
             HtmlStringBuffer buffer = new HtmlStringBuffer(0);
-            for (int i = 0, size = getControls().size(); i < size; i++) {
-                Control control = (Control) getControls().get(i);
+            for (Control control : getControls()) {
                 String htmlImports = control.getHtmlImports();
                 if (htmlImports != null) {
                     buffer.append(htmlImports);
@@ -342,7 +327,7 @@
         return buffer.toString();
     }
 
-    // ------------------------------------------------------ Protected Methods
+    // Protected Methods ------------------------------------------------------
 
     /**
      * @see AbstractControl#renderTagEnd(java.lang.String, org.apache.click.util.HtmlStringBuffer).
@@ -371,17 +356,14 @@
      * @param buffer the buffer to append the output to
      */
     protected void renderChildren(HtmlStringBuffer buffer) {
-        if (hasControls()) {
-            for (int i = 0; i < getControls().size(); i++) {
-                Control control = (Control) getControls().get(i);
+        for (Control control : getControls()) {
 
-                int before = buffer.length();
-                control.render(buffer);
+            int before = buffer.length();
+            control.render(buffer);
 
-                int after = buffer.length();
-                if (before != after) {
-                    buffer.append("\n");
-                }
+            int after = buffer.length();
+            if (before != after) {
+                buffer.append("\n");
             }
         }
     }

Modified: click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java?rev=916580&r1=916579&r2=916580&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java Fri Feb 26 06:22:44 2010
@@ -32,11 +32,12 @@
 
 import javax.servlet.ServletContext;
 
+import org.apache.click.ActionEventDispatcher;
 import org.apache.click.ActionListener;
 import org.apache.click.Context;
 import org.apache.click.Control;
-import org.apache.click.ActionEventDispatcher;
 import org.apache.click.Page;
+import org.apache.click.element.Element;
 import org.apache.click.util.ActionListenerAdaptor;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
@@ -121,11 +122,11 @@
  */
 public abstract class AbstractControl implements Control {
 
-    // -------------------------------------------------------------- Constants
+    // Constants --------------------------------------------------------------
 
     private static final long serialVersionUID = 1L;
 
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /** The control's action listener. */
     protected ActionListener actionListener;
@@ -134,13 +135,13 @@
      * The list of page HTML HEAD elements including: Javascript imports,
      * Css imports, inline Javascript and inline Css.
      */
-    protected List headElements;
+    protected List<Element> headElements;
 
     /** The Control attributes Map. */
-    protected Map attributes;
+    protected Map<String, String> attributes;
 
     /** The Control localized messages Map. */
-    protected transient Map messages;
+    protected transient Map<String, String> messages;
 
     /** The Control name. */
     protected String name;
@@ -154,7 +155,7 @@
      * @deprecated use {@link #addStyleClass(String)} and
      * {@link #removeStyleClass(String)} instead.
      */
-    protected Map styles;
+    protected Map<String, String> styles;
 
     /** The listener target object. */
     protected Object listener;
@@ -162,7 +163,7 @@
     /** The listener method name. */
     protected String listenerMethod;
 
-    // ---------------------------------------------------- Public Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Create a control with no name defined.
@@ -181,7 +182,7 @@
         }
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * Returns the controls html tag.
@@ -280,9 +281,9 @@
      *
      * @return the control's attributes Map.
      */
-    public Map getAttributes() {
+    public Map<String, String> getAttributes() {
         if (attributes == null) {
-            attributes = new HashMap();
+            attributes = new HashMap<String, String>();
         }
         return attributes;
     }
@@ -446,7 +447,7 @@
      * @return a Map of localized messages for the control
      * @throws IllegalStateException if the context for the control has not be set
      */
-    public Map getMessages() {
+    public Map<String, String> getMessages() {
         if (messages == null) {
             messages = new MessagesMap(getClass(), CONTROL_MESSAGES);
         }
@@ -566,11 +567,11 @@
      *
      * @return the list of HEAD elements to be included in the page
      */
-    public List getHeadElements() {
+    public List<Element> getHeadElements() {
         if (headElements == null) {
             // Most controls won't provide their own head elements, so save
             // memory by creating an empty array list
-            headElements = new ArrayList(0);
+            headElements = new ArrayList<Element>(0);
         }
         return headElements;
     }
@@ -593,8 +594,8 @@
     public String getStyle(String name) {
         if (hasAttribute("style")) {
             String currentStyles = getAttribute("style");
-            Map stylesMap = parseStyles(currentStyles);
-            return (String) stylesMap.get(name);
+            Map<String, String> stylesMap = parseStyles(currentStyles);
+            return stylesMap.get(name);
         } else {
             return null;
         }
@@ -619,6 +620,7 @@
      * @param name the CSS style name
      * @param value the CSS style value
      */
+    @SuppressWarnings("unchecked")
     public void setStyle(String name, String value) {
         if (name == null) {
             throw new IllegalArgumentException("Null name parameter");
@@ -643,7 +645,7 @@
             oldStyles.length() + 10);
 
         //Parse the current styles into a map
-        Map stylesMap = parseStyles(oldStyles);
+        Map<String, String> stylesMap = parseStyles(oldStyles);
 
         //Check if the new style is already present
         if (stylesMap.containsKey(name)) {
@@ -697,9 +699,9 @@
      *
      * @return the Map of control CSS styles
      */
-    public Map getStyles() {
+    public Map<String, String> getStyles() {
         if (styles == null) {
-            styles = new HashMap();
+            styles = new HashMap<String, String>();
         }
         return styles;
     }
@@ -774,7 +776,7 @@
 
             // If the class does exist, parse the class attributes into a set
             // and remove the specified class
-            Set styleClassSet = parseStyleClasses(oldStyleClasses);
+            Set<String> styleClassSet = parseStyleClasses(oldStyleClasses);
             styleClassSet.remove(value);
 
             if (styleClassSet.isEmpty()) {
@@ -788,9 +790,9 @@
                     oldStyleClasses.length() + value.length());
 
                 // Iterate over the styleClassSet appending each entry to buffer
-                Iterator it = styleClassSet.iterator();
+                Iterator<String> it = styleClassSet.iterator();
                 while (it.hasNext()) {
-                    String entry = (String) it.next();
+                    String entry = it.next();
                     buffer.append(entry);
                     if (it.hasNext()) {
                         buffer.append(" ");
@@ -839,7 +841,7 @@
         return buffer.toString();
     }
 
-    // ------------------------------------------------------ Protected Methods
+    // Protected Methods ------------------------------------------------------
 
     /**
      * Dispatch an ActionListener event with the {@link org.apache.click.ActionEventDispatcher}.
@@ -932,7 +934,7 @@
         return size;
     }
 
-    // -------------------------------------------------------- Private Methods
+    // Private Methods --------------------------------------------------------
 
     /**
      * Parse the specified string of style attributes and return a Map
@@ -943,7 +945,7 @@
      * @return map containing key/value pairs of the specified style
      * @throws IllegalArgumentException if style is null
      */
-    private Map parseStyles(String style) {
+    private Map<String, String> parseStyles(String style) {
         if (style == null) {
             throw new IllegalArgumentException("style cannot be null");
         }
@@ -951,7 +953,7 @@
         //LinkHashMap is used to keep the order of the style names. Probably
         //makes no difference to browser but it makes testing easier since the
         //order that styles are added are kept when rendering the control.
-        Map stylesMap = new LinkedHashMap();
+        Map<String, String> stylesMap = new LinkedHashMap<String, String>();
         StringTokenizer tokens = new StringTokenizer(style, ";");
         while (tokens.hasMoreTokens()) {
             String token = tokens.nextToken();
@@ -983,7 +985,7 @@
      * @return map containing key/value pairs of the specified style
      * @throws IllegalArgumentException if styleClasses is null
      */
-    private Set parseStyleClasses(String styleClasses) {
+    private Set<String> parseStyleClasses(String styleClasses) {
         if (styleClasses == null) {
             throw new IllegalArgumentException("styleClasses cannot be null");
         }
@@ -992,7 +994,7 @@
         //makes no difference to browser but it makes testing easier since the
         //order that classes were added in, are kept when rendering the control.
         //Thus one can test whether the expected result and actual result match.
-        Set styleClassesSet = new LinkedHashSet();
+        Set<String> styleClassesSet = new LinkedHashSet<String>();
         StringTokenizer tokens = new StringTokenizer(styleClasses, " ");
         while (tokens.hasMoreTokens()) {
             String token = tokens.nextToken();

Modified: click/trunk/click/framework/src/org/apache/click/control/Container.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Container.java?rev=916580&r1=916579&r2=916580&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Container.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Container.java Fri Feb 26 06:22:44 2010
@@ -72,7 +72,7 @@
      *
      * @return the sequential list of controls held by the container
      */
-    List getControls();
+    List<Control> getControls();
 
     /**
      * Return the named control from the container if found or null otherwise.

Modified: click/trunk/click/framework/src/org/apache/click/control/Field.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Field.java?rev=916580&r1=916579&r2=916580&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Field.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Field.java Fri Feb 26 06:22:44 2010
@@ -180,6 +180,10 @@
  * </dl>
  */
 public abstract class Field extends AbstractControl {
+    
+    // -------------------------------------------------------------- Constants
+
+    private static final long serialVersionUID = 1L;
 
     // ----------------------------------------------------- Instance Variables
 

Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Table.java?rev=916580&r1=916579&r2=916580&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Table.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Table.java Fri Feb 26 06:22:44 2010
@@ -30,7 +30,6 @@
 import org.apache.click.Control;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 
@@ -383,6 +382,9 @@
     /** The table HTML &lt;td&gt; height attribute. */
     protected String height;
 
+    /** The table data provider. */
+    protected CachingDataProvider dataProvider;
+
     /**
      * The table rows set 'hover' CSS class on mouseover events flag. By default
      * hoverRows is false.
@@ -426,11 +428,11 @@
      */
     protected boolean renderId;
 
-    /**
-     * The list Table rows. Please note the rowList is cleared in table
-     * {@link #onDestroy()} method at the end of each request.
-     */
-    protected List rowList;
+//    /**
+//     * The list Table rows. Please note the rowList is cleared in table
+//     * {@link #onDestroy()} method at the end of each request.
+//     */
+//    protected List rowList;
 
     /**
      * The show table banner flag detailing number of rows and rows
@@ -744,6 +746,35 @@
     }
 
     /**
+     * Return the table row list DataProvider.
+     *
+     * @return the table row list DataProvider
+     */
+    public DataProvider getDataProvider() {
+        return dataProvider;
+    }
+
+    /**
+     * Set the table row list DataProvider.
+     *
+     * @param dataProvider the table row list DataProvider
+     */
+    public void setDataProvider(DataProvider dataProvider) {
+        if (dataProvider != null) {
+
+            if (dataProvider instanceof CachingDataProvider) {
+                this.dataProvider = (CachingDataProvider) dataProvider;
+
+            } else {
+                this.dataProvider = new CachingDataProvider(dataProvider);
+            }
+
+        } else {
+            this.dataProvider = null;
+        }
+    }
+
+    /**
      * Return the table HTML &lt;td&gt; height attribute.
      *
      * @return the table HTML &lt;td&gt; height attribute
@@ -993,11 +1024,12 @@
      * @return the list of table rows
      */
     public List getRowList() {
-        if (rowList == null) {
-            rowList = new ArrayList(0);
-        }
+        if (dataProvider != null) {
+            return dataProvider.getData();
 
-        return rowList;
+        } else {
+            return Collections.EMPTY_LIST;
+        }
     }
 
     /**
@@ -1010,7 +1042,7 @@
      * @param rowList the list of table rows to set
      */
     public void setRowList(List rowList) {
-        this.rowList = rowList;
+        this.dataProvider = new CachingDataProvider(rowList);
     }
 
     /**
@@ -1262,7 +1294,7 @@
             }
         }
         if (getNullifyRowListOnDestroy()) {
-            setRowList(null);
+            getRowList().clear();
         }
     }