CellContextUtilities { public static GridBodyCellEditContext makeCellRenderContext(final GridWidget gridWidget, final BaseGridRendererHelper.RenderingInformation ri, final BaseGridRendererHelper.ColumnInformation ci, final int uiRowIndex) { final GridColumn<?> column = ci.getColumn(); final GridRenderer renderer = gridWidget.getRenderer(); final double cellX = getCellX(gridWidget, ci); final double cellY = getCellY(gridWidget, uiRowIndex); final BaseGridRendererHelper.RenderingBlockInformation floatingBlockInformation = ri.getFloatingBlockInformation(); final double clipMinX = getClipMinX(gridWidget, floatingBlockInformation); final double clipMinY = getClipMinY(gridWidget); final double blockCellWidth = column.getWidth(); final double blockCellHeight = ri.getAllRowHeights().get(uiRowIndex); return new GridBodyCellEditContext(cellX, cellY, blockCellWidth, blockCellHeight, clipMinY, clipMinX, uiRowIndex, ci.getUiColumnIndex(), floatingBlockInformation.getColumns().contains(column), gridWidget.getViewport().getTransform(), renderer, Optional.empty()); }  static GridBodyCellEditContext makeCellRenderContext(final GridWidget gridWidget,
                                                                final BaseGridRendererHelper.RenderingInformation ri,
                                                                final BaseGridRendererHelper.ColumnInformation ci,
                                                                final int uiRowIndex); static GridBodyCellEditContext makeHeaderCellRenderContext(final GridWidget gridWidget,
                                                                      final BaseGridRendererHelper.RenderingInformation ri,
                                                                      final BaseGridRendererHelper.ColumnInformation ci,
                                                                      final int uiHeaderRowIndex); static GridBodyCellEditContext makeHeaderCellRenderContext(final GridWidget gridWidget,
                                                                      final BaseGridRendererHelper.RenderingInformation ri,
                                                                      final BaseGridRendererHelper.ColumnInformation ci,
                                                                      final Point2D rp,
                                                                      final int uiHeaderRowIndex); static void editSelectedCell(final GridWidget gridWidget); static void editSelectedCell(final GridWidget gridWidget,
                                        final Point2D relativeLocation);  }
@Test public void testMakeCellRenderContextOneRow() { final List<GridColumn<?>> allColumns = new ArrayList<>(); final List<Double> allRowHeights = Collections.singletonList(row1.getHeight()); final GridColumn<?> uiColumn1 = mockGridColumn(25.0); final GridColumn<?> uiColumn2 = mockGridColumn(60.0); final GridColumn<?> uiColumn3 = mockGridColumn(100.0); allColumns.add(uiColumn1); allColumns.add(uiColumn2); allColumns.add(uiColumn3); gridWidget.getModel().appendRow(row1); doReturn(allColumns).when(ri).getAllColumns(); doReturn(allRowHeights).when(ri).getAllRowHeights(); doReturn(uiColumn2).when(ci).getColumn(); doReturn(25.0).when(ci).getOffsetX(); doReturn(1).when(ci).getUiColumnIndex(); final GridBodyCellEditContext context = CellContextUtilities.makeCellRenderContext(gridWidget, ri, ci, 0); assertNotNull(context); assertThat(context.getAbsoluteCellX()) .as("Should be column offset") .isEqualTo(25.0); assertThat(context.getAbsoluteCellY()) .as("Should be headers height") .isEqualTo(HEADER_HEIGHT); }
@Test public void testMakeCellRenderContextThreeRows() { setupThreeRowGrid(); final GridBodyCellEditContext context = CellContextUtilities.makeCellRenderContext(gridWidget, ri, ci, 2); assertNotNull(context); assertThat(context.getAbsoluteCellX()) .as("Should be column offset") .isEqualTo(25.0); assertThat(context.getAbsoluteCellY()) .as("Should be sum of header height plus preceding row heights") .isEqualTo(HEADER_HEIGHT + row1.getHeight() + row2.getHeight()); }
@Test public void testMakeCellRenderContextThreeRowsWhenScrolled() { setupThreeRowGrid(); final Point2D gridComputedLocation = new Point2D(0, -row1.getHeight()); doReturn(gridComputedLocation).when(gridWidget).getComputedLocation(); final GridBodyCellEditContext context = CellContextUtilities.makeCellRenderContext(gridWidget, ri, ci, 2); assertNotNull(context); assertThat(context.getAbsoluteCellX()) .as("Should be column offset") .isEqualTo(25.0); assertThat(context.getAbsoluteCellY()) .as("Should be sum of header height plus preceding visible row heights") .isEqualTo(HEADER_HEIGHT + row2.getHeight()); }