Author: knopp
Date: Wed May  7 02:36:01 2008
New Revision: 654055

URL: http://svn.apache.org/viewvc?rev=654055&view=rev
Log:
WICKET-1366

Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java?rev=654055&r1=654054&r2=654055&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java 
(original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxRequestTarget.java 
Wed May  7 02:36:01 2008
@@ -20,11 +20,13 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.wicket.Application;
 import org.apache.wicket.Component;
@@ -485,10 +487,46 @@
        }
 
        /**
+        * Components can implement this interface to get a notification when 
AjaxRequestTarget begins
+        * to respond. This can be used to postpone adding components to 
AjaxRequestTarget until the
+        * response begins.
+        * 
+        * @author Matej Knopp
+        */
+       public static interface ITargetRespondListener
+       {
+               /**
+                * Invoked when AjaxRequestTarget is about the respond.
+                * 
+                * @param target
+                */
+               public void onTargetRespond(AjaxRequestTarget target);
+       };
+
+       private Set<ITargetRespondListener> respondListeners = new 
HashSet<ITargetRespondListener>();
+
+       /**
+        * Register the given respond listener. The listener's
+        * [EMAIL PROTECTED] 
ITargetRespondListener#onTargetRespond(AjaxRequestTarget)} method will be 
invoked
+        * when the [EMAIL PROTECTED] AjaxRequestTarget} starts to respond.
+        * 
+        * @param listener
+        */
+       public void registerRespondListener(ITargetRespondListener listener)
+       {
+               respondListeners.add(listener);
+       }
+
+       /**
         * @see 
org.apache.wicket.IRequestTarget#respond(org.apache.wicket.RequestCycle)
         */
        public final void respond(final RequestCycle requestCycle)
        {
+               for (ITargetRespondListener listener : respondListeners)
+               {
+                       listener.onTargetRespond(this);
+               }
+               
                final Application app = Application.get();
 
                // Determine encoding

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java?rev=654055&r1=654054&r2=654055&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/tree/AbstractTree.java
 Wed May  7 02:36:01 2008
@@ -52,7 +52,7 @@
  * 
  * @author Matej Knopp
  */
-public abstract class AbstractTree extends Panel implements 
ITreeStateListener, TreeModelListener
+public abstract class AbstractTree extends Panel implements 
ITreeStateListener, TreeModelListener, AjaxRequestTarget.ITargetRespondListener
 {
 
        /**
@@ -876,23 +876,8 @@
                target.addComponent(component);
        }
 
-       /**
-        * Updates the changed portions of the tree using given 
AjaxRequestTarget. Call this method if
-        * you modified the tree model during an ajax request target and you 
want to partially update
-        * the component on page. Make sure that the tree model has fired the 
proper listener functions.
-        * <p>
-        * <b>You can only call this method once in a request.</b>
-        * 
-        * @param target
-        *            Ajax request target used to send the update to the page
-        */
-       public final void updateTree(final AjaxRequestTarget target)
+       public void onTargetRespond(AjaxRequestTarget target)
        {
-               if (target == null)
-               {
-                       return;
-               }
-
                // check whether the model hasn't changed
                checkModel();
 
@@ -990,6 +975,26 @@
                        updated();
                }
        }
+       
+       /**
+        * Updates the changed portions of the tree using given 
AjaxRequestTarget. Call this method if
+        * you modified the tree model during an ajax request target and you 
want to partially update
+        * the component on page. Make sure that the tree model has fired the 
proper listener functions.
+        * <p>
+        * <b>You can only call this method once in a request.</b>
+        * 
+        * @param target
+        *            Ajax request target used to send the update to the page
+        */
+       public final void updateTree(final AjaxRequestTarget target)
+       {
+               if (target == null)
+               {
+                       return;
+               }
+
+               target.registerRespondListener(this);
+       }
 
        /**
         * Returns whether the given node is expanded.


Reply via email to