]> source.dussan.org Git - vaadin-framework.git/commitdiff
Remove grid.[set|get]EditorField(Object, Field) (#16538)
authorLeif Åstrand <leif@vaadin.com>
Mon, 9 Feb 2015 12:11:01 +0000 (14:11 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 9 Feb 2015 19:17:32 +0000 (19:17 +0000)
Change-Id: Ia5c09b80e32f9842fb4680f035b53cea755cb451

server/src/com/vaadin/ui/Grid.java
server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java
server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java
uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java

index 6332520d2a1981fbde6564c850efbdbb3ea015f1..2bc42676c3a06dd1a3a455d7abf5d0ea191e6dcd 100644 (file)
@@ -51,6 +51,7 @@ import com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper;
 import com.vaadin.data.Validator.InvalidValueException;
 import com.vaadin.data.fieldgroup.DefaultFieldGroupFieldFactory;
 import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup.BindException;
 import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
 import com.vaadin.data.fieldgroup.FieldGroupFieldFactory;
 import com.vaadin.data.sort.Sort;
@@ -2618,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)}.
+         * <p>
+         * Setting the field to <code>null</code> 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) {
@@ -2632,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}.
+         * <p>
+         * When {@link #editItem(Object) editItem} is called, fields are
+         * automatically created and bound for any unbound properties.
+         * <p>
+         * 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 <code>FieldGroup</code> might cause
+         * {@link BindException} to be thrown.
          * 
-         * @return the editor field or null if this column is not editable
+         * @return the bound field; or <code>null</code> 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());
@@ -4789,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}.
-     * <p>
-     * When {@link #editItem(Object) editItem} is called, fields are
-     * automatically created and bound for any unbound properties.
-     * <p>
-     * 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 <code>FieldGroup</code> 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()) {
@@ -4870,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)}.
-     * <p>
-     * Setting the field to <code>null</code> 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);
index ab17e473931e0603f7800f9125f15c218815e616..06c1b14bb60a51f42e309f55d5897ecdbfa8c3ca 100644 (file)
@@ -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
index b247876d5d0a92ae9c891bb1a2f8a46fb1ba2462..135d7d398c8ca8d196c79d63dde17f1c0c993a32 100644 (file)
@@ -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() {
index fe4b4342a23b121629ca8a9ce19c105301f8c208..60e241bae3b4dee110f09c5c3d3c0ea3bd0a76b1 100644 (file)
@@ -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);
     }
index 6557dafb6f407e8a7bd2596a38e19cad04579f16..e5a46894b88e0ff128d79bf5033ea968bf9a6679 100644 (file)
@@ -227,7 +227,7 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
 
         grid.setSelectionMode(SelectionMode.NONE);
 
-        grid.getEditorField(getColumnProperty(2)).setReadOnly(true);
+        grid.getColumn(getColumnProperty(2)).getEditorField().setReadOnly(true);
         grid.getColumn(getColumnProperty(3)).setEditable(false);
 
         createGridActions();
index 63ba2986e1014841b2c7c8442a45ddb645a37945..62c217445f5db13f8983fb780e4ee97efda98a37 100644 (file)
@@ -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);
     }