Skip to content

Commit

Permalink
Distribute GridUtil methods where they are actually used (#13334)
Browse files Browse the repository at this point in the history
Change-Id: I10f015d0f5fce8f005a4ebdfeb218025459cf751
  • Loading branch information
Henrik Paul authored and Legioth committed Dec 30, 2014
1 parent 8355e9d commit 464cab6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 105 deletions.
59 changes: 56 additions & 3 deletions client/src/com/vaadin/client/renderers/ClickableRenderer.java
Expand Up @@ -26,8 +26,12 @@
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.google.web.bindery.event.shared.HandlerRegistration; 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.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; import com.vaadin.client.widgets.Grid;


/** /**
Expand Down Expand Up @@ -122,13 +126,62 @@ protected void dispatch(RendererClickHandler handler) {
} }


Element e = Element.as(target); 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(); row = cell.getRow();


handler.onClick(this); 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; private HandlerManager handlerManager;
Expand Down
95 changes: 0 additions & 95 deletions client/src/com/vaadin/client/widget/grid/GridUtil.java

This file was deleted.

26 changes: 19 additions & 7 deletions client/src/com/vaadin/client/widgets/Grid.java
Expand Up @@ -83,7 +83,6 @@
import com.vaadin.client.widget.grid.EditorHandler.EditorRequest; import com.vaadin.client.widget.grid.EditorHandler.EditorRequest;
import com.vaadin.client.widget.grid.EditorHandler.EditorRequest.RequestCallback; import com.vaadin.client.widget.grid.EditorHandler.EditorRequest.RequestCallback;
import com.vaadin.client.widget.grid.EventCellReference; 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.RendererCellReference;
import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowReference;
import com.vaadin.client.widget.grid.RowStyleGenerator; import com.vaadin.client.widget.grid.RowStyleGenerator;
Expand Down Expand Up @@ -1248,7 +1247,7 @@ public void onClick(ClickEvent event) {


protected void hideOverlay() { protected void hideOverlay() {
for (Widget w : columnToWidget.values()) { for (Widget w : columnToWidget.values()) {
GridUtil.setParent(w, null); setParent(w, null);
} }
columnToWidget.clear(); columnToWidget.clear();


Expand Down Expand Up @@ -1286,7 +1285,7 @@ protected Element createCell(TableCellElement td) {


private void attachWidget(Widget w, Element parent) { private void attachWidget(Widget w, Element parent) {
parent.appendChild(w.getElement()); parent.appendChild(w.getElement());
GridUtil.setParent(w, grid); setParent(w, grid);
} }


private static void setBounds(Element e, double left, double top, private static void setBounds(Element e, double left, double top,
Expand Down Expand Up @@ -3034,7 +3033,7 @@ public void postAttach(Row row, Iterable<FlyweightCell> attachedCells) {
cell.getElement().appendChild(widget.getElement()); cell.getElement().appendChild(widget.getElement());


// Logical attach // Logical attach
GridUtil.setParent(widget, Grid.this); setParent(widget, Grid.this);
} catch (RuntimeException e) { } catch (RuntimeException e) {
getLogger().log( getLogger().log(
Level.SEVERE, Level.SEVERE,
Expand Down Expand Up @@ -3176,7 +3175,7 @@ public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
if (w != null) { if (w != null) {


// Logical detach // Logical detach
GridUtil.setParent(w, null); setParent(w, null);


// Physical detach // Physical detach
cell.getElement().removeChild(w.getElement()); cell.getElement().removeChild(w.getElement());
Expand Down Expand Up @@ -3343,7 +3342,7 @@ public void postAttach(Row row, Iterable<FlyweightCell> attachedCells) {
cellElement.appendChild(widget.getElement()); cellElement.appendChild(widget.getElement());


// Logical attach // Logical attach
GridUtil.setParent(widget, Grid.this); setParent(widget, Grid.this);
} }
} }
} }
Expand All @@ -3365,7 +3364,7 @@ public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
Widget widget = metadata.getWidget(); Widget widget = metadata.getWidget();


// Logical detach // Logical detach
GridUtil.setParent(widget, null); setParent(widget, null);


// Physical detach // Physical detach
widget.getElement().removeFromParent(); widget.getElement().removeFromParent();
Expand Down Expand Up @@ -5675,4 +5674,17 @@ public boolean remove(Widget w) {
*/ */
return false; 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);
}-*/;
} }

0 comments on commit 464cab6

Please sign in to comment.