CoordinateUtilities { public static Integer getUiHeaderRowIndex(final GridWidget gridWidget, final Point2D rp) { final double relativeX = rp.getX(); final double relativeY = rp.getY(); final Group header = gridWidget.getHeader(); final GridRenderer renderer = gridWidget.getRenderer(); final BaseGridRendererHelper.RenderingInformation ri = gridWidget.getRendererHelper().getRenderingInformation(); final double headerRowsYOffset = ri.getHeaderRowsYOffset(); final double headerMinY = (header == null ? headerRowsYOffset : header.getY() + headerRowsYOffset); final double headerMaxY = (header == null ? renderer.getHeaderHeight() : renderer.getHeaderHeight() + header.getY()); if (relativeX < 0 || relativeX > gridWidget.getWidth()) { return null; } if (relativeY < headerMinY || relativeY > headerMaxY) { return null; } final int headerRowCount = gridWidget.getModel().getHeaderRowCount(); if (headerRowCount < 1) { return null; } final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(relativeX); final GridColumn<?> uiColumn = ci.getColumn(); if (uiColumn == null) { return null; } int uiHeaderRowIndex = 0; double offsetY = relativeY - headerMinY; final double headerRowHeight = renderer.getHeaderRowHeight(); final double headerRowsHeight = headerRowHeight * headerRowCount; final double columnHeaderRowHeight = headerRowsHeight / uiColumn.getHeaderMetaData().size(); while (columnHeaderRowHeight < offsetY) { offsetY = offsetY - columnHeaderRowHeight; uiHeaderRowIndex++; } if (uiHeaderRowIndex < 0 || uiHeaderRowIndex > uiColumn.getHeaderMetaData().size() - 1) { return null; } return uiHeaderRowIndex; }  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 @SuppressWarnings("unchecked") public void testGetUiHeaderRowIndexHeaderMinY() { point = new Point2D(COLUMN_WIDTH / 2, -5.0); setupGridWidget(); final GridColumn uiColumn = new BaseGridColumn<>(new BaseHeaderMetaData("first"), gridColumnRenderer, COLUMN_WIDTH); gridData.appendColumn(uiColumn); doReturn(uiColumn).when(ci).getColumn(); final Integer uiHeaderRowIndex = CoordinateUtilities.getUiHeaderRowIndex(view, point); assertNull(uiHeaderRowIndex); }
@Test @SuppressWarnings("unchecked") public void testGetUiHeaderRowIndexHeaderMaxY() { point = new Point2D(COLUMN_WIDTH / 2, gridRenderer.getHeaderHeight() + 5.0); setupGridWidget(); final GridColumn uiColumn = new BaseGridColumn<>(new BaseHeaderMetaData("first"), gridColumnRenderer, COLUMN_WIDTH); gridData.appendColumn(uiColumn); doReturn(uiColumn).when(ci).getColumn(); final Integer uiHeaderRowIndex = CoordinateUtilities.getUiHeaderRowIndex(view, point); assertNull(uiHeaderRowIndex); }
@Test @SuppressWarnings("unchecked") public void testGetUiHeaderRowIndexRow0() { point = new Point2D(COLUMN_WIDTH / 2, gridRenderer.getHeaderRowHeight() - 5.0); setupGridWidget(); final GridColumn uiColumn = new BaseGridColumn<>(new BaseHeaderMetaData("first"), gridColumnRenderer, COLUMN_WIDTH); gridData.appendColumn(uiColumn); doReturn(uiColumn).when(ci).getColumn(); final Integer uiHeaderRowIndex = CoordinateUtilities.getUiHeaderRowIndex(view, point); assertNotNull(uiHeaderRowIndex); assertEquals(0, (int) uiHeaderRowIndex); }
@Test @SuppressWarnings("unchecked") public void testGetUiHeaderRowIndexRow1() { point = new Point2D(COLUMN_WIDTH / 2, gridRenderer.getHeaderRowHeight() + 5.0); setupGridWidget(); final List<GridColumn.HeaderMetaData> headerMetaData = new ArrayList<>(); headerMetaData.add(new BaseHeaderMetaData("first")); headerMetaData.add(new BaseHeaderMetaData("second")); final GridColumn uiColumn = new BaseGridColumn<>(headerMetaData, gridColumnRenderer, COLUMN_WIDTH); gridData.appendColumn(uiColumn); doReturn(uiColumn).when(ci).getColumn(); final Integer uiHeaderRowIndex = CoordinateUtilities.getUiHeaderRowIndex(view, point); assertNotNull(uiHeaderRowIndex); assertEquals(1, (int) uiHeaderRowIndex); }
@Test public void testGetUiHeaderRowIndexOnNoRowsHeader() { point = new Point2D(COLUMN_WIDTH / 2, gridRenderer.getHeaderRowHeight() - 5.0); setupGridWidget(); gridData.setHeaderRowCount(0); final Integer uiHeaderRowIndex = CoordinateUtilities.getUiHeaderRowIndex(view, point); assertNull(uiHeaderRowIndex); }