From f360817b0be2368489301baf1aa1985e165e4c36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Mon, 9 Feb 2015 14:11:01 +0200 Subject: [PATCH] Remove grid.[set|get]EditorField(Object, Field) (#16538) Change-Id: Ia5c09b80e32f9842fb4680f035b53cea755cb451 --- server/src/com/vaadin/ui/Grid.java | 73 +++++++------------ .../server/component/grid/GridColumns.java | 11 +-- .../server/component/grid/GridEditorTest.java | 37 +++++----- .../tests/components/grid/GridEditorUI.java | 8 +- .../grid/basicfeatures/GridBasicFeatures.java | 2 +- .../fieldgroup/BasicCrudGridEditorRow.java | 7 +- 6 files changed, 64 insertions(+), 74 deletions(-) diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 054030f61b..2bc42676c3 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -2619,11 +2619,16 @@ public class Grid extends AbstractComponent implements SelectionNotifier, /** * Sets the field component used to edit the properties in this column - * when the item editor is active. Please refer to - * {@link Grid#setEditorField(Object, Field)} for more information. + * when the item editor is active. If an item has not been set, then the + * binding is postponed until the item is set using + * {@link #editItem(Object)}. + *

+ * Setting the field to null clears any previously set + * field, causing a new field to be created the next time the item + * editor is opened. * * @param editor - * the editor field, cannot be null + * the editor field * @return this column */ public Column setEditorField(Field editor) { @@ -2633,10 +2638,25 @@ public class Grid extends AbstractComponent implements SelectionNotifier, /** * Returns the editor field used to edit the properties in this column - * when the item editor is active. Please refer to - * {@link Grid#getEditorField(Object)} for more information. + * when the item editor is active. Returns null if the column is not + * {@link Column#isEditable() editable}. + *

+ * When {@link #editItem(Object) editItem} is called, fields are + * automatically created and bound for any unbound properties. + *

+ * Getting a field before the editor has been opened depends on special + * support from the {@link FieldGroup} in use. Using this method with a + * user-provided FieldGroup might cause + * {@link BindException} to be thrown. * - * @return the editor field or null if this column is not editable + * @return the bound field; or null if the respective + * column is not editable + * + * @throws IllegalArgumentException + * if there is no column for the provided property id + * @throws BindException + * if no field has been configured and there is a problem + * building or binding */ public Field getEditorField() { return grid.getEditorField(getPropertyId()); @@ -4790,30 +4810,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } } - /** - * Gets the field component that represents a property in the item editor. - * Returns null if the corresponding column is not - * {@link Column#isEditable() editable}. - *

- * When {@link #editItem(Object) editItem} is called, fields are - * automatically created and bound for any unbound properties. - *

- * Getting a field before the editor has been opened depends on special - * support from the {@link FieldGroup} in use. Using this method with a - * user-provided FieldGroup might cause {@link BindException} - * to be thrown. - * - * @param propertyId - * the property id of the property for which to find the field - * @return the bound field or null if the respective column is not editable - * - * @throws IllegalArgumentException - * if there is no column for the provided property id - * @throws BindException - * if no field has been configured and there is a problem - * building or binding - */ - public Field getEditorField(Object propertyId) { + private Field getEditorField(Object propertyId) { checkColumnExists(propertyId); if (!getColumn(propertyId).isEditable()) { @@ -4871,21 +4868,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } } - /** - * Binds the field to the given propertyId. If an item has not been set, - * then the binding is postponed until the item is set using - * {@link #editItem(Object)}. - *

- * Setting the field to null clears any previously set field, - * causing a new field to be created the next time the item editor is - * opened. - * - * @param field - * The field to bind - * @param propertyId - * The propertyId to bind the field to - */ - public void setEditorField(Object propertyId, Field field) { + private void setEditorField(Object propertyId, Field field) { checkColumnExists(propertyId); Field oldField = editorFieldGroup.getField(propertyId); diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java index ab17e47393..06c1b14bb6 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java @@ -253,13 +253,14 @@ public class GridColumns { @Test public void testPropertyAndColumnEditorFieldsMatch() { - grid.setEditorField("column1", new TextField()); - assertSame(grid.getEditorField("column1"), grid.getColumn("column1") + Column column1 = grid.getColumn("column1"); + column1.setEditorField(new TextField()); + assertSame(column1.getEditorField(), grid.getColumn("column1") .getEditorField()); - grid.getColumn("column2").setEditorField(new TextField()); - assertSame(grid.getEditorField("column2"), grid.getColumn("column2") - .getEditorField()); + Column column2 = grid.getColumn("column2"); + column2.setEditorField(new TextField()); + assertSame(column2.getEditorField(), column2.getEditorField()); } @Test diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java index b247876d5d..135d7d398c 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java @@ -139,16 +139,17 @@ public class GridEditorTest { assertEquals(getEditedItem(), grid.getEditorFieldGroup() .getItemDataSource()); - assertEquals(DEFAULT_NAME, grid.getEditorField(PROPERTY_NAME) - .getValue()); - assertEquals(String.valueOf(DEFAULT_AGE), - grid.getEditorField(PROPERTY_AGE).getValue()); + assertEquals(DEFAULT_NAME, grid.getColumn(PROPERTY_NAME) + .getEditorField().getValue()); + assertEquals(String.valueOf(DEFAULT_AGE), grid.getColumn(PROPERTY_AGE) + .getEditorField().getValue()); } @Test public void testSaveEditor() throws Exception { startEdit(); - TextField field = (TextField) grid.getEditorField(PROPERTY_NAME); + TextField field = (TextField) grid.getColumn(PROPERTY_NAME) + .getEditorField(); field.setValue("New Name"); assertEquals(DEFAULT_NAME, field.getPropertyDataSource().getValue()); @@ -164,7 +165,8 @@ public class GridEditorTest { public void testSaveEditorCommitFail() throws Exception { startEdit(); - ((TextField) grid.getEditorField(PROPERTY_AGE)).setValue("Invalid"); + ((TextField) grid.getColumn(PROPERTY_AGE).getEditorField()) + .setValue("Invalid"); try { // Manual fail instead of @Test(expected=...) to check it is // saveEditor that fails and not setValue @@ -178,7 +180,8 @@ public class GridEditorTest { @Test public void testCancelEditor() throws Exception { startEdit(); - TextField field = (TextField) grid.getEditorField(PROPERTY_NAME); + TextField field = (TextField) grid.getColumn(PROPERTY_NAME) + .getEditorField(); field.setValue("New Name"); grid.cancelEditor(); @@ -199,23 +202,23 @@ public class GridEditorTest { public void testGetField() throws Exception { startEdit(); - assertNotNull(grid.getEditorField(PROPERTY_NAME)); + assertNotNull(grid.getColumn(PROPERTY_NAME).getEditorField()); } @Test public void testGetFieldWithoutItem() throws Exception { grid.setEditorEnabled(true); - assertNotNull(grid.getEditorField(PROPERTY_NAME)); + assertNotNull(grid.getColumn(PROPERTY_NAME).getEditorField()); } @Test public void testCustomBinding() { TextField textField = new TextField(); - grid.setEditorField(PROPERTY_NAME, textField); + grid.getColumn(PROPERTY_NAME).setEditorField(textField); startEdit(); - assertSame(textField, grid.getEditorField(PROPERTY_NAME)); + assertSame(textField, grid.getColumn(PROPERTY_NAME).getEditorField()); } @Test(expected = IllegalStateException.class) @@ -228,7 +231,7 @@ public class GridEditorTest { public void testFieldIsNotReadonly() { startEdit(); - Field field = grid.getEditorField(PROPERTY_NAME); + Field field = grid.getColumn(PROPERTY_NAME).getEditorField(); assertFalse(field.isReadOnly()); } @@ -237,13 +240,13 @@ public class GridEditorTest { startEdit(); grid.getEditorFieldGroup().setReadOnly(true); - Field field = grid.getEditorField(PROPERTY_NAME); + Field field = grid.getColumn(PROPERTY_NAME).getEditorField(); assertTrue(field.isReadOnly()); } @Test public void testColumnRemoved() { - Field field = grid.getEditorField(PROPERTY_NAME); + Field field = grid.getColumn(PROPERTY_NAME).getEditorField(); assertSame("field should be attached to ", grid, field.getParent()); @@ -255,13 +258,13 @@ public class GridEditorTest { @Test public void testSetFieldAgain() { TextField field = new TextField(); - grid.setEditorField(PROPERTY_NAME, field); + grid.getColumn(PROPERTY_NAME).setEditorField(field); field = new TextField(); - grid.setEditorField(PROPERTY_NAME, field); + grid.getColumn(PROPERTY_NAME).setEditorField(field); assertSame("new field should be used.", field, - grid.getEditorField(PROPERTY_NAME)); + grid.getColumn(PROPERTY_NAME).getEditorField()); } private void startEdit() { diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java index fe4b4342a2..60e241bae3 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java @@ -35,13 +35,13 @@ public class GridEditorUI extends AbstractTestUI { grid.setEditorEnabled(true); - grid.setEditorField("firstName", new PasswordField()); + grid.getColumn("firstName").setEditorField(new PasswordField()); - TextField lastNameField = (TextField) grid - .getEditorField("lastName"); + TextField lastNameField = (TextField) grid.getColumn("lastName") + .getEditorField(); lastNameField.setMaxLength(50); - grid.getEditorField("phoneNumber").setReadOnly(true); + grid.getColumn("phoneNumber").getEditorField().setReadOnly(true); addComponent(grid); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java index 6557dafb6f..e5a46894b8 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -227,7 +227,7 @@ public class GridBasicFeatures extends AbstractComponentTest { grid.setSelectionMode(SelectionMode.NONE); - grid.getEditorField(getColumnProperty(2)).setReadOnly(true); + grid.getColumn(getColumnProperty(2)).getEditorField().setReadOnly(true); grid.getColumn(getColumnProperty(3)).setEditable(false); createGridActions(); diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java index 63ba2986e1..62c217445f 100644 --- a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java +++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java @@ -47,8 +47,11 @@ public class BasicCrudGridEditorRow extends AbstractBasicCrud { }); grid.setEditorEnabled(true); grid.setSizeFull(); - grid.getEditorField("age").addValidator( - new IntegerRangeValidator("Must be between 0 and 100", 0, 100)); + grid.getColumn("age") + .getEditorField() + .addValidator( + new IntegerRangeValidator("Must be between 0 and 100", + 0, 100)); addComponent(grid); getLayout().setExpandRatio(grid, 1); } -- 2.39.5