Revision: 9413
Author: [email protected]
Date: Mon Dec 13 11:55:24 2010
Log: CellWidget should only fire a ValueChangeEvent when the new value is
not equal to the previous one. The redraw logic should do the same. If you
really want to redraw the widget unconditionally, call setValue(a, b,
false) and then redraw()).
Code Review at http://gwt-code-reviews.appspot.com/1155801/show
Author: tbroyer
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9413
Modified:
/trunk/user/src/com/google/gwt/user/cellview/client/CellWidget.java
/trunk/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellWidget.java Wed
Dec 1 05:40:20 2010
+++ /trunk/user/src/com/google/gwt/user/cellview/client/CellWidget.java Mon
Dec 13 11:55:24 2010
@@ -183,7 +183,8 @@
/**
* {...@inheritdoc}
* <p>
- * This method will redraw the widget using the new value.
+ * This method will redraw the widget if the new value does not equal the
+ * existing value.
* </p>
*/
public void setValue(C value) {
@@ -193,7 +194,8 @@
/**
* {...@inheritdoc}
* <p>
- * This method will redraw the widget using the new value.
+ * This method will redraw the widget if the new value does not equal the
+ * existing value.
* </p>
*/
public void setValue(C value, boolean fireEvents) {
@@ -204,18 +206,23 @@
* Sets this object's value and optionally redraw the widget. Fires
* {...@link com.google.gwt.event.logical.shared.ValueChangeEvent} when
* fireEvents is true and the new value does not equal the existing
value.
+ * Redraws the widget when redraw is true and the new value does not
equal the
+ * existing value.
*
* @param value the object's new value
* @param fireEvents fire events if true and value is new
- * @param redraw true to redraw the widget, false not to
+ * @param redraw redraw the widget if true and value is new
*/
public void setValue(C value, boolean fireEvents, boolean redraw) {
- this.value = value;
- if (redraw) {
- redraw();
- }
- if (fireEvents) {
- ValueChangeEvent.fire(this, value);
+ C oldValue = getValue();
+ if (value != oldValue && (oldValue == null |
| !oldValue.equals(value))) {
+ this.value = value;
+ if (redraw) {
+ redraw();
+ }
+ if (fireEvents) {
+ ValueChangeEvent.fire(this, value);
+ }
}
}
=======================================
---
/trunk/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
Wed Dec 1 05:40:20 2010
+++
/trunk/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
Mon Dec 13 11:55:24 2010
@@ -181,6 +181,10 @@
assertEquals("test0", cw.getElement().getInnerText());
handler.assertOnValueChangeNotCalled();
+ // Set value to the existing value, shouldn't fire events.
+ cw.setValue("test0", true);
+ handler.assertOnValueChangeNotCalled();
+
// Set value and fire events.
cw.setValue("test1", true);
assertEquals("test1", cw.getValue());
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors