Reviewers: jlabanca, sbrubaker,

Description:
Issues 6206 and 6216: CellWidget's getValue is never updated by the Cell

Issue 6206: CellWidget should be IsEditor<TakesValueEditor<C>>
http://code.google.com/p/google-web-toolkit/issues/detail?id=6206
I made it a IsEditor<LeafValueEditor<C>> instead (backed by a
TakesValueEditor as an implementation detail). I'm not aware of any rule
about the parameterization to use for IsEditor<> so I picked one
(TakesValueEditor is an adapter to easily turn a TakesValue into a
LeadValueEditor, so it probably should only be an implementation detail)

Issue 6216: CellWidget's getValue is never updated by the Cell
http://code.google.com/p/google-web-toolkit/issues/detail?id=6216

Please review this at http://gwt-code-reviews.appspot.com/1400802/

Affected files:
  M user/src/com/google/gwt/user/cellview/CellView.gwt.xml
  M user/src/com/google/gwt/user/cellview/client/CellWidget.java
  M user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java


Index: user/src/com/google/gwt/user/cellview/CellView.gwt.xml
diff --git a/user/src/com/google/gwt/user/cellview/CellView.gwt.xml b/user/src/com/google/gwt/user/cellview/CellView.gwt.xml index ec6bcf2fe5767aea8b83cc167b2a227ab7a20874..3c8d066206872054e028c509653c1ff6d90eb766 100644
--- a/user/src/com/google/gwt/user/cellview/CellView.gwt.xml
+++ b/user/src/com/google/gwt/user/cellview/CellView.gwt.xml
@@ -16,6 +16,7 @@
 <module>
    <inherits name="com.google.gwt.user.User"/>
    <inherits name="com.google.gwt.cell.Cell"/>
+   <inherits name="com.google.gwt.editor.Editor"/>
    <inherits name="com.google.gwt.view.View"/>
    <inherits name="com.google.gwt.user.UserAgent"/>
    <source path="client"/>
Index: user/src/com/google/gwt/user/cellview/client/CellWidget.java
diff --git a/user/src/com/google/gwt/user/cellview/client/CellWidget.java b/user/src/com/google/gwt/user/cellview/client/CellWidget.java index 2a1ab4d46eccd62765175c02212d6d0a040db8b4..270f79aa74ae4e78c1f79f77cadfed75ada19f2c 100644
--- a/user/src/com/google/gwt/user/cellview/client/CellWidget.java
+++ b/user/src/com/google/gwt/user/cellview/client/CellWidget.java
@@ -21,6 +21,9 @@ import com.google.gwt.cell.client.ValueUpdater;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.editor.client.IsEditor;
+import com.google.gwt.editor.client.LeafValueEditor;
+import com.google.gwt.editor.client.adapters.TakesValueEditor;
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 import com.google.gwt.event.shared.HandlerRegistration;
@@ -37,7 +40,8 @@ import com.google.gwt.view.client.ProvidesKey;
  *
  * @param <C> the type that the Cell represents
  */
-public class CellWidget<C> extends Widget implements HasKeyProvider<C>, HasValue<C> { +public class CellWidget<C> extends Widget implements HasKeyProvider<C>, HasValue<C>,
+    IsEditor<LeafValueEditor<C>> {

   /**
* Create the default element used to wrap the Cell. The default element is a @@ -57,6 +61,11 @@ public class CellWidget<C> extends Widget implements HasKeyProvider<C>, HasValue
   private final Cell<C> cell;

   /**
+   * For use with the editor framework.
+   */
+  private LeafValueEditor<C> editor;
+
+  /**
    * The key provider for the value.
    */
   private final ProvidesKey<C> keyProvider;
@@ -71,7 +80,8 @@ public class CellWidget<C> extends Widget implements HasKeyProvider<C>, HasValue
    */
   private final ValueUpdater<C> valueUpdater = new ValueUpdater<C>() {
     public void update(C value) {
-      ValueChangeEvent.fire(CellWidget.this, value);
+      // no need to redraw, the Cell took care of it
+      setValue(value, true, false);
     }
   };

@@ -140,6 +150,14 @@ public class CellWidget<C> extends Widget implements HasKeyProvider<C>, HasValue
     return addHandler(handler, ValueChangeEvent.getType());
   }

+  @Override
+  public LeafValueEditor<C> asEditor() {
+    if (editor == null) {
+      editor = TakesValueEditor.of(this);
+    }
+    return editor;
+  }
+
   /**
    * Get the {@link Cell} wrapped by this widget.
    *
Index: user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
diff --git a/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java b/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java index 8a848e67dfbfe4148cbd5acf1944e6d5bca20810..5b400f856cb53af221861d11ab6e0b073c235738 100644
--- a/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
+++ b/user/test/com/google/gwt/user/cellview/client/CellWidgetTest.java
@@ -117,6 +117,7 @@ public class CellWidgetTest extends GWTTestCase {
     cw.onBrowserEvent(event);
     cell.assertLastEventKey("test");
     cell.assertLastEventValue("test");
+    assertEquals("newValue", cw.getValue());
   }

   public void testOnBrowserEventWithKeyProvider() {
@@ -135,6 +136,7 @@ public class CellWidgetTest extends GWTTestCase {
     cw.onBrowserEvent(event);
     cell.assertLastEventKey("t");
     cell.assertLastEventValue("test");
+    assertEquals("newValue", cw.getValue());
   }

   public void testOnBrowserEventWithValueChangeHandler() {
@@ -152,6 +154,7 @@ public class CellWidgetTest extends GWTTestCase {
     cell.assertLastEventKey("test");
     cell.assertLastEventValue("test");
     handler.assertLastValue("newValue");
+    assertEquals("newValue", cw.getValue());
   }

   /**


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to