]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensure the whole hierarchy is refreshed when opening editor row (#17459)
authorArtur Signell <artur@vaadin.com>
Mon, 18 May 2015 20:09:47 +0000 (23:09 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 19 May 2015 16:19:28 +0000 (16:19 +0000)
Change-Id: Iff691f27b70ccbad004dbc55411be977c5acff03

server/src/com/vaadin/ui/Grid.java
uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java [new file with mode: 0644]

index 5cc1a6752e7e4b80423bc3957cd0a564d9855e62..282711aa9288ea45f6aa957892b6d8874e831a52 100644 (file)
@@ -5688,6 +5688,13 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
             column.getState().editorConnector = getEditorField(column
                     .getPropertyId());
         }
+
+        // Must ensure that all fields, recursively, are sent to the client
+        // This is needed because the fields are hidden using isRendered
+        for (Field<?> f : getEditorFields()) {
+            f.markAsDirtyRecursive();
+        }
+
     }
 
     private void setEditorField(Object propertyId, Field<?> field) {
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomField.java
new file mode 100644 (file)
index 0000000..4703c98
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.fieldgroup.ComplexPerson;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.CustomField;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.HorizontalLayout;
+
+@Theme("valo")
+public class GridEditorCustomField extends AbstractTestUIWithLog {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        Grid grid = new PersonTestGrid(100);
+        grid.setWidth("800px");
+        grid.setColumns("firstName", "lastName", "address.city");
+        grid.setEditorEnabled(true);
+        Set<String> cities = new HashSet<String>();
+        for (Object o : grid.getContainerDataSource().getItemIds()) {
+            ComplexPerson p = (ComplexPerson) o;
+            cities.add(p.getAddress().getCity());
+        }
+        CustomCitySelect cityEditor = new CustomCitySelect(
+                cities.toArray(new String[cities.size()]));
+        grid.getColumn("address.city").setEditorField(cityEditor);
+        addComponent(grid);
+    }
+
+    public static class CustomCitySelect extends CustomField<String> {
+        private HorizontalLayout fieldLayout;
+        private String[] values;
+        private ComboBox cityComboBox;
+
+        public CustomCitySelect(String... values) {
+            this.values = values;
+        }
+
+        @Override
+        protected Component initContent() {
+            fieldLayout = new HorizontalLayout();
+            fieldLayout.setWidth("100%");
+
+            cityComboBox = new ComboBox();
+            for (String value : values) {
+                cityComboBox.addItem(value);
+            }
+            fieldLayout.addComponent(cityComboBox);
+            fieldLayout.setExpandRatio(cityComboBox, 1.0f);
+
+            Button addCountryButton = new Button("New");
+            fieldLayout.addComponent(addCountryButton);
+
+            return fieldLayout;
+        }
+
+        @Override
+        public Class<String> getType() {
+            return String.class;
+        }
+
+        @Override
+        protected void setInternalValue(String newValue) {
+            super.setInternalValue(newValue);
+            if (cityComboBox == null) {
+                return;
+            }
+            cityComboBox.setValue(newValue);
+        }
+
+        @Override
+        public String getInternalValue() {
+            if (cityComboBox == null) {
+                return null;
+            }
+            return (String) cityComboBox.getValue();
+        }
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java
new file mode 100644 (file)
index 0000000..3187e62
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridElement.GridEditorElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridEditorCustomFieldTest extends MultiBrowserTest {
+
+    @Test
+    public void testCustomFieldWorksInEditorRow() {
+        openTestURL();
+        GridElement grid = $(GridElement.class).first();
+        Assert.assertEquals("Stockholm", grid.getCell(0, 2).getText());
+        grid.getCell(0, 1).doubleClick();
+        GridEditorElement editor = grid.getEditor();
+        TestBenchElement customField = editor.getField(2);
+
+        ComboBoxElement comboBox = customField.$(ComboBoxElement.class).first();
+        comboBox.selectByText("Oslo");
+        editor.save();
+        Assert.assertEquals("Oslo", grid.getCell(0, 2).getText());
+
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java b/uitest/src/com/vaadin/tests/components/grid/PersonTestGrid.java
new file mode 100644 (file)
index 0000000..f654cd1
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.tests.fieldgroup.ComplexPerson;
+import com.vaadin.ui.Grid;
+
+public class PersonTestGrid extends Grid {
+
+    public PersonTestGrid(int size) {
+        BeanItemContainer<ComplexPerson> container = ComplexPerson
+                .createContainer(size);
+        container.addNestedContainerBean("address");
+        setContainerDataSource(container);
+    }
+}