diff options
author | Henrik Paul <henrik@vaadin.com> | 2014-12-19 09:33:53 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2014-12-30 10:47:32 +0000 |
commit | 464cab6680a18bcac5fce702e8b1a1b87af4051e (patch) | |
tree | 8fc170daa461e5b41aee9d8102b2d29c6c081e18 /client | |
parent | 8355e9d00fd6025ce390293f9cf5fc8fdd45d0e8 (diff) | |
download | vaadin-framework-464cab6680a18bcac5fce702e8b1a1b87af4051e.tar.gz vaadin-framework-464cab6680a18bcac5fce702e8b1a1b87af4051e.zip |
Distribute GridUtil methods where they are actually used (#13334)
Change-Id: I10f015d0f5fce8f005a4ebdfeb218025459cf751
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/renderers/ClickableRenderer.java | 59 | ||||
-rw-r--r-- | client/src/com/vaadin/client/widget/grid/GridUtil.java | 95 | ||||
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 26 |
3 files changed, 75 insertions, 105 deletions
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/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/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index e53e79c46b..4756921325 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -83,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; @@ -1248,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(); @@ -1286,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, @@ -3034,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, @@ -3176,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()); @@ -3343,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); } } } @@ -3365,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(); @@ -5675,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); + }-*/; } |