Reviewers: rjrjr,

Description:
See one use-case in point 3 of
http://groups.google.fr/group/google-web-toolkit-contributors/msg/af8578d95692aff5

Another use case: "edit" and "details" of a proxy is based on the proxy
itself (it has an isReadOnly() property, and if it isn't read-only it's
always in "edit mode"). You can ask the server to "make the domain
object editable". So we'd have a read-only proxy displayed in the
current activity, and (from another activity, but that's an
implementation detail) the user asks to make it editable (it locks it on
the server so other users cannot edit it). An update event is dispatched
(by RequestFactory) so the current activity now needs to display the
proxy in "edit mode". Note that there hasn't been a place change, so
it's the same activity; we only want to switch from "read only mode" to
"edit mode", and the easiest is probably to switch views, by calling the
activity's display setWidget() once more.

Ray's answer:
http://groups.google.fr/group/google-web-toolkit-contributors/msg/e02de4378705c726
"""I don't see anything wrong with "redundant" calls to
showActivityWidget, and I think I was careful to make sure it wouldn't
break anything."""

So, this patch adds a unit-test to explicitly check that this is a
problem, and that it won't be in the future. The test is needed because
AcceptsOneWidget passed to the Activity by ActivityManager is not
directly the one you passed to its setDisplay() method, so
ActivityManager could (theoretically) evolve in the future and break
this use case, which isn't documented as being a "valid use case".

(the patch also "fixes" what looks like an oversight in
AsyncActivity#start)

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

Affected files:
  user/test/com/google/gwt/activity/shared/ActivityManagerTest.java


Index: user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
===================================================================
--- user/test/com/google/gwt/activity/shared/ActivityManagerTest.java (revision 9092) +++ user/test/com/google/gwt/activity/shared/ActivityManagerTest.java (working copy)
@@ -41,6 +41,7 @@
     @Override
     public void start(AcceptsOneWidget display, EventBus eventBus) {
       this.display = display;
+      this.bus = eventBus;
     }

     void finish() {
@@ -455,4 +456,51 @@
     assertTrue(activity1.stopped);
     assertFalse(activity1.canceled);
   }
+
+  /**
+ * Non-regression test: make sure an activity can call {...@link AcceptsOneWidget#setWidget(IsWidget)} several times to switch views.
+   */
+  public void testSetWidgetSeveralTimesPerActivity() {
+    class TwoViewActivity extends SyncActivity {
+      MyView view2;
+
+      public TwoViewActivity(MyView view1, MyView view2) {
+        super(view1);
+        this.view2 = view2;
+      }
+
+      void secondView() {
+        display.setWidget(view2);
+      }
+
+      void firstView() {
+        display.setWidget(view);
+      }
+    }
+ final TwoViewActivity activity = new TwoViewActivity(new MyView(), new MyView());
+
+    ActivityMapper map = new ActivityMapper() {
+      public Activity getActivity(Place place) {
+        return activity;
+      }
+    };
+
+    manager = new ActivityManager(map, eventBus);
+    manager.setDisplay(realDisplay);
+
+    // Start an activity
+    manager.onPlaceChange(new PlaceChangeEvent(place1));
+
+    assertEquals(activity.view, realDisplay.widget);
+
+ // Call setWidget on the display several times, just to make sure it's possible
+    activity.secondView();
+    assertEquals(activity.view2, realDisplay.widget);
+
+    activity.firstView();
+    assertEquals(activity.view, realDisplay.widget);
+
+    activity.secondView();
+    assertEquals(activity.view2, realDisplay.widget);
+  }
 }


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

Reply via email to