CoordinateUtilities { public static Integer getUiRowIndex(final GridWidget gridWidget, final double relativeY) { final Group header = gridWidget.getHeader(); final GridData gridModel = gridWidget.getModel(); final GridRenderer renderer = gridWidget.getRenderer(); final double headerMaxY = (header == null ? renderer.getHeaderHeight() : renderer.getHeaderHeight() + header.getY()); if (relativeY < headerMaxY || relativeY > gridWidget.getHeight()) { return null; } if (gridModel.getRowCount() == 0) { return null; } GridRow row; int uiRowIndex = 0; double offsetY = relativeY - renderer.getHeaderHeight(); while ((row = gridModel.getRow(uiRowIndex)).getHeight() < offsetY) { offsetY = offsetY - row.getHeight(); uiRowIndex++; } if (uiRowIndex > gridModel.getRowCount() - 1) { return null; } return uiRowIndex; }  static Point2D convertDOMToGridCoordinate(final GridWidget view,
                                                     final Point2D point); static Integer getUiRowIndex(final GridWidget gridWidget,
                                        final double relativeY); static Integer getUiColumnIndex(final GridWidget gridWidget,
                                           final double relativeX); static Integer getUiHeaderRowIndex(final GridWidget gridWidget,
                                              final Point2D rp); static int getRelativeXOfEvent(final DomEvent event); static int getRelativeYOfEvent(final DomEvent event);  }
@Test public void testGetUiRowIndexOverHeader() throws Exception { setupGridWidget(); final Integer rowIndex = CoordinateUtilities.getUiRowIndex(view, -1); Assertions.assertThat(rowIndex).isNull(); }
@Test public void testGetUiRowIndexInHeader() throws Exception { setupGridWidget(); final Integer rowIndex = CoordinateUtilities.getUiRowIndex(view, gridRenderer.getHeaderHeight() - 1); Assertions.assertThat(rowIndex).isNull(); }
@Test public void testGetUiRowIndexInHeaderInFirstRow() throws Exception { gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); setupGridWidget(); final Integer rowIndex = CoordinateUtilities.getUiRowIndex(view, gridRenderer.getHeaderHeight() + 1); Assertions.assertThat(rowIndex).isEqualTo(0); }
@Test public void testGetUiRowIndexInHeaderInSecondRow() throws Exception { gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); setupGridWidget(); final Integer rowIndex = CoordinateUtilities.getUiRowIndex(view, gridRenderer.getHeaderHeight() + DEFAULT_ROW_HEIGHT + 1); Assertions.assertThat(rowIndex).isEqualTo(1); }
@Test public void testGetUiRowIndexInHeaderInThirdRow() throws Exception { gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); setupGridWidget(); final Integer rowIndex = CoordinateUtilities.getUiRowIndex(view, gridRenderer.getHeaderHeight() + (DEFAULT_ROW_HEIGHT * 2) + 1); Assertions.assertThat(rowIndex).isEqualTo(2); }
@Test public void testGetUiRowIndexInHeaderBelowLastRow() throws Exception { gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); gridData.appendRow(new BaseGridRow()); setupGridWidget(); final Integer rowIndex = CoordinateUtilities.getUiRowIndex(view, gridRenderer.getHeaderHeight() + (DEFAULT_ROW_HEIGHT * 3) + 1); Assertions.assertThat(rowIndex).isNull(); }