You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/05/04 05:04:27 UTC
svn commit: r535063 - in /incubator/wicket/trunk/jdk-1.4/wicket/src:
main/java/org/apache/wicket/ test/java/org/apache/wicket/
test/java/org/apache/wicket/ajax/markup/html/ajaxLink/
test/java/org/apache/wicket/markup/html/debug/
Author: ivaynberg
Date: Thu May 3 20:04:27 2007
New Revision: 535063
URL: http://svn.apache.org/viewvc?view=rev&rev=535063
Log:
WICKET-529 : Add ability to remove behaviors
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html
incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html
incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html
incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html
incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/debug/WicketComponentTreeTestPage_ExpectedResult.html
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java?view=diff&rev=535063&r1=535062&r2=535063
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java Thu May 3 20:04:27 2007
@@ -315,6 +315,75 @@
}
/**
+ * Change object for undoing removal of behavior
+ *
+ * @author Igor Vaynberg (ivaynberg)
+ */
+ private final class RemovedBehaviorChange extends Change
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ private final IBehavior behavior;
+
+ /**
+ * Construct.
+ *
+ * @param behavior
+ */
+ public RemovedBehaviorChange(IBehavior behavior)
+ {
+ this.behavior = behavior;
+ }
+
+ public void undo()
+ {
+ add(behavior);
+ }
+
+ public String toString()
+ {
+ return "[" + getClass().getName() + " behavior=" + behavior.toString() + "]";
+ }
+
+ }
+
+ /**
+ * Change object for undoing addition of behavior
+ *
+ * @author Igor Vaynberg (ivaynberg)
+ */
+ private final class AddedBehaviorChange extends Change
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ private final IBehavior behavior;
+
+ /**
+ * Construct.
+ *
+ * @param behavior
+ */
+ public AddedBehaviorChange(IBehavior behavior)
+ {
+ this.behavior = behavior;
+ }
+
+ public void undo()
+ {
+ remove(behavior);
+ }
+
+ public String toString()
+ {
+ return "[" + getClass().getName() + " behavior=" + behavior.toString() + "]";
+ }
+
+ }
+
+
+ /**
* A enabled change operation.
*/
protected final static class EnabledChange extends Change
@@ -563,7 +632,7 @@
private static final long serialVersionUID = 1L;
/** List of behaviors to be applied for this Component */
- private List behaviors = null;
+ private ArrayList behaviors = null;
/** Component flags. See FLAG_* for possible non-exclusive flag values. */
private int flags = FLAG_VISIBLE | FLAG_ESCAPE_MODEL_STRINGS | FLAG_VERSIONED | FLAG_ENABLED
@@ -654,8 +723,44 @@
behaviors.add(behavior);
+ if (!behavior.isTemporary())
+ {
+ addStateChange(new AddedBehaviorChange(behavior));
+ }
+
// Give handler the opportunity to bind this component
behavior.bind(this);
+
+ return this;
+ }
+
+ /**
+ * Removes behavior from component
+ *
+ * @param behavior
+ * behavior to remove
+ *
+ * @return this (to allow method call chaining)
+ */
+ public Component remove(final IBehavior behavior)
+ {
+ if (behavior == null)
+ {
+ throw new IllegalArgumentException("Argument `behavior` cannot be null");
+ }
+ if (behaviors == null || !behaviors.contains(behavior) == false)
+ {
+ throw new IllegalStateException(
+ "Tried to remove a behavior that was not added to the component. Behavior: "
+ + behavior.toString());
+ }
+
+ if (!behavior.isTemporary())
+ {
+ addStateChange(new RemovedBehaviorChange(behavior));
+ }
+ behaviors.remove(behavior);
+
return this;
}
@@ -2924,6 +3029,10 @@
*/
protected void onDetach()
{
+ if (behaviors != null)
+ {
+ behaviors.trimToSize();
+ }
setFlag(FLAG_DETACHING, false);
}
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html?view=diff&rev=535063&r1=535062&r2=535063
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html Thu May 3 20:04:27 2007
@@ -7,6 +7,6 @@
<script type="text/javascript" src="resources/org.apache.wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug.js"></script>
</head><body>
- <span wicket:id="comp" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:comp::IBehaviorListener:0', function() { }, function() { });" id="comp0">body</span>
+ <span id="comp0" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:comp::IBehaviorListener:0', function() { }.bind(this), function() { }.bind(this));" wicket:id="comp">body</span>
</body>
</html>
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html?view=diff&rev=535063&r1=535062&r2=535063
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html Thu May 3 20:04:27 2007
@@ -8,6 +8,6 @@
<script type="text/javascript" src="resources/org.apache.wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug.js"></script>
</head><body>
<span wicket:id="ajaxLabel" id="ajaxLabel0">UpdateMe</span>
- <a href="#" wicket:id="ajaxLink" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:ajaxLink::IBehaviorListener:0', function() { }, function() { });return !wcall;" id="ajaxLink1">Update</a>
+ <a href="#" wicket:id="ajaxLink" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:ajaxLink::IBehaviorListener:0', function() { }.bind(this), function() { }.bind(this));return !wcall;" id="ajaxLink1">Update</a>
</body>
</html>
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html?view=diff&rev=535063&r1=535062&r2=535063
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html Thu May 3 20:04:27 2007
@@ -11,7 +11,7 @@
Border
<wicket:body>
<span wicket:id="ajaxLabel" id="ajaxLabel0">UpdateMe</span>
- <a href="#" wicket:id="ajaxLink" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:ajaxLink::IBehaviorListener:0', function() { }, function() { });return !wcall;" id="ajaxLink1">Update</a>
+ <a href="#" wicket:id="ajaxLink" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:ajaxLink::IBehaviorListener:0', function() { }.bind(this), function() { }.bind(this));return !wcall;" id="ajaxLink1">Update</a>
</wicket:body>
Border
</wicket:border></span>
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html?view=diff&rev=535063&r1=535062&r2=535063
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html Thu May 3 20:04:27 2007
@@ -16,7 +16,7 @@
<td width = "100%">
<wicket:body>
<span wicket:id="ajaxLabel" id="ajaxLabel0">AAAAAAA</span>
- <a href="#" wicket:id="ajaxLink" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:ajaxLink::IBehaviorListener:0', function() { }, function() { });return !wcall;" id="ajaxLink1">Update</a>
+ <a href="#" wicket:id="ajaxLink" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:ajaxLink::IBehaviorListener:0', function() { }.bind(this), function() { }.bind(this));return !wcall;" id="ajaxLink1">Update</a>
</wicket:body>
</td>
</tr>
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/debug/WicketComponentTreeTestPage_ExpectedResult.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/debug/WicketComponentTreeTestPage_ExpectedResult.html?view=diff&rev=535063&r1=535062&r2=535063
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/debug/WicketComponentTreeTestPage_ExpectedResult.html (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/html/debug/WicketComponentTreeTestPage_ExpectedResult.html Thu May 3 20:04:27 2007
@@ -34,13 +34,13 @@
<tr wicket:id="components">
<td valign="top" align="left"><span wicket:id="row">1</span> </td>
<td valign="top" align="left"><span wicket:id="path">label1</span> </td>
- <td valign="top" align="left" nowrap><span wicket:id="size">486 bytes</span> </td>
+ <td valign="top" align="left" nowrap><span wicket:id="size">491 bytes</span> </td>
<td valign="top" align="left"><span wicket:id="type">org.apache.wicket.markup.html.basic.Label</span> </td>
<td valign="top" align="left"><span wicket:id="model">test1</span> </td>
</tr><tr wicket:id="components">
<td valign="top" align="left"><span wicket:id="row">2</span> </td>
<td valign="top" align="left"><span wicket:id="path">label2</span> </td>
- <td valign="top" align="left" nowrap><span wicket:id="size">487 bytes</span> </td>
+ <td valign="top" align="left" nowrap><span wicket:id="size">492 bytes</span> </td>
<td valign="top" align="left"><span wicket:id="type">org.apache.wicket.markup.html.basic.Label</span> </td>
<td valign="top" align="left"><span wicket:id="model">test22</span> </td>
</tr>