Thomas Broyer has uploaded a new change for review.

  https://gwt-review.googlesource.com/3185


Change subject: Add HasPaths interface.
......................................................................

Add HasPaths interface.

Bug: issue 6227
Change-Id: I2f259552d945bf22592c4395e3c7b2ad45bfe93c
---
A user/src/com/google/web/bindery/requestfactory/gwt/client/HasPaths.java
M user/src/com/google/web/bindery/requestfactory/gwt/client/impl/PathCollector.java M user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java
3 files changed, 65 insertions(+), 5 deletions(-)



diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/HasPaths.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/HasPaths.java
new file mode 100644
index 0000000..03b580f
--- /dev/null
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/HasPaths.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.web.bindery.requestfactory.gwt.client;
+
+import com.google.gwt.editor.client.Editor;
+
+/**
+ * Editors used with {@link RequestFactoryEditorDriver} that implement this interface will provide + * paths to {@link RequestFactoryEditorDriver#getPaths()} in addition to those collected from their
+ * sub-editors.
+ *
+ * @param <T> the type of data being edited
+ */
+public interface HasPaths<T> extends Editor<T> {
+
+  /**
+   * Called by {@link RequestFactoryEditorDriver} when collecting paths for
+   * {@link RequestFactoryEditorDriver#getPaths()}.
+   */
+  String[] getPaths();
+}
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/PathCollector.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/PathCollector.java
index ab4f8aa..a98f5ab 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/PathCollector.java +++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/PathCollector.java
@@ -15,9 +15,11 @@
  */
 package com.google.web.bindery.requestfactory.gwt.client.impl;

-import com.google.web.bindery.autobean.shared.ValueCodex;
+import com.google.gwt.editor.client.Editor;
 import com.google.gwt.editor.client.EditorContext;
 import com.google.gwt.editor.client.EditorVisitor;
+import com.google.web.bindery.autobean.shared.ValueCodex;
+import com.google.web.bindery.requestfactory.gwt.client.HasPaths;

 import java.util.ArrayList;
 import java.util.LinkedHashSet;
@@ -57,6 +59,16 @@
         paths.add(path);
       }
     }
+    Editor<?> editor = ctx.getEditor();
+    if (editor instanceof HasPaths<?>) {
+      String[] subpaths = ((HasPaths<?>) editor).getPaths();
+      if (subpaths != null) {
+        String prefix = path.length() > 0 ? path + "." : "";
+        for (String subpath : subpaths) {
+          paths.add(prefix + subpath);
+        }
+      }
+    }
     if (ctx.asCompositeEditor() != null) {
       ctx.traverseSyntheticCompositeEditor(this);
     }
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java
index ec6987f..7d193ac 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java +++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/ui/EditorTest.java
@@ -26,6 +26,7 @@
 import com.google.gwt.editor.client.adapters.EditorSource;
 import com.google.gwt.editor.client.adapters.ListEditor;
 import com.google.gwt.editor.client.adapters.SimpleEditor;
+import com.google.web.bindery.requestfactory.gwt.client.HasPaths;
 import com.google.web.bindery.requestfactory.gwt.client.HasRequestContext;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver; import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryTestBase;
@@ -52,9 +53,15 @@
    * DO NOT USE finishTest(). Instead, call finishTestAndReset();
    */

- static class SimpleBarEditor implements Editor<SimpleBarProxy>, HasRequestContext<SimpleBarProxy> {
+  static class SimpleBarEditor implements HasPaths<SimpleBarProxy>,
+      HasRequestContext<SimpleBarProxy> {
     protected final SimpleEditor<String> userName = SimpleEditor.of();
     RequestContext ctx;
+
+    @Override
+    public String[] getPaths() {
+      return new String[] {"unpersisted"};
+    }

     public void setRequestContext(RequestContext ctx) {
       this.ctx = ctx;
@@ -78,7 +85,7 @@
interface SimpleFooDriver extends RequestFactoryEditorDriver<SimpleFooProxy, SimpleFooEditor> {
   }

-  static class SimpleFooEditor implements HasEditorErrors<SimpleFooProxy> {
+ static class SimpleFooEditor implements HasEditorErrors<SimpleFooProxy>, HasPaths<SimpleFooProxy> {
     /**
      * Test field-based access.
      */
@@ -93,6 +100,11 @@
     private final SimpleBarEditor barEditor = new SimpleBarEditor();

     List<EditorError> errors;
+
+    @Override
+    public String[] getPaths() {
+      return new String[] {"fooField"};
+    }

     public void showErrors(List<EditorError> errors) {
       this.errors = errors;
@@ -147,7 +159,8 @@
     final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
     driver.initialize(req, editor);
     final String[] paths = driver.getPaths();
-    assertEquals(Arrays.asList("barField"), Arrays.asList(paths));
+ assertEquals(Arrays.asList("fooField", "barField", "selfOneToManyField", + "selfOneToManyField.barField", "barField.unpersisted"), Arrays.asList(paths));

req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(new Receiver<SimpleFooProxy>() {
       @Override
@@ -332,7 +345,8 @@
     driver.initialize(req, editor);

     String[] paths = driver.getPaths();
-    assertEquals(Arrays.asList("barField"), Arrays.asList(paths));
+ assertEquals(Arrays.asList("fooField", "barField", "selfOneToManyField", + "selfOneToManyField.barField", "barField.unpersisted"), Arrays.asList(paths));

req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(new Receiver<SimpleFooProxy>() {
       @Override

--
To view, visit https://gwt-review.googlesource.com/3185
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f259552d945bf22592c4395e3c7b2ad45bfe93c
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Thomas Broyer <[email protected]>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to