Revision: 9547
Author: b...@google.com
Date: Fri Jan 14 06:09:32 2011
Log: Integrate Editor fix to GWT 2.2 branch.
Ensure that Editor framework descends into LeafValueEditors that require delegates.

http://code.google.com/p/google-web-toolkit/source/detail?r=9547

Modified:
 /releases/2.2/user/src/com/google/gwt/editor/rebind/model/EditorModel.java
/releases/2.2/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java

=======================================
--- /releases/2.2/user/src/com/google/gwt/editor/rebind/model/EditorModel.java Thu Dec 9 12:12:52 2010 +++ /releases/2.2/user/src/com/google/gwt/editor/rebind/model/EditorModel.java Fri Jan 14 06:09:32 2011
@@ -423,7 +423,7 @@
       superModel = superModel.parentModel;
     }

-    if (!data.isLeafValueEditor()) {
+    if (data.isDelegateRequired()) {
EditorModel subModel = new EditorModel(this, data.getEditorType(), data,
           calculateEditedType(logger, data.getEditorType()));
       accumulator.addAll(accumulator.indexOf(data) + 1,
=======================================
--- /releases/2.2/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java Thu Dec 9 12:12:52 2010 +++ /releases/2.2/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java Fri Jan 14 06:09:32 2011
@@ -143,6 +143,40 @@
     assertEquals(types.findType("t.PersonEditor"), m.getEditorType());
     assertEquals(types.findType("t.PersonProxy"), m.getProxyType());
   }
+
+  /**
+ * Verify that we correctly descend into a subeditor of a CompositeEditor that
+   * also is a LeafValueEditor (as is the case of OptionalFieldEditor).
+   */
+  public void testCompositeAndLeafValueEditor()
+      throws UnableToCompleteException {
+    EditorModel m = new EditorModel(logger,
+        types.findType("t.CompositeAndLeafEditorDriver"), rfedType);
+
+    assertEquals(types.findType("t.CompositeAndLeafEditorDriver.AProxy"),
+        m.getProxyType());
+    assertEquals(types.findType("t.CompositeAndLeafEditorDriver.AEditor"),
+        m.getEditorType());
+
+    EditorData[] data = m.getEditorData();
+    assertEquals(1, data.length);
+
+    assertTrue(data[0].isCompositeEditor());
+
+    EditorData composed = data[0].getComposedData();
+    assertEquals(types.findType("t.CompositeAndLeafEditorDriver.BProxy"),
+        composed.getEditedType());
+    assertEquals(types.findType("t.CompositeAndLeafEditorDriver.BEditor"),
+        composed.getEditorType());
+
+    // Nonsensical for the optional editor to have any data
+ EditorData[] optionalEditorData = m.getEditorData(data[0].getEditorType());
+    assertEquals(0, optionalEditorData.length);
+
+    // Make sure we have EditorData for the sub-editor
+    EditorData[] subEditorData = m.getEditorData(composed.getEditorType());
+    assertEquals(1, subEditorData.length);
+  }

   public void testCompositeDriver() throws UnableToCompleteException {
     EditorModel m = new EditorModel(logger,
@@ -796,6 +830,39 @@
         code.append("}");
         return code;
       }
+    }, new MockJavaResource("t.CompositeAndLeafEditorDriver") {
+ // Tests that we descend into sub-editor of a CompositeEditor that also
+        // is
+        // a LeafValueEditor (this is the case for the
+        // c.g.g.editor.client.adapters.OptionalFieldEditor)
+      @Override
+      protected CharSequence getContent() {
+        StringBuilder code = new StringBuilder();
+        code.append("package t;\n");
+        code.append("import " + Editor.class.getName() + ";\n");
+        code.append("import " + IsEditor.class.getName() + ";\n");
+        code.append("import " + EntityProxy.class.getName() + ";\n");
+        code.append("import " + RequestFactoryEditorDriver.class.getName()
+            + ";\n");
+        code.append("import " + SimpleEditor.class.getName() + ";\n");
+        code.append("import " + CompositeEditor.class.getName() + ";\n");
+        code.append("import " + LeafValueEditor.class.getName() + ";\n");
+        code.append("interface CompositeAndLeafEditorDriver extends"
+ + " RequestFactoryEditorDriver<CompositeAndLeafEditorDriver.AProxy,"
+            + " CompositeAndLeafEditorDriver.AEditor> {\n");
+ code.append(" interface AProxy extends EntityProxy { BProxy getB();}"); + code.append(" interface BProxy extends EntityProxy { String getString();}");
+        code.append("  interface AEditor extends Editor<AProxy> {");
+        code.append("    OptionalBEditor bEditor();");
+        code.append("  }");
+ code.append(" interface OptionalBEditor extends CompositeEditor<BProxy, BProxy, BEditor>, LeafValueEditor<BProxy> {");
+        code.append("  }");
+        code.append("  interface BEditor extends Editor<BProxy> {");
+ code.append(" @Editor.Path(\"string\") SimpleEditor<String> coEditor();");
+        code.append("  }");
+        code.append("}");
+        return code;
+      }
     }, new MockJavaResource("java.util.List") {
         // Tests a Driver interface that extends more than RFED
       @Override
@@ -809,7 +876,7 @@
     }};

Set<Resource> toReturn = new HashSet<Resource>(Arrays.asList(javaFiles));
-    toReturn.addAll(Arrays.asList(new Resource[]{
+    toReturn.addAll(Arrays.asList(new Resource[] {
         new RealJavaResource(CompositeEditor.class),
         new RealJavaResource(Editor.class),
         new RealJavaResource(EditorError.class),

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

Reply via email to