click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r962521 - in /click/trunk/click: extras/src/org/apache/click/extras/panel/ framework/src/org/apache/click/ framework/src/org/apache/click/control/
Date Fri, 09 Jul 2010 13:32:52 GMT
Author: sabob
Date: Fri Jul  9 13:32:52 2010
New Revision: 962521

URL: http://svn.apache.org/viewvc?rev=962521&view=rev
Log:
Converted Behavior List to a Set. Renamed registerBehavior to registerAjaxTarget

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java
    click/trunk/click/framework/src/org/apache/click/CallbackDispatcher.java
    click/trunk/click/framework/src/org/apache/click/ClickServlet.java
    click/trunk/click/framework/src/org/apache/click/Control.java
    click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java?rev=962521&r1=962520&r2=962521&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java Fri Jul  9
13:32:52 2010
@@ -409,7 +409,7 @@ public class TabbedPanel extends Panel {
     @Override
     public void onInit() {
         if (hasBehaviors()) {
-            CallbackDispatcher.registerBehavior(this);
+            CallbackDispatcher.registerAjaxTarget(this);
         }
 
         initActivePanel();

Modified: click/trunk/click/framework/src/org/apache/click/CallbackDispatcher.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/CallbackDispatcher.java?rev=962521&r1=962520&r2=962521&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/CallbackDispatcher.java (original)
+++ click/trunk/click/framework/src/org/apache/click/CallbackDispatcher.java Fri Jul  9 13:32:52
2010
@@ -27,7 +27,7 @@ import org.apache.click.service.LogServi
 import org.apache.commons.lang.Validate;
 
 /**
- * Provides a Control event callback dispatcher.
+ * Provides a registry for Controls.
  *
  * TODO: javadoc
  */
@@ -36,13 +36,13 @@ public class CallbackDispatcher {
     // Constants --------------------------------------------------------------
 
     /** The thread local dispatcher holder. */
-    private static final ThreadLocal<DispatcherStack> THREAD_LOCAL_DISPATCHER =
-                    new ThreadLocal<DispatcherStack>();
+    private static final ThreadLocal<RegistryStack> THREAD_LOCAL_REGISTRY =
+                    new ThreadLocal<RegistryStack>();
 
     // Variables --------------------------------------------------------------
 
-    /** The set of registered behavior enabled controls. */
-    Set<Control> behaviorEnabledControls;
+    /** The set of Ajax target controls. */
+    Set<Control> ajaxTargetControls;
 
     /** The list of registered callbacks. */
     List<CallbackHolder> callbacks;
@@ -58,9 +58,17 @@ public class CallbackDispatcher {
 
     // Public Methods ---------------------------------------------------------
 
-    public static void registerBehavior(Control control) {
+    /**
+     * Register the control to be processed by the ClickServlet if the control
+     * is the Ajax target. A control is an Ajax target if the
+     * {@link Control#isAjaxTarget(org.apache.click.Context)} method returns true.
+     * Target controls have their {@link Control#onProcess()} method invoked.
+     *
+     * @param control the control to register
+     */
+    public static void registerAjaxTarget(Control control) {
         CallbackDispatcher instance = getThreadLocalDispatcher();
-        instance.internalRegisterBehavior(control);
+        instance.internalRegisterAjaxTarget(control);
     }
 
     public static void registerCallback(Control control, Callback callback) {
@@ -89,19 +97,19 @@ public class CallbackDispatcher {
             getCallbacks().clear();
         }
 
-        if (hasBehaviorEnabledControls()) {
-            getBehaviorEnabledControls().clear();
+        if (hasAjaxTargetControls()) {
+            getAjaxTargetControls().clear();
         }
     }
 
     /**
-     * Register the behavior source control.
+     * Register the ajax target control.
      *
-     * @param source the behavior source control
+     * @param control the ajax target control
      */
-    void internalRegisterBehavior(Control source) {
-        Validate.notNull(source, "Null source parameter");
-        getBehaviorEnabledControls().add(source);
+    void internalRegisterAjaxTarget(Control control) {
+        Validate.notNull(control, "Null control parameter");
+        getAjaxTargetControls().add(control);
     }
 
     /**
@@ -118,10 +126,9 @@ public class CallbackDispatcher {
     }
 
     void processPreResponse(Context context) {
-        if (hasBehaviorEnabledControls()) {
-            for (Control control : getBehaviorEnabledControls()) {
-                List<Behavior> behaviors = control.getBehaviors();
-                for (Behavior behavior : behaviors) {
+        if (hasAjaxTargetControls()) {
+            for (Control control : getAjaxTargetControls()) {
+                for (Behavior behavior : control.getBehaviors()) {
                     behavior.preResponse(control);
                 }
             }
@@ -137,10 +144,9 @@ public class CallbackDispatcher {
     }
 
     void processPreGetHeadElements(Context context) {
-        if (hasBehaviorEnabledControls()) {
-            for (Control control : getBehaviorEnabledControls()) {
-                List<Behavior> behaviors = control.getBehaviors();
-                for (Behavior behavior : behaviors) {
+        if (hasAjaxTargetControls()) {
+            for (Control control : getAjaxTargetControls()) {
+                for (Behavior behavior : control.getBehaviors()) {
                     behavior.preGetHeadElements(control);
                 }
             }
@@ -156,10 +162,9 @@ public class CallbackDispatcher {
     }
 
     void processPreDestroy(Context context) {
-        if (hasBehaviorEnabledControls()) {
-            for (Control control : getBehaviorEnabledControls()) {
-                List<Behavior> behaviors = control.getBehaviors();
-                for (Behavior behavior : behaviors) {
+        if (hasAjaxTargetControls()) {
+            for (Control control : getAjaxTargetControls()) {
+                for (Behavior behavior : control.getBehaviors()) {
                     behavior.preDestroy(control);
                 }
             }
@@ -177,8 +182,8 @@ public class CallbackDispatcher {
     /**
      * Checks if any control callbacks have been registered.
      */
-    boolean hasBehaviorEnabledControls() {
-        if (behaviorEnabledControls == null || behaviorEnabledControls.isEmpty()) {
+    boolean hasAjaxTargetControls() {
+        if (ajaxTargetControls == null || ajaxTargetControls.isEmpty()) {
             return false;
         }
         return true;
@@ -189,11 +194,11 @@ public class CallbackDispatcher {
      *
      * @return the set of behavior enabled controls.
      */
-    Set<Control> getBehaviorEnabledControls() {
-        if (behaviorEnabledControls == null) {
-            behaviorEnabledControls = new LinkedHashSet<Control>();
+    Set<Control> getAjaxTargetControls() {
+        if (ajaxTargetControls == null) {
+            ajaxTargetControls = new LinkedHashSet<Control>();
         }
-        return behaviorEnabledControls;
+        return ajaxTargetControls;
     }
 
     /**
@@ -238,22 +243,22 @@ public class CallbackDispatcher {
      * @return the callbackDispatcher instance on top of the dispatcher stack
      */
     static CallbackDispatcher popThreadLocalDispatcher() {
-        DispatcherStack dispatcherStack = getDispatcherStack();
-        CallbackDispatcher callbackDispatcher = dispatcherStack.pop();
+        RegistryStack registryStack = getDispatcherStack();
+        CallbackDispatcher callbackDispatcher = registryStack.pop();
 
-        if (dispatcherStack.isEmpty()) {
-            THREAD_LOCAL_DISPATCHER.set(null);
+        if (registryStack.isEmpty()) {
+            THREAD_LOCAL_REGISTRY.set(null);
         }
 
         return callbackDispatcher;
     }
 
-    static DispatcherStack getDispatcherStack() {
-        DispatcherStack dispatcherStack = THREAD_LOCAL_DISPATCHER.get();
+    static RegistryStack getDispatcherStack() {
+        RegistryStack dispatcherStack = THREAD_LOCAL_REGISTRY.get();
 
         if (dispatcherStack == null) {
-            dispatcherStack = new DispatcherStack(2);
-            THREAD_LOCAL_DISPATCHER.set(dispatcherStack);
+            dispatcherStack = new RegistryStack(2);
+            THREAD_LOCAL_REGISTRY.set(dispatcherStack);
         }
 
         return dispatcherStack;
@@ -262,7 +267,7 @@ public class CallbackDispatcher {
     /**
      * Provides an unsynchronized Stack.
      */
-    static class DispatcherStack extends ArrayList<CallbackDispatcher> {
+    static class RegistryStack extends ArrayList<CallbackDispatcher> {
 
         /** Serialization version indicator. */
         private static final long serialVersionUID = 1L;
@@ -272,7 +277,7 @@ public class CallbackDispatcher {
          *
          * @param initialCapacity specify initial capacity of this stack
          */
-        private DispatcherStack(int initialCapacity) {
+        private RegistryStack(int initialCapacity) {
             super(initialCapacity);
         }
 

Modified: click/trunk/click/framework/src/org/apache/click/ClickServlet.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/ClickServlet.java?rev=962521&r1=962520&r2=962521&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/ClickServlet.java (original)
+++ click/trunk/click/framework/src/org/apache/click/ClickServlet.java Fri Jul  9 13:32:52
2010
@@ -1810,7 +1810,7 @@ public class ClickServlet extends HttpSe
 
             // TODO: Ajax doesn't support forward. Is it still necessary to
             // check isForward?
-            if (callbackDispatcher.hasBehaviorEnabledControls() && !context.isForward())
{
+            if (callbackDispatcher.hasAjaxTargetControls() && !context.isForward())
{
 
                 // Perform onProcess for regsitered Ajax controls
                 processAjaxControls(context, eventDispatcher, callbackDispatcher);
@@ -1869,20 +1869,20 @@ public class ClickServlet extends HttpSe
 
         if (logger.isTraceEnabled()) {
             logger.trace("   the following controls have been registered as potential Ajax
targets:");
-            if (callbackDispatcher.getBehaviorEnabledControls().isEmpty()) {
-                logger.trace("      *no* control has been registered");
-            } else {
-                for (Control control : callbackDispatcher.getBehaviorEnabledControls()) {
+            if (!callbackDispatcher.hasAjaxTargetControls()) {
+                for (Control control : callbackDispatcher.getAjaxTargetControls()) {
                     HtmlStringBuffer buffer = new HtmlStringBuffer();
                     String controlClassName = ClassUtils.getShortClassName(control.getClass());
                     buffer.append("      ").append(controlClassName);
                     buffer.append(": name='").append(control.getName()).append("'");
                     logger.trace(buffer.toString());
                 }
+            } else {
+                logger.trace("      *no* control has been registered");
             }
         }
 
-        for (Control control : callbackDispatcher.getBehaviorEnabledControls()) {
+        for (Control control : callbackDispatcher.getAjaxTargetControls()) {
 
             if (control.isAjaxTarget(context)) {
                 ajaxTarget = control;

Modified: click/trunk/click/framework/src/org/apache/click/Control.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/Control.java?rev=962521&r1=962520&r2=962521&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/Control.java (original)
+++ click/trunk/click/framework/src/org/apache/click/Control.java Fri Jul  9 13:32:52 2010
@@ -21,6 +21,7 @@ package org.apache.click;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.ServletContext;
 
@@ -469,16 +470,16 @@ public interface Control extends Seriali
      * <tt>Behavior</tt>s registered.
      *
      * @return <tt>true</tt> if this control has any
-     * <tt>Behavior</tt>s registered, <tt>false</tt> otherwise.
+     * <tt>Behavior</tt>s registered, <tt>false</tt> otherwise
      */
     public boolean hasBehaviors();
 
     /**
-     * Returns the list with all available behaviors for this control.
+     * Returns the list of behaviors for this control.
      *
-     * @return the list with this control's behaviors.
+     * @return the list with this control behaviors.
      */
-    public List<Behavior> getBehaviors();
+    public Set<Behavior> getBehaviors();
 
     /**
      * Returns <tt>true</tt> if this control is an AJAX target, <tt>false</tt>

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=962521&r1=962520&r2=962521&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 Jul
 9 13:32:52 2010
@@ -21,6 +21,7 @@ package org.apache.click.control;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -140,7 +141,7 @@ public abstract class AbstractControl im
     protected ActionListener actionListener;
 
     /** The control's list of {@link org.apache.click.Behavior behaviors}. */
-    protected List<Behavior> behaviors;
+    protected Set<Behavior> behaviors;
 
     /**
      * The list of page HTML HEAD elements including: Javascript imports,
@@ -251,16 +252,13 @@ public abstract class AbstractControl im
      * @param behavior the AJAX behavior
      */
     public void addBehavior(Behavior behavior) {
-        if (getBehaviors().contains(behavior)) {
-            return;
+        boolean added = getBehaviors().add(behavior);
+        if (added) {
+            // Register control here in case behavior was added *after* the onInit event.
+            // This can occur if the behavior is added in a listener event or during
+            // onRender.
+            CallbackDispatcher.registerAjaxTarget(this);
         }
-
-        getBehaviors().add(behavior);
-
-        // Register control here in case behavior was added *after* the onInit event.
-        // This can occur if the behavior is added in a listener event or during
-        // onRender.
-        CallbackDispatcher.registerBehavior(this);
     }
 
     /**
@@ -277,9 +275,9 @@ public abstract class AbstractControl im
      *
      * @return the list with this control's behaviors.
      */
-    public List<Behavior> getBehaviors() {
+    public Set<Behavior> getBehaviors() {
         if (behaviors == null) {
-            behaviors = new ArrayList<Behavior>();
+            behaviors = new HashSet<Behavior>();
         }
         return behaviors;
     }
@@ -594,7 +592,7 @@ public abstract class AbstractControl im
         //    to ensure this code is called *before* onProcess. Leaving the code
         //    here opens problems if subclass does not call super.onInit
         if (hasBehaviors()) {
-           CallbackDispatcher.registerBehavior(this);
+           CallbackDispatcher.registerAjaxTarget(this);
         }
     }
 



Mime
View raw message