Revision: 9838
Author: t.bro...@gmail.com
Date: Thu Mar 10 07:36:40 2011
Log: Address issue 6076 where composite paths were not recorded correctly.
http://gwt-code-reviews.appspot.com/1364801/
Patch by: t.broyer
Review by: bobv
http://code.google.com/p/google-web-toolkit/source/detail?r=9838
Modified:
/trunk/user/src/com/google/gwt/editor/rebind/AbstractEditorDriverGenerator.java
/trunk/user/test/com/google/gwt/editor/client/SimpleBeanEditorTest.java
/trunk/user/test/com/google/gwt/editor/client/impl/DelegateMapTest.java
=======================================
---
/trunk/user/src/com/google/gwt/editor/rebind/AbstractEditorDriverGenerator.java
Wed Feb 9 08:49:34 2011
+++
/trunk/user/src/com/google/gwt/editor/rebind/AbstractEditorDriverGenerator.java
Thu Mar 10 07:36:40 2011
@@ -175,7 +175,7 @@
sw.indent();
sw.println("%s = new %s();", delegateFields.get(d),
subDelegateType);
sw.println("addSubDelegate(%s, appendPath(\"%s\"), editor.%s);",
- delegateFields.get(d), d.getPropertyName(),
+ delegateFields.get(d), d.getDeclaredPath(),
d.getSimpleExpression());
sw.outdent();
sw.println("}");
=======================================
--- /trunk/user/test/com/google/gwt/editor/client/SimpleBeanEditorTest.java
Wed Feb 9 08:49:34 2011
+++ /trunk/user/test/com/google/gwt/editor/client/SimpleBeanEditorTest.java
Thu Mar 10 07:36:40 2011
@@ -33,8 +33,7 @@
* AbstractEditorDriverGenerator.
*/
public class SimpleBeanEditorTest extends GWTTestCase {
- class AddressCoEditorView extends LeafAddressEditor implements
- IsEditor<LeafAddressEditor> {
+ class AddressCoEditorView extends LeafAddressEditor implements
IsEditor<LeafAddressEditor> {
private LeafAddressEditor addressEditor = new LeafAddressEditor();
public LeafAddressEditor asEditor() {
@@ -58,8 +57,7 @@
}
}
- class LeafAddressEditor extends AddressEditor implements
- LeafValueEditor<Address> {
+ class LeafAddressEditor extends AddressEditor implements
LeafValueEditor<Address> {
/*
* These two fields are used to ensure that getValue() and setValue()
aren't
* called excessively.
@@ -79,8 +77,7 @@
}
}
- interface ListEditorDriver
- extends
+ interface ListEditorDriver extends
SimpleBeanEditorDriver<List<String>, ListEditor<String,
SimpleEditor<String>>> {
}
@@ -118,8 +115,7 @@
SimpleBeanEditorDriver<Person, PersonEditorWithCoAddressEditorView> {
}
- static class PersonEditorWithDelegate extends PersonEditor implements
- HasEditorDelegate<Person> {
+ static class PersonEditorWithDelegate extends PersonEditor implements
HasEditorDelegate<Person> {
EditorDelegate<Person> delegate;
public void setDelegate(EditorDelegate<Person> delegate) {
@@ -141,6 +137,16 @@
interface PersonEditorWithLeafAddressEditorDriver extends
SimpleBeanEditorDriver<Person, PersonEditorWithLeafAddressEditor> {
}
+
+ class PersonEditorWithManagerNameWithDelegate implements Editor<Person> {
+ @Path("manager.name")
+ SimpleEditorWithDelegate<String> managerName = new
SimpleEditorWithDelegate<String>(
+ UNINITIALIZED);
+ }
+
+ interface PersonEditorWithManagerNameWithDelegateDriver extends
+ SimpleBeanEditorDriver<Person,
PersonEditorWithManagerNameWithDelegate> {
+ }
class PersonEditorWithMultipleBindings implements Editor<Person> {
@Editor.Path("address")
@@ -185,8 +191,7 @@
SimpleEditor<String> managerName = SimpleEditor.of(UNINITIALIZED);
}
- interface PersonEditorWithValueAwareLeafAddressEditorDriver
- extends
+ interface PersonEditorWithValueAwareLeafAddressEditorDriver extends
SimpleBeanEditorDriver<Person,
PersonEditorWithValueAwareLeafAddressEditor> {
}
@@ -205,20 +210,32 @@
class PersonWithListEditor implements Editor<PersonWithList> {
SimpleEditor<String> nameEditor = SimpleEditor.of(UNINITIALIZED);
- ListEditor<Address, AddressEditor> addressesEditor = ListEditor.of(new
EditorSource<AddressEditor>() {
- @Override
- public AddressEditor create(int index) {
- return new AddressEditor();
- }
- });
+ ListEditor<Address, AddressEditor> addressesEditor = ListEditor
+ .of(new EditorSource<AddressEditor>() {
+ @Override
+ public AddressEditor create(int index) {
+ return new AddressEditor();
+ }
+ });
}
interface PersonWithListEditorDriver extends
SimpleBeanEditorDriver<PersonWithList, PersonWithListEditor> {
}
- class ValueAwareAddressEditor extends AddressEditor implements
- ValueAwareEditor<Address> {
+ class SimpleEditorWithDelegate<T> extends SimpleEditor<T> implements
HasEditorDelegate<T> {
+ EditorDelegate<T> delegate;
+
+ public SimpleEditorWithDelegate(T value) {
+ super(value);
+ }
+
+ public void setDelegate(EditorDelegate<T> delegate) {
+ this.delegate = delegate;
+ }
+ }
+
+ class ValueAwareAddressEditor extends AddressEditor implements
ValueAwareEditor<Address> {
int flushCalled;
int setDelegateCalled;
int setValueCalled;
@@ -244,8 +261,7 @@
/**
* All the mix-ins. Not that this seems like a good idea...
*/
- class ValueAwareLeafAddressEditor extends LeafAddressEditor implements
- ValueAwareEditor<Address> {
+ class ValueAwareLeafAddressEditor extends LeafAddressEditor implements
ValueAwareEditor<Address> {
int flushCalled;
int setDelegateCalled;
@@ -300,7 +316,8 @@
public void testAliasedEditors() {
PersonEditorWithAliasedSubEditors editor = new
PersonEditorWithAliasedSubEditors();
- PersonEditorWithAliasedSubEditorsDriver driver =
GWT.create(PersonEditorWithAliasedSubEditorsDriver.class);
+ PersonEditorWithAliasedSubEditorsDriver driver =
+ GWT.create(PersonEditorWithAliasedSubEditorsDriver.class);
driver.initialize(editor);
driver.edit(person);
@@ -320,6 +337,16 @@
driver.flush();
assertEquals("Should see this", person.getName());
}
+
+ public void testDelegatePath() {
+ PersonEditorWithManagerNameWithDelegate editor = new
PersonEditorWithManagerNameWithDelegate();
+ PersonEditorWithManagerNameWithDelegateDriver driver =
+ GWT.create(PersonEditorWithManagerNameWithDelegateDriver.class);
+ driver.initialize(editor);
+ driver.edit(person);
+
+ assertEquals("manager.name", editor.managerName.delegate.getPath());
+ }
public void testEditorWithNullSubEditor() {
PersonEditor editor = new PersonEditor();
@@ -358,9 +385,9 @@
*/
public void testIsEditorView() {
PersonEditorWithAddressEditorView personEditor = new
PersonEditorWithAddressEditorView();
- PersonEditorWithAddressEditorViewDriver driver =
GWT.create(PersonEditorWithAddressEditorViewDriver.class);
- testLeafAddressEditor(driver, personEditor,
- personEditor.addressEditor.asEditor(), true);
+ PersonEditorWithAddressEditorViewDriver driver =
+ GWT.create(PersonEditorWithAddressEditorViewDriver.class);
+ testLeafAddressEditor(driver, personEditor,
personEditor.addressEditor.asEditor(), true);
}
/**
@@ -369,9 +396,9 @@
*/
public void testIsEditorViewWithCoEditorA() {
PersonEditorWithCoAddressEditorView personEditor = new
PersonEditorWithCoAddressEditorView();
- PersonEditorWithCoAddressEditorViewDriver driver =
GWT.create(PersonEditorWithCoAddressEditorViewDriver.class);
- testLeafAddressEditor(driver, personEditor, personEditor.addressEditor,
- true);
+ PersonEditorWithCoAddressEditorViewDriver driver =
+ GWT.create(PersonEditorWithCoAddressEditorViewDriver.class);
+ testLeafAddressEditor(driver, personEditor,
personEditor.addressEditor, true);
}
/**
@@ -380,9 +407,9 @@
*/
public void testIsEditorViewWithCoEditorB() {
PersonEditorWithCoAddressEditorView personEditor = new
PersonEditorWithCoAddressEditorView();
- PersonEditorWithCoAddressEditorViewDriver driver =
GWT.create(PersonEditorWithCoAddressEditorViewDriver.class);
- testLeafAddressEditor(driver, personEditor,
- personEditor.addressEditor.asEditor(), true);
+ PersonEditorWithCoAddressEditorViewDriver driver =
+ GWT.create(PersonEditorWithCoAddressEditorViewDriver.class);
+ testLeafAddressEditor(driver, personEditor,
personEditor.addressEditor.asEditor(), true);
}
/**
@@ -392,7 +419,8 @@
*/
public void testLeafValueEditorDeclaredInSlot() {
PersonEditorWithLeafAddressEditor personEditor = new
PersonEditorWithLeafAddressEditor();
- PersonEditorWithLeafAddressEditorDriver driver =
GWT.create(PersonEditorWithLeafAddressEditorDriver.class);
+ PersonEditorWithLeafAddressEditorDriver driver =
+ GWT.create(PersonEditorWithLeafAddressEditorDriver.class);
LeafAddressEditor addressEditor = personEditor.addressEditor;
testLeafAddressEditor(driver, personEditor, addressEditor, true);
@@ -436,7 +464,8 @@
* Test a top-level ListEditor.
*/
public void testListEditor() {
- final SortedMap<Integer, SimpleEditor<String>> positionMap = new
TreeMap<Integer, SimpleEditor<String>>();
+ final SortedMap<Integer, SimpleEditor<String>> positionMap =
+ new TreeMap<Integer, SimpleEditor<String>>();
@SuppressWarnings("unchecked")
final SimpleEditor<String>[] disposed = new SimpleEditor[1];
class StringSource extends EditorSource<SimpleEditor<String>> {
@@ -462,16 +491,14 @@
driver.initialize(editor);
- List<String> rawData = new
ArrayList<String>(Arrays.asList("foo", "bar",
- "baz"));
+ List<String> rawData = new
ArrayList<String>(Arrays.asList("foo", "bar", "baz"));
driver.edit(rawData);
List<SimpleEditor<String>> editors = editor.getEditors();
assertEquals(rawData.size(), editors.size());
- assertEquals(rawData, Arrays.asList(editors.get(0).getValue(),
- editors.get(1).getValue(), editors.get(2).getValue()));
- assertEquals(editors,
- new ArrayList<SimpleEditor<String>>(positionMap.values()));
+ assertEquals(rawData, Arrays.asList(editors.get(0).getValue(),
editors.get(1).getValue(),
+ editors.get(2).getValue()));
+ assertEquals(editors, new
ArrayList<SimpleEditor<String>>(positionMap.values()));
List<String> mutableList = editor.getList();
assertEquals(rawData, mutableList);
@@ -490,8 +517,7 @@
mutableList.add("quux");
assertEquals(4, editors.size());
assertEquals("quux", editors.get(3).getValue());
- assertEquals(editors,
- new ArrayList<SimpleEditor<String>>(positionMap.values()));
+ assertEquals(editors, new
ArrayList<SimpleEditor<String>>(positionMap.values()));
// Delete an element
SimpleEditor<String> expectedDisposed = editors.get(0);
@@ -499,8 +525,7 @@
assertSame(expectedDisposed, disposed[0]);
assertEquals(3, editors.size());
assertEquals("quux", editors.get(2).getValue());
- assertEquals(editors,
- new ArrayList<SimpleEditor<String>>(positionMap.values()));
+ assertEquals(editors, new
ArrayList<SimpleEditor<String>>(positionMap.values()));
}
/**
@@ -531,8 +556,7 @@
// Edit
driver.edit(person);
- AddressEditor addressEditor =
personEditor.addressesEditor.getEditors().get(
- 1);
+ AddressEditor addressEditor =
personEditor.addressesEditor.getEditors().get(1);
assertEquals("a2City", addressEditor.city.getValue());
addressEditor.city.setValue("edited");
@@ -542,7 +566,8 @@
}
public void testMultipleBinding() {
- PersonEditorWithMultipleBindingsDriver driver =
GWT.create(PersonEditorWithMultipleBindingsDriver.class);
+ PersonEditorWithMultipleBindingsDriver driver =
+ GWT.create(PersonEditorWithMultipleBindingsDriver.class);
PersonEditorWithMultipleBindings editor = new
PersonEditorWithMultipleBindings();
driver.initialize(editor);
@@ -559,12 +584,13 @@
}
public void testOptionalField() {
- PersonEditorWithOptionalAddressDriver driver =
GWT.create(PersonEditorWithOptionalAddressDriver.class);
+ PersonEditorWithOptionalAddressDriver driver =
+ GWT.create(PersonEditorWithOptionalAddressDriver.class);
person.address = null;
AddressEditor delegate = new AddressEditor();
- PersonEditorWithOptionalAddressEditor editor = new
PersonEditorWithOptionalAddressEditor(
- delegate);
+ PersonEditorWithOptionalAddressEditor editor =
+ new PersonEditorWithOptionalAddressEditor(delegate);
driver.initialize(editor);
// Make sure we don't blow up with the null field
@@ -583,8 +609,10 @@
}
public void testValueAwareEditorInDeclaredSlot() {
- PersonEditorWithValueAwareAddressEditorDriver driver =
GWT.create(PersonEditorWithValueAwareAddressEditorDriver.class);
- PersonEditorWithValueAwareAddressEditor personEditor = new
PersonEditorWithValueAwareAddressEditor();
+ PersonEditorWithValueAwareAddressEditorDriver driver =
+ GWT.create(PersonEditorWithValueAwareAddressEditorDriver.class);
+ PersonEditorWithValueAwareAddressEditor personEditor =
+ new PersonEditorWithValueAwareAddressEditor();
ValueAwareAddressEditor addressEditor = personEditor.addressEditor;
testValueAwareAddressEditor(driver, personEditor, addressEditor);
@@ -606,8 +634,10 @@
}
public void testValueAwareLeafValueEditorInDeclaredSlot() {
- PersonEditorWithValueAwareLeafAddressEditor personEditor = new
PersonEditorWithValueAwareLeafAddressEditor();
- PersonEditorWithValueAwareLeafAddressEditorDriver driver =
GWT.create(PersonEditorWithValueAwareLeafAddressEditorDriver.class);
+ PersonEditorWithValueAwareLeafAddressEditor personEditor =
+ new PersonEditorWithValueAwareLeafAddressEditor();
+ PersonEditorWithValueAwareLeafAddressEditorDriver driver =
+
GWT.create(PersonEditorWithValueAwareLeafAddressEditorDriver.class);
ValueAwareLeafAddressEditor addressEditor = personEditor.addressEditor;
testLeafAddressEditor(driver, personEditor, addressEditor, true);
@@ -646,8 +676,8 @@
}
private <T extends Editor<Person>> void testLeafAddressEditor(
- SimpleBeanEditorDriver<Person, T> driver, T personEditor,
- LeafAddressEditor addressEditor, boolean declaredAsLeaf) {
+ SimpleBeanEditorDriver<Person, T> driver, T personEditor,
LeafAddressEditor addressEditor,
+ boolean declaredAsLeaf) {
Address oldAddress = person.address;
// Initialize
driver.initialize(personEditor);
=======================================
--- /trunk/user/test/com/google/gwt/editor/client/impl/DelegateMapTest.java
Wed Feb 2 03:25:11 2011
+++ /trunk/user/test/com/google/gwt/editor/client/impl/DelegateMapTest.java
Thu Mar 10 07:36:40 2011
@@ -19,6 +19,8 @@
import com.google.gwt.editor.client.Address;
import com.google.gwt.editor.client.AddressEditor;
import com.google.gwt.editor.client.Editor;
+import com.google.gwt.editor.client.EditorDelegate;
+import com.google.gwt.editor.client.HasEditorDelegate;
import com.google.gwt.editor.client.IsEditor;
import com.google.gwt.editor.client.Person;
import com.google.gwt.editor.client.SimpleBeanEditorDriver;
@@ -33,8 +35,7 @@
* Tests for DelegateMap.
*/
public class DelegateMapTest extends GWTTestCase {
- class AddressCoEditorView extends AddressEditor implements
- IsEditor<AddressEditor> {
+ class AddressCoEditorView extends AddressEditor implements
IsEditor<AddressEditor> {
private AddressEditor addressEditor = new AddressEditor();
public AddressEditor asEditor() {
@@ -46,22 +47,53 @@
AddressCoEditorView addressEditor = new AddressCoEditorView();
SimpleEditor<String> name = SimpleEditor.of("uninitialized");
@Path("manager.name")
- SimpleEditor<String> managerName = SimpleEditor.of("uninitialized");
+ SimpleEditorWithDelegate<String> managerName = new
SimpleEditorWithDelegate<String>(
+ "uninitialized");
}
interface PersonEditorWithCoAddressEditorViewDriver extends
SimpleBeanEditorDriver<Person, PersonEditorWithCoAddressEditorView> {
}
- @Override
- public String getModuleName() {
- return "com.google.gwt.editor.Editor";
+ class SimpleEditorWithDelegate<T> extends SimpleEditor<T> implements
HasEditorDelegate<T> {
+ EditorDelegate<T> delegate;
+
+ public SimpleEditorWithDelegate(T value) {
+ super(value);
+ }
+
+ public void setDelegate(EditorDelegate<T> delegate) {
+ this.delegate = delegate;
+ }
}
private AbstractSimpleBeanEditorDriver<Person,
PersonEditorWithCoAddressEditorView> driver;
private PersonEditorWithCoAddressEditorView editor;
private DelegateMap map;
private Person person;
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.editor.Editor";
+ }
+
+ public void test() {
+ // Test by-object
+ assertEquals(Arrays.asList(editor), editors(map, person));
+ assertEquals(Arrays.asList(editor.addressEditor.addressEditor,
editor.addressEditor), editors(
+ map, person.getAddress()));
+
+ // Test by-path
+ assertEquals(Arrays.asList(editor), editors(map, ""));
+ assertEquals(Arrays.asList(editor.addressEditor.addressEditor,
editor.addressEditor), editors(
+ map, "address"));
+ assertEquals(Arrays.<Editor<?>> asList(editor.managerName),
editors(map, "manager.name"));
+ }
+
+ public void testSimplePath() {
+ assertSame(editor.name, map.getEditorByPath("name").get(0));
+ assertSame(editor.managerName,
map.getEditorByPath("manager.name").get(0));
+ }
@Override
protected void gwtSetUp() throws Exception {
@@ -84,25 +116,6 @@
map = DelegateMap.of(driver, DelegateMap.IDENTITY);
}
-
- public void test() {
- // Test by-object
- assertEquals(Arrays.asList(editor), editors(map, person));
- assertEquals(
- Arrays.asList(editor.addressEditor.addressEditor,
editor.addressEditor),
- editors(map, person.getAddress()));
-
- // Test by-path
- assertEquals(Arrays.asList(editor), editors(map, ""));
- assertEquals(
- Arrays.asList(editor.addressEditor.addressEditor,
editor.addressEditor),
- editors(map, "address"));
- }
-
- public void testSimplePath() {
- assertSame(editor.name, map.getEditorByPath("name").get(0));
- assertSame(editor.managerName,
map.getEditorByPath("manager.name").get(0));
- }
private List<Editor<?>> editors(DelegateMap map, Object o) {
List<Editor<?>> toReturn = new ArrayList<Editor<?>>();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors