summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/Grid.java74
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java11
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java37
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java8
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java2
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java7
6 files changed, 65 insertions, 74 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 6332520d2a..2bc42676c3 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -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);
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> {
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);
}