diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-23 12:23:40 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2014-12-23 12:23:40 +0200 |
commit | 02bc5233c422a55e87edda72e41999e5eacf8902 (patch) | |
tree | 3c3b6cd2086e9f66109da18aecc404cacaadf657 | |
parent | 8d8ba6f438f61d2e1d26fe9e23ddd58296e5f193 (diff) | |
parent | de22dbb220798b23f369e9685a49ac23c3af14b5 (diff) | |
download | vaadin-framework-02bc5233c422a55e87edda72e41999e5eacf8902.tar.gz vaadin-framework-02bc5233c422a55e87edda72e41999e5eacf8902.zip |
Merge remote-tracking branch 'origin/grid' into 7.4
9 files changed, 202 insertions, 7 deletions
diff --git a/client/src/com/vaadin/Vaadin.gwt.xml b/client/src/com/vaadin/Vaadin.gwt.xml index 40fbeb5a7a..7387d0f997 100644 --- a/client/src/com/vaadin/Vaadin.gwt.xml +++ b/client/src/com/vaadin/Vaadin.gwt.xml @@ -10,7 +10,7 @@ <inherits name="com.google.gwt.http.HTTP" /> - <inherits name="elemental.Elemental"/> + <inherits name="elemental.Json"/> <inherits name="com.google.gwt.logging.Logging" /> <set-property name="gwt.logging.enabled" value="TRUE" /> diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index ed9cfce062..8b23bf433b 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -60,9 +60,7 @@ import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.util.SharedUtil; import elemental.js.json.JsJsonValue; -import elemental.js.util.Json; import elemental.json.JsonValue; -import elemental.json.impl.JsonUtil; public class Util { @@ -1552,7 +1550,7 @@ public class Util { if (GWT.isProdMode()) { return (T) jso.<JsJsonValue> cast(); } else { - return JsonUtil.parse(Json.stringify(jso)); + return elemental.json.Json.instance().parse(stringify(jso)); } } @@ -1569,11 +1567,37 @@ public class Util { if (GWT.isProdMode()) { return ((JavaScriptObject) jsonValue.toNative()).cast(); } else { - return Json.parse(jsonValue.toJson()); + return parse(jsonValue.toJson()); } } /** + * Convert a {@link JavaScriptObject} into a string representation. + * + * @param json + * a JavaScript object to be converted to a string + * @return JSON in string representation + */ + private native static String stringify(JavaScriptObject json) + /*-{ + return JSON.stringify(json); + }-*/; + + /** + * Parse a string containing JSON into a {@link JavaScriptObject}. + * + * @param <T> + * the overlay type to expect from the parse + * @param jsonAsString + * @return a JavaScript object constructed from the parse + */ + public native static <T extends JavaScriptObject> T parse( + String jsonAsString) + /*-{ + return JSON.parse(jsonAsString); + }-*/; + + /** * The allowed value inaccuracy when comparing two double-typed pixel * values. * <p> diff --git a/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java index 96ebd811fb..883bbae0bd 100644 --- a/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -414,7 +414,7 @@ public abstract class ScrollbarBundle implements DeferredWorker { * offset size. All other browser need to suffer alongside. */ - boolean newOffsetSizeIsGreaterThanScrollSize = px > getOffsetSize(); + boolean newOffsetSizeIsGreaterThanScrollSize = px > getScrollSize(); boolean offsetSizeBecomesGreaterThanScrollSize = showsScrollHandle() && newOffsetSizeIsGreaterThanScrollSize; if (offsetSizeBecomesGreaterThanScrollSize && getScrollPos() != 0) { diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 63070dcd92..a5b90e5563 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -2519,7 +2519,15 @@ public class Grid<T> extends ResizeComposite implements + DEFAULT_RENDERER_WARNING); warned = true; } - cell.getElement().setInnerText(data.toString()); + + final String text; + if (data == null) { + text = ""; + } else { + text = data.toString(); + } + + cell.getElement().setInnerText(text); } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java index 26d6fefa45..91dff944cb 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java @@ -74,6 +74,11 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest { getGridVerticalScrollbar()); } + protected int getGridVerticalScrollPos() { + return ((Number) executeScript("return arguments[0].scrollTop", + getGridVerticalScrollbar())).intValue(); + } + protected List<TestBenchElement> getGridHeaderRowCells() { List<TestBenchElement> headerCells = new ArrayList<TestBenchElement>(); for (int i = 0; i < getGridElement().getHeaderCount(); ++i) { diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java new file mode 100644 index 0000000000..5c4ccfae89 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java @@ -0,0 +1,32 @@ +/* + * 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.basicfeatures; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.grid.GridDefaultTextRendererWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Widgetset(TestingWidgetSet.NAME) +public class GridDefaultTextRenderer extends UI { + + @Override + protected void init(VaadinRequest request) { + setContent(new TestWidgetComponent(GridDefaultTextRendererWidget.class)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java new file mode 100644 index 0000000000..cd31bfc860 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java @@ -0,0 +1,60 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.ServerClass; +import com.vaadin.tests.annotations.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridDefaultTextRendererTest extends MultiBrowserTest { + + @ServerClass("com.vaadin.tests.widgetset.server.TestWidgetComponent") + public static class MyGridElement extends GridElement { + // empty + } + + private GridElement grid; + + @Before + public void init() { + openTestURL(); + grid = $(MyGridElement.class).first(); + assertFalse("There was an unexpected notification during init", + $(NotificationElement.class).exists()); + } + + @Test + public void testNullIsRenderedAsEmptyStringByDefaultTextRenderer() { + assertTrue("First cell should've been empty", grid.getCell(0, 0) + .getText().isEmpty()); + } + + @Test + public void testStringIsRenderedAsStringByDefaultTextRenderer() { + assertEquals("Second cell should've been populated ", "string", grid + .getCell(1, 0).getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java index 9e1a9d5e91..9a9f85ccb9 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java @@ -437,4 +437,14 @@ public class GridStructureTest extends GridBasicFeaturesTest { assertTrue(vscrollStyleName.contains(stylename + "-scroller")); assertTrue(vscrollStyleName.contains(stylename + "-scroller-vertical")); } + + @Test + public void testScrollPosDoesNotChangeAfterStateChange() { + openTestURL(); + scrollGridVerticallyTo(1000); + int scrollPos = getGridVerticalScrollPos(); + selectMenuPath("Component", "Editor", "Enabled"); + assertEquals("Scroll position should've not have changed", scrollPos, + getGridVerticalScrollPos()); + } } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java new file mode 100644 index 0000000000..173ae097ed --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java @@ -0,0 +1,56 @@ +/* + * 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.widgetset.client.grid; + +import com.vaadin.client.widget.grid.datasources.ListDataSource; +import com.vaadin.client.widgets.Grid; +import com.vaadin.client.widgets.Grid.Column; +import com.vaadin.client.widgets.Grid.SelectionMode; +import com.vaadin.shared.ui.grid.HeightMode; + +public class GridDefaultTextRendererWidget extends + PureGWTTestApplication<Grid<String>> { + /* + * This can't be null, because grid thinks that a row object of null means + * "data is still being fetched". + */ + private static final String NULL_STRING = ""; + + private Grid<String> grid; + + public GridDefaultTextRendererWidget() { + super(new Grid<String>()); + grid = getTestedWidget(); + + grid.setDataSource(new ListDataSource<String>(NULL_STRING, "string")); + grid.addColumn(new Column<String, String>() { + @Override + public String getValue(String row) { + if (!NULL_STRING.equals(row)) { + return row; + } else { + return null; + } + } + }); + + grid.setHeightByRows(2); + grid.setHeightMode(HeightMode.ROW); + grid.setSelectionMode(SelectionMode.NONE); + addNorth(grid, 500); + } + +} |