diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-02 18:47:48 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-01-02 18:47:48 +0200 |
commit | fac1da3160ba4f7479abaa0e671fe697cd7f129c (patch) | |
tree | b6a20725cb779d25540a518ebe512401da14de9a | |
parent | 87bce70111765d1e56729a76804d76f3f071992a (diff) | |
parent | 2e4677b67a63980fd71955d4325c4e329a95f5e8 (diff) | |
download | vaadin-framework-fac1da3160ba4f7479abaa0e671fe697cd7f129c.tar.gz vaadin-framework-fac1da3160ba4f7479abaa0e671fe697cd7f129c.zip |
Merge remote-tracking branch 'origin/grid' into 7.4
Conflicts:
shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java
Change-Id: Ic5fdf12c480828c2ceed0bd97695db76dfd0f386
27 files changed, 644 insertions, 153 deletions
diff --git a/WebContent/VAADIN/themes/base/grid/grid.scss b/WebContent/VAADIN/themes/base/grid/grid.scss index e1941826ca..310e37d0fb 100644 --- a/WebContent/VAADIN/themes/base/grid/grid.scss +++ b/WebContent/VAADIN/themes/base/grid/grid.scss @@ -198,6 +198,11 @@ $v-grid-editor-background-color: $v-grid-row-background-color !default; display: block; } + .#{$primaryStyleName}.v-disabled:focus .#{$primaryStyleName}-cell-focused:before { + // Disabled Grid should not show cell focus outline + display: none; + } + // Editor .#{$primaryStyleName}-editor { diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index d3954f2366..0044025d40 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -57,6 +57,7 @@ import com.vaadin.client.widget.grid.sort.SortEvent; import com.vaadin.client.widget.grid.sort.SortHandler; import com.vaadin.client.widget.grid.sort.SortOrder; import com.vaadin.client.widgets.Grid; +import com.vaadin.client.widgets.Grid.Column; import com.vaadin.client.widgets.Grid.FooterCell; import com.vaadin.client.widgets.Grid.FooterRow; import com.vaadin.client.widgets.Grid.HeaderCell; @@ -102,7 +103,12 @@ public class GridConnector extends AbstractHasComponentsConnector implements return null; } - CustomGridColumn c = (CustomGridColumn) cellReference.getColumn(); + Column<?, JsonObject> column = cellReference.getColumn(); + if (!(column instanceof CustomGridColumn)) { + // Selection checkbox column + return null; + } + CustomGridColumn c = (CustomGridColumn) column; JsonObject cellStylesObject = row .getObject(GridState.JSONKEY_CELLSTYLES); @@ -436,6 +442,13 @@ public class GridConnector extends AbstractHasComponentsConnector implements public void onStateChanged(final StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); + if (stateChangeEvent.hasPropertyChanged("selectionMode")) { + onSelectionModeChange(); + } + if (stateChangeEvent.hasPropertyChanged("selectedKeys")) { + updateSelectionFromState(); + } + /* * The operations in here have been made deferred. * @@ -730,7 +743,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements getWidget().setDataSource(this.dataSource); } - @OnStateChange("selectionMode") private void onSelectionModeChange() { SharedSelectionMode mode = getState().selectionMode; if (mode == null) { @@ -764,7 +776,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements } } - @OnStateChange("selectedKeys") private void updateSelectionFromState() { boolean changed = false; diff --git a/client/src/com/vaadin/client/renderers/ClickableRenderer.java b/client/src/com/vaadin/client/renderers/ClickableRenderer.java index 21f0e28c76..93e68763e0 100644 --- a/client/src/com/vaadin/client/renderers/ClickableRenderer.java +++ b/client/src/com/vaadin/client/renderers/ClickableRenderer.java @@ -26,8 +26,12 @@ import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.ui.Widget; import com.google.web.bindery.event.shared.HandlerRegistration; +import com.vaadin.client.Util; +import com.vaadin.client.widget.escalator.Cell; +import com.vaadin.client.widget.escalator.RowContainer; import com.vaadin.client.widget.grid.CellReference; -import com.vaadin.client.widget.grid.GridUtil; +import com.vaadin.client.widget.grid.EventCellReference; +import com.vaadin.client.widgets.Escalator; import com.vaadin.client.widgets.Grid; /** @@ -122,13 +126,62 @@ public abstract class ClickableRenderer<T, W extends Widget> extends } Element e = Element.as(target); - Grid<R> grid = (Grid<R>) GridUtil.findClosestParentGrid(e); + Grid<R> grid = (Grid<R>) findClosestParentGrid(e); - cell = GridUtil.findCell(grid, e); + cell = findCell(grid, e); row = cell.getRow(); handler.onClick(this); } + + /** + * Returns the cell the given element belongs to. + * + * @param grid + * the grid instance that is queried + * @param e + * a cell element or the descendant of one + * @return the cell or null if the element is not a grid cell or a + * descendant of one + */ + private static <T> CellReference<T> findCell(Grid<T> grid, Element e) { + RowContainer container = getEscalator(grid).findRowContainer(e); + if (container == null) { + return null; + } + Cell cell = container.getCell(e); + EventCellReference<T> cellReference = new EventCellReference<T>( + grid); + cellReference.set(cell); + return cellReference; + } + + private native static Escalator getEscalator(Grid<?> grid) + /*-{ + return grid.@com.vaadin.client.widgets.Grid::escalator; + }-*/; + + /** + * Returns the Grid instance containing the given element, if any. + * <p> + * <strong>Note:</strong> This method may not work reliably if the grid + * in question is wrapped in a {@link Composite} <em>unless</em> the + * element is inside another widget that is a child of the wrapped grid; + * please refer to the note in {@link Util#findWidget(Element, Class) + * Util.findWidget} for details. + * + * @param e + * the element whose parent grid to find + * @return the parent grid or null if none found. + */ + private static Grid<?> findClosestParentGrid(Element e) { + Widget w = Util.findWidget(e, null); + + while (w != null && !(w instanceof Grid)) { + w = w.getParent(); + } + return (Grid<?>) w; + } } private HandlerManager handlerManager; diff --git a/client/src/com/vaadin/client/renderers/ComplexRenderer.java b/client/src/com/vaadin/client/renderers/ComplexRenderer.java index 4e41b5f80d..75ea523cdc 100644 --- a/client/src/com/vaadin/client/renderers/ComplexRenderer.java +++ b/client/src/com/vaadin/client/renderers/ComplexRenderer.java @@ -37,7 +37,7 @@ import com.vaadin.client.widget.grid.RendererCellReference; * Also provides a helper method for hiding the cell contents by overriding * {@link #setContentVisible(FlyweightCell, boolean)} * - * @since + * @since 7.4.0 * @author Vaadin Ltd */ public abstract class ComplexRenderer<T> implements Renderer<T> { diff --git a/client/src/com/vaadin/client/widget/grid/GridUtil.java b/client/src/com/vaadin/client/widget/grid/GridUtil.java deleted file mode 100644 index 25e29f52dc..0000000000 --- a/client/src/com/vaadin/client/widget/grid/GridUtil.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.client.widget.grid; - -import com.google.gwt.dom.client.Element; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.Util; -import com.vaadin.client.widget.escalator.Cell; -import com.vaadin.client.widget.escalator.RowContainer; -import com.vaadin.client.widgets.Escalator; -import com.vaadin.client.widgets.Grid; - -/** - * Utilities for working with Grid. - * - * @since 7.4 - * @author Vaadin Ltd - */ -public class GridUtil { - - /** - * Returns the cell the given element belongs to. - * - * @param grid - * the grid instance that is queried - * @param e - * a cell element or the descendant of one - * @return the cell or null if the element is not a grid cell or a - * descendant of one - */ - public static <T> CellReference<T> findCell(Grid<T> grid, Element e) { - RowContainer container = getEscalator(grid).findRowContainer(e); - if (container == null) { - return null; - } - Cell cell = container.getCell(e); - EventCellReference<T> cellReference = new EventCellReference<T>(grid); - cellReference.set(cell); - return cellReference; - } - - /** - * Returns the Grid instance containing the given element, if any. - * <p> - * <strong>Note:</strong> This method may not work reliably if the grid in - * question is wrapped in a {@link Composite} <em>unless</em> the element is - * inside another widget that is a child of the wrapped grid; please refer - * to the note in {@link Util#findWidget(Element, Class) Util.findWidget} - * for details. - * - * @param e - * the element whose parent grid to find - * @return the parent grid or null if none found. - */ - public static Grid<?> findClosestParentGrid(Element e) { - Widget w = Util.findWidget(e, null); - - while (w != null && !(w instanceof Grid)) { - w = w.getParent(); - } - return (Grid<?>) w; - } - - /** - * Accesses the package private method Widget#setParent() - * - * @param widget - * The widget to access - * @param parent - * The parent to set - */ - public static native final void setParent(Widget widget, Grid<?> parent) - /*-{ - widget.@com.google.gwt.user.client.ui.Widget::setParent(Lcom/google/gwt/user/client/ui/Widget;)(parent); - }-*/; - - private native static Escalator getEscalator(Grid<?> grid) - /*-{ - return grid.@com.vaadin.client.widgets.Grid::escalator; - }-*/; -} diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 74fb28bbd2..57c55d457d 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -50,6 +50,7 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RequiresResize; import com.google.gwt.user.client.ui.UIObject; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.BrowserInfo; import com.vaadin.client.DeferredWorker; import com.vaadin.client.Profiler; import com.vaadin.client.Util; @@ -63,6 +64,7 @@ import com.vaadin.client.widget.escalator.PositionFunction.AbsolutePosition; import com.vaadin.client.widget.escalator.PositionFunction.Translate3DPosition; import com.vaadin.client.widget.escalator.PositionFunction.TranslatePosition; import com.vaadin.client.widget.escalator.PositionFunction.WebkitTranslate3DPosition; +import com.vaadin.client.widget.escalator.Row; import com.vaadin.client.widget.escalator.RowContainer; import com.vaadin.client.widget.escalator.RowVisibilityChangeEvent; import com.vaadin.client.widget.escalator.RowVisibilityChangeHandler; @@ -2009,9 +2011,19 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker cellClone.getStyle().clearWidth(); rowElement.insertBefore(cellClone, cellOriginal); - maxCellWidth = Math.max(Util - .getRequiredWidthBoundingClientRectDouble(cellClone), - maxCellWidth); + double requiredWidth = Util + .getRequiredWidthBoundingClientRectDouble(cellClone); + + if (BrowserInfo.get().isIE9()) { + /* + * IE9 does not support subpixels. Usually it is rounded + * down which leads to content not shown. Increase the + * counted required size by one just to be on the safe side. + */ + requiredWidth += 1; + } + + maxCellWidth = Math.max(requiredWidth, maxCellWidth); cellClone.removeFromParent(); } diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index a5b90e5563..a32dccd391 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -54,6 +54,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.HasEnabled; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.ResizeComposite; import com.google.gwt.user.client.ui.Widget; @@ -82,7 +83,6 @@ import com.vaadin.client.widget.grid.EditorHandler; import com.vaadin.client.widget.grid.EditorHandler.EditorRequest; import com.vaadin.client.widget.grid.EditorHandler.EditorRequest.RequestCallback; import com.vaadin.client.widget.grid.EventCellReference; -import com.vaadin.client.widget.grid.GridUtil; import com.vaadin.client.widget.grid.RendererCellReference; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; @@ -171,7 +171,8 @@ import com.vaadin.shared.util.SharedUtil; * @author Vaadin Ltd */ public class Grid<T> extends ResizeComposite implements - HasSelectionHandlers<T>, SubPartAware, DeferredWorker, HasWidgets { + HasSelectionHandlers<T>, SubPartAware, DeferredWorker, HasWidgets, + HasEnabled { /** * Enum describing different sections of Grid. @@ -1246,7 +1247,7 @@ public class Grid<T> extends ResizeComposite implements protected void hideOverlay() { for (Widget w : columnToWidget.values()) { - GridUtil.setParent(w, null); + setParent(w, null); } columnToWidget.clear(); @@ -1284,7 +1285,7 @@ public class Grid<T> extends ResizeComposite implements private void attachWidget(Widget w, Element parent) { parent.appendChild(w.getElement()); - GridUtil.setParent(w, grid); + setParent(w, grid); } private static void setBounds(Element e, double left, double top, @@ -2449,6 +2450,8 @@ public class Grid<T> extends ResizeComposite implements */ private final AutoColumnWidthsRecalculator autoColumnWidthsRecalculator = new AutoColumnWidthsRecalculator(); + private boolean enabled = true; + /** * Enumeration for easy setting of selection mode. */ @@ -2513,7 +2516,7 @@ public class Grid<T> extends ResizeComposite implements @Override public void render(RendererCellReference cell, Object data) { - if (!warned) { + if (!warned && !(data instanceof String)) { getLogger().warning( Column.this.toString() + ": " + DEFAULT_RENDERER_WARNING); @@ -3030,7 +3033,7 @@ public class Grid<T> extends ResizeComposite implements cell.getElement().appendChild(widget.getElement()); // Logical attach - GridUtil.setParent(widget, Grid.this); + setParent(widget, Grid.this); } catch (RuntimeException e) { getLogger().log( Level.SEVERE, @@ -3172,7 +3175,7 @@ public class Grid<T> extends ResizeComposite implements if (w != null) { // Logical detach - GridUtil.setParent(w, null); + setParent(w, null); // Physical detach cell.getElement().removeChild(w.getElement()); @@ -3339,7 +3342,7 @@ public class Grid<T> extends ResizeComposite implements cellElement.appendChild(widget.getElement()); // Logical attach - GridUtil.setParent(widget, Grid.this); + setParent(widget, Grid.this); } } } @@ -3361,7 +3364,7 @@ public class Grid<T> extends ResizeComposite implements Widget widget = metadata.getWidget(); // Logical detach - GridUtil.setParent(widget, null); + setParent(widget, null); // Physical detach widget.getElement().removeFromParent(); @@ -3457,6 +3460,19 @@ public class Grid<T> extends ResizeComposite implements } @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public void setEnabled(boolean enabled) { + this.enabled = enabled; + getElement().setTabIndex(enabled ? 0 : -1); + getEscalator().setScrollLocked(Direction.VERTICAL, !enabled); + getEscalator().setScrollLocked(Direction.HORIZONTAL, !enabled); + } + + @Override public void setStylePrimaryName(String style) { super.setStylePrimaryName(style); escalator.setStylePrimaryName(style); @@ -4428,6 +4444,10 @@ public class Grid<T> extends ResizeComposite implements @Override public void onBrowserEvent(Event event) { + if (!isEnabled()) { + return; + } + EventTarget target = event.getEventTarget(); if (!Element.is(target)) { @@ -5654,4 +5674,17 @@ public class Grid<T> extends ResizeComposite implements */ return false; } + + /** + * Accesses the package private method Widget#setParent() + * + * @param widget + * The widget to access + * @param parent + * The parent to set + */ + private static native final void setParent(Widget widget, Grid<?> parent) + /*-{ + widget.@com.google.gwt.user.client.ui.Widget::setParent(Lcom/google/gwt/user/client/ui/Widget;)(parent); + }-*/; } diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 8e119f0d94..2b3e00e6f0 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -303,7 +303,7 @@ public class RpcDataProviderExtension extends AbstractExtension { } Object itemIdAtIndex(int index) { - return indexToItemId.inverse().get(Integer.valueOf(index)); + return indexToItemId.get(Integer.valueOf(index)); } } @@ -508,7 +508,7 @@ public class RpcDataProviderExtension extends AbstractExtension { activeRange.getEnd(), count); removeValueChangeListeners(deprecatedRange); - final Range freshRange = Range.between(firstIndex, count); + final Range freshRange = Range.withLength(firstIndex, count); addValueChangeListeners(freshRange); } else { // out of view, noop @@ -516,23 +516,39 @@ public class RpcDataProviderExtension extends AbstractExtension { } /** - * Removes a single item by its id. + * Handles the removal of rows. + * <p> + * This method's responsibilities are to: + * <ul> + * <li>shift the internal bookkeeping by <code>count</code> if the + * removal happens above currently active range + * <li>ignore rows removed below the currently active range + * </ul> * - * @param itemId - * the id of the removed id. <em>Note:</em> this item does - * not exist anymore in the datasource + * @param firstIndex + * the index of the first removed rows + * @param count + * the number of rows removed at <code>firstIndex</code> */ - public void removeItemId(Object itemId) { - final GridValueChangeListener removedListener = valueChangeListeners - .remove(itemId); - if (removedListener != null) { - /* - * We removed an item from somewhere in the visible range, so we - * make the active range shorter. The empty hole will be filled - * by the client-side code when it asks for more information. - */ + public void removeRows(int firstIndex, int count) { + int lastRemoved = firstIndex + count; + if (lastRemoved < activeRange.getStart()) { + /* firstIndex < lastIndex < start */ + activeRange = activeRange.offsetBy(-count); + } else if (firstIndex < activeRange.getEnd()) { + final Range deprecated = Range.between( + Math.max(activeRange.getStart(), firstIndex), + Math.min(activeRange.getEnd(), lastRemoved + 1)); + for (int i = deprecated.getStart(); i < deprecated.getEnd(); ++i) { + Object itemId = keyMapper.itemIdAtIndex(i); + // Item doesn't exist anymore. + valueChangeListeners.remove(itemId); + } + activeRange = Range.withLength(activeRange.getStart(), - activeRange.length() - 1); + activeRange.length() - deprecated.length()); + } else { + /* end <= firstIndex, no need to do anything */ } } } @@ -698,7 +714,8 @@ public class RpcDataProviderExtension extends AbstractExtension { @Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); - if (!clientInitialized) { + + if (initial) { clientInitialized = true; /* @@ -846,12 +863,7 @@ public class RpcDataProviderExtension extends AbstractExtension { rpc.removeRowData(firstIndex, count); } - for (int i = 0; i < count; i++) { - Object itemId = keyMapper.itemIdAtIndex(firstIndex + i); - if (itemId != null) { - activeRowHandler.removeItemId(itemId); - } - } + activeRowHandler.removeRows(firstIndex, count); } /** diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 7d8ec59533..d61458297a 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -1487,8 +1487,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, rows.add(index, row); getSectionState().rows.add(index, row.getRowState()); - Indexed dataSource = grid.getContainerDataSource(); - for (Object id : dataSource.getContainerPropertyIds()) { + for (Object id : grid.columns.keySet()) { row.addCell(id); } @@ -2528,21 +2527,50 @@ public class Grid extends AbstractComponent implements SelectionNotifier, .findMethod(SortListener.class, "sort", SortEvent.class); /** - * Creates a new Grid with a new {@link IndexedContainer} as the datasource. + * Creates a new Grid with a new {@link IndexedContainer} as the data + * source. */ public Grid() { - internalSetContainerDataSource(new IndexedContainer()); - initGrid(); + this(null, null); } /** - * Creates a new Grid using the given datasource. + * Creates a new Grid using the given data source. * - * @param datasource - * the data source for the grid + * @param dataSource + * the indexed container to use as a data source */ - public Grid(final Container.Indexed datasource) { - setContainerDataSource(datasource); + public Grid(final Container.Indexed dataSource) { + this(null, dataSource); + } + + /** + * Creates a new Grid with the given caption and a new + * {@link IndexedContainer} data source. + * + * @param caption + * the caption of the grid + */ + public Grid(String caption) { + this(caption, null); + } + + /** + * Creates a new Grid with the given caption and data source. If the data + * source is null, a new {@link IndexedContainer} will be used. + * + * @param caption + * the caption of the grid + * @param dataSource + * the indexed container to use as a data source + */ + public Grid(String caption, Container.Indexed dataSource) { + if (dataSource == null) { + internalSetContainerDataSource(new IndexedContainer()); + } else { + setContainerDataSource(dataSource); + } + setCaption(caption); initGrid(); } @@ -2781,7 +2809,6 @@ public class Grid extends AbstractComponent implements SelectionNotifier, removeExtension(datasourceExtension); } - columnKeys.removeAll(); datasource = container; resetEditor(); diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnAddingAndRemovingTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnAddingAndRemovingTest.java index f401fba1e3..97f0355b4b 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnAddingAndRemovingTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumnAddingAndRemovingTest.java @@ -102,6 +102,12 @@ public class GridColumnAddingAndRemovingTest { grid.setContainerDataSource(container2); assertNull("Grid should not have a column for property foo", grid.getColumn("foo")); + assertNotNull("Grid did should have a column for property bar", + grid.getColumn("bar")); + for (Grid.Column column : grid.getColumns()) { + assertNotNull("Grid getColumns returned a null value", column); + } + grid.removeAllColumns(); grid.addColumn("foo"); assertNotNull("Grid should now have a column for property foo", diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridStaticSectionTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridStaticSectionTest.java index c0b4afbdbe..4031886e7a 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridStaticSectionTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridStaticSectionTest.java @@ -16,6 +16,8 @@ package com.vaadin.tests.server.component.grid; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.lang.reflect.Method; @@ -73,6 +75,24 @@ public class GridStaticSectionTest extends Grid { } @Test + public void testUnusedPropertyNotInCells() { + removeColumn("firstName"); + assertNull("firstName cell was not removed from existing row", + getDefaultHeaderRow().getCell("firstName")); + HeaderRow newRow = appendHeaderRow(); + assertNull("firstName cell was created when it should not.", + newRow.getCell("firstName")); + addColumn("firstName"); + assertNotNull( + "firstName cell was not created for default row when added again", + getDefaultHeaderRow().getCell("firstName")); + assertNotNull( + "firstName cell was not created for new row when added again", + newRow.getCell("firstName")); + + } + + @Test public void testJoinHeaderCells() { HeaderRow mergeRow = prependHeaderRow(); mergeRow.join("firstName", "lastName").setText("Name"); diff --git a/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java b/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java index 80ffc42207..6059379dc5 100644 --- a/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java +++ b/shared/src/com/vaadin/shared/ui/tabsheet/TabsheetState.java @@ -19,8 +19,8 @@ import java.util.ArrayList; import java.util.List; import com.vaadin.shared.AbstractComponentState; -import com.vaadin.shared.annotations.NoLayout; import com.vaadin.shared.annotations.DelegateToWidget; +import com.vaadin.shared.annotations.NoLayout; public class TabsheetState extends AbstractComponentState { public static final String PRIMARY_STYLE_NAME = "v-tabsheet"; diff --git a/uitest/src/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java b/uitest/src/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java index d66a95a13c..cc5be455cd 100644 --- a/uitest/src/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java @@ -17,6 +17,8 @@ package com.vaadin.tests.components.grid; import static org.junit.Assert.assertEquals; +import java.io.IOException; + import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; @@ -60,10 +62,16 @@ public abstract class AbstractGridColumnAutoWidthTest extends MultiBrowserTest { bodyWidth); assertEquals("column should've been roughly as wide as the header", headerWidth, colWidth, 5); + } @Test public void testTooNarrowColumn() { + if (BrowserUtil.isIE(getDesiredCapabilities())) { + // IE can't deal with overflow nicely. + return; + } + WebElement[] col = getColumn(3); int headerWidth = col[0].getSize().getWidth(); int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; @@ -82,6 +90,11 @@ public abstract class AbstractGridColumnAutoWidthTest extends MultiBrowserTest { headerWidth); } + @Test + public void testColumnsRenderCorrectly() throws IOException { + compareScreen("initialRender"); + } + private WebElement[] getColumn(int i) { WebElement[] col = new WebElement[3]; col[0] = getDriver().findElement( diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java new file mode 100644 index 0000000000..4a331f3fa4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java @@ -0,0 +1,67 @@ +/* + * 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.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; + +public class GridInTabSheet extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TabSheet sheet = new TabSheet(); + final Grid grid = new Grid(); + grid.addColumn("count", Integer.class); + for (Integer i = 0; i < 3; ++i) { + grid.addRow(i); + } + + sheet.addTab(grid); + sheet.addTab(new Label("Hidden")); + + addComponent(sheet); + addComponent(new Button("Add row to Grid", new Button.ClickListener() { + + private Integer k = 0; + + @Override + public void buttonClick(ClickEvent event) { + grid.addRow(100 + (k++)); + } + })); + addComponent(new Button("Remove row from Grid", + new Button.ClickListener() { + + private Integer k = 0; + + @Override + public void buttonClick(ClickEvent event) { + Object firstItemId = grid.getContainerDataSource() + .firstItemId(); + if (firstItemId != null) { + grid.getContainerDataSource().removeItem( + firstItemId); + } + } + })); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java new file mode 100644 index 0000000000..0fe15b149b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java @@ -0,0 +1,59 @@ +/* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridInTabSheetTest extends MultiBrowserTest { + + @Test + public void testRemoveAllRowsAndAddThreeNewOnes() { + setDebug(true); + openTestURL(); + + for (int i = 0; i < 3; ++i) { + removeGridRow(); + } + + for (int i = 0; i < 3; ++i) { + addGridRow(); + assertEquals("" + (100 + i), getGridElement().getCell(i, 1) + .getText()); + } + assertFalse("There was an unexpected error notification", + isElementPresent(NotificationElement.class)); + } + + private void removeGridRow() { + $(ButtonElement.class).caption("Remove row from Grid").first().click(); + } + + private void addGridRow() { + $(ButtonElement.class).caption("Add row to Grid").first().click(); + } + + private GridElement getGridElement() { + return $(GridElement.class).first(); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/SelectDuringInit.java b/uitest/src/com/vaadin/tests/components/grid/SelectDuringInit.java new file mode 100644 index 0000000000..d8394acd19 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/SelectDuringInit.java @@ -0,0 +1,40 @@ +/* + * 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.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; + +public class SelectDuringInit extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.MULTI); + + grid.addColumn("value"); + grid.addRow("row 1"); + grid.addRow("row 2"); + grid.addRow("row 3"); + + grid.select(Integer.valueOf(2)); + + addComponent(grid); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/SelectDuringInitTest.java b/uitest/src/com/vaadin/tests/components/grid/SelectDuringInitTest.java new file mode 100644 index 0000000000..edfc8031a8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/SelectDuringInitTest.java @@ -0,0 +1,35 @@ +/* + * 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.elements.GridElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class SelectDuringInitTest extends SingleBrowserTest { + + @Test + public void testSelectDuringInit() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertTrue(grid.getRow(1).isSelected()); + } + +} 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 99b7ef21c7..20b6a3c418 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -787,7 +787,7 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { createClickAction("Add first row", "Body rows", newRowCommand, null); - createClickAction("Add second row", "Body rows", new NewRowCommand(1), + createClickAction("Add third row", "Body rows", new NewRowCommand(2), null); createClickAction("Remove first row", "Body rows", 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 91dff944cb..0e339ec0ae 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java @@ -121,4 +121,15 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest { .findElement( By.xpath("//div[contains(@class, \"v-grid-scroller-vertical\")]")); } + + /** + * Reloads the page without restartApplication. This occasionally breaks + * stuff. + */ + protected void reopenTestURL() { + String testUrl = getTestUrl(); + testUrl = testUrl.replace("?restartApplication", "?"); + testUrl = testUrl.replace("?&", "?"); + driver.get(testUrl); + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java index cd31bfc860..79eadd03d8 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; +import com.vaadin.testbench.By; import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.testbench.elements.ServerClass; @@ -40,6 +41,7 @@ public class GridDefaultTextRendererTest extends MultiBrowserTest { @Before public void init() { + setDebug(true); openTestURL(); grid = $(MyGridElement.class).first(); assertFalse("There was an unexpected notification during init", @@ -57,4 +59,10 @@ public class GridDefaultTextRendererTest extends MultiBrowserTest { assertEquals("Second cell should've been populated ", "string", grid .getCell(1, 0).getText()); } + + @Test + public void testWarningShouldNotBeInDebugLog() { + assertFalse("Warning visible with string content.", + isElementPresent(By.xpath("//span[contains(.,'attached:#1')]"))); + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java new file mode 100644 index 0000000000..0038d3dabe --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java @@ -0,0 +1,58 @@ +/* + * 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.client; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class DisabledGridClientTest extends GridBasicFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "State", "Enabled"); + } + + @Test + public void testSelection() { + selectMenuPath("Component", "State", "Selection mode", "single"); + + GridRowElement row = getGridElement().getRow(0); + row.click(); + assertFalse("disabled row should not be selected", row.isSelected()); + + } + + @Test + public void testEditorOpening() { + selectMenuPath("Component", "Editor", "Enabled"); + + GridRowElement row = getGridElement().getRow(0); + row.click(); + assertNull("Editor should not open", getEditor()); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertNull("Editor should not open", getEditor()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java index 6b9e36b235..e808001cf7 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java @@ -69,7 +69,7 @@ public class EscalatorColumnFreezingTest extends populate(); selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); - int scrollPx = 100; + int scrollPx = 60; scrollHorizontallyTo(scrollPx); WebElement bodyCell = getBodyCell(0, 0); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/DisabledGridTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/DisabledGridTest.java new file mode 100644 index 0000000000..ed1234e608 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/DisabledGridTest.java @@ -0,0 +1,58 @@ +/* + * 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.server; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class DisabledGridTest extends GridBasicFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "State", "Enabled"); + } + + @Test + public void testSelection() { + selectMenuPath("Component", "State", "Selection mode", "single"); + + GridRowElement row = getGridElement().getRow(0); + row.click(); + assertFalse("disabled row should not be selected", row.isSelected()); + + } + + @Test + public void testEditorOpening() { + selectMenuPath("Component", "Editor", "Enabled"); + + GridRowElement row = getGridElement().getRow(0); + row.click(); + assertNull("Editor should not open", getEditor()); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertNull("Editor should not open", getEditor()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java index ef6d6bfa82..0c26ceb5c9 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java @@ -78,7 +78,7 @@ public class GridCellFocusAdjustmentTest extends GridBasicFeaturesTest { assertTrue("Body 0,0 should've gotten focus", getGridElement().getCell(0, 0).isFocused()); - selectMenuPath("Component", "Body rows", "Add second row"); + selectMenuPath("Component", "Body rows", "Add third row"); assertTrue("Body 0,0 should've remained focused", getGridElement() .getCell(0, 0).isFocused()); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java index fc44d5aaf5..643c61d90a 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java @@ -15,11 +15,14 @@ */ package com.vaadin.tests.components.grid.basicfeatures.server; +import static org.junit.Assert.assertFalse; + import org.junit.Assert; import org.junit.Test; import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; @@ -96,6 +99,18 @@ public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest { Assert.assertTrue(hasCssClass(cell3_2, "Column-2")); } + @Test + public void testCellStyleGeneratorWithSelectionColumn() { + setDebug(true); + openTestURL(); + selectMenuPath("Component", "State", "Selection mode", "multi"); + + selectCellStyleNameGenerator(GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } + private void selectRowStyleNameGenerator(String name) { selectMenuPath("Component", "State", "Row style generator", name); } 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 9a9f85ccb9..08f903b3fe 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 @@ -447,4 +447,39 @@ public class GridStructureTest extends GridBasicFeaturesTest { assertEquals("Scroll position should've not have changed", scrollPos, getGridVerticalScrollPos()); } + + @Test + public void testReloadPage() throws InterruptedException { + setDebug(true); + openTestURL(); + + reopenTestURL(); + + // After opening the URL Grid can be stuck in a state where it thinks it + // should wait for something that's not going to happen. + testBench().disableWaitForVaadin(); + + // Wait until page is loaded completely. + int count = 0; + while (!isElementPresent(GridElement.class)) { + if (count == 100) { + fail("Reloading page failed"); + } + sleep(100); + ++count; + } + + // Wait a bit more for notification to occur. + sleep(1000); + + assertFalse("Exception occurred when reloading page", + isElementPresent(NotificationElement.class)); + } + + @Test + public void testAddThirdRowToGrid() { + openTestURL(); + selectMenuPath("Component", "Body rows", "Add third row"); + assertFalse(logContainsText("Exception occured")); + } } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java index 173ae097ed..4f1ea48be5 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java @@ -47,10 +47,18 @@ public class GridDefaultTextRendererWidget extends } }); + grid.addColumn(new Column<String, String>() { + + @Override + public String getValue(String row) { + return "foo"; + } + + }); + grid.setHeightByRows(2); grid.setHeightMode(HeightMode.ROW); grid.setSelectionMode(SelectionMode.NONE); addNorth(grid, 500); } - } |