/** * Edit the cell (normally in response to a mouse double-click event) * @param cell * @param context * @param callback */ default void edit(final GridCell<T> cell, final GridBodyCellEditContext context, final Consumer<GridCellValue<T>> callback) { edit(cell, (GridBodyCellRenderContext) context, callback); }
/** * Edit the cell (normally in response to a mouse double-click event) * @param cell * @param context * @param callback */ default void edit(final GridCell<T> cell, final GridBodyCellEditContext context, final Consumer<GridCellValue<T>> callback) { edit(cell, (GridBodyCellRenderContext) context, callback); }
@Test @SuppressWarnings("unchecked") public void startEditingCellCoordinateOutsideGridBounds() { cellSelectionManager.startEditingCell(-1, -1); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); }
@Test @SuppressWarnings("unchecked") public void startEditingCellCoordinateOutsideGridBounds() { cellSelectionManager.startEditingCell(-1, -1); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); }
@Test @SuppressWarnings("unchecked") public void startEditingCellPointCoordinateOutsideGridBounds() { cellSelectionManager.startEditingCell(new Point2D(-10, -10)); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); }
@Test @SuppressWarnings("unchecked") public void startEditingCellPointCoordinateOutsideGridBounds() { cellSelectionManager.startEditingCell(new Point2D(-10, -10)); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellRenderContext.class), any(Consumer.class)); verify(col1, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); verify(col2, never()).edit(any(GridCell.class), any(GridBodyCellEditContext.class), any(Consumer.class)); }
@SuppressWarnings("unchecked") private void assertStartEditingCoordinateWithinGridBounds(final Group header) { when(gridWidget.getHeader()).thenReturn(header); cellSelectionManager.startEditingCell(0, 1); verify(col2, times(1)).edit(any(GridCell.class), contextArgumentCaptor.capture(), any(Consumer.class)); verify(col2, times(1)).edit(any(GridCell.class), editContextArgumentCaptor.capture(), any(Consumer.class)); final GridBodyCellRenderContext context = contextArgumentCaptor.getValue(); assertEquals(0, context.getRowIndex()); assertEquals(1, context.getColumnIndex()); final GridBodyCellEditContext editContext = editContextArgumentCaptor.getValue(); assertFalse(editContext.getRelativeLocation().isPresent()); cellSelectionManager.startEditingCell(new Point2D(10, HEADER_HEIGHT + 1)); } }
@SuppressWarnings("unchecked") private void assertStartEditingCoordinateWithinGridBounds(final Group header) { when(gridWidget.getHeader()).thenReturn(header); cellSelectionManager.startEditingCell(0, 1); verify(col2, times(1)).edit(any(GridCell.class), contextArgumentCaptor.capture(), any(Consumer.class)); verify(col2, times(1)).edit(any(GridCell.class), editContextArgumentCaptor.capture(), any(Consumer.class)); final GridBodyCellRenderContext context = contextArgumentCaptor.getValue(); assertEquals(0, context.getRowIndex()); assertEquals(1, context.getColumnIndex()); final GridBodyCellEditContext editContext = editContextArgumentCaptor.getValue(); assertFalse(editContext.getRelativeLocation().isPresent()); cellSelectionManager.startEditingCell(new Point2D(10, HEADER_HEIGHT + 1)); } }
@SuppressWarnings("unchecked") protected void doEdit(final GridBodyCellEditContext context) { final int uiRowIndex = context.getRowIndex(); final int uiColumnIndex = context.getColumnIndex(); final GridData gridModel = gridWidget.getModel(); final GridColumn column = gridModel.getColumns().get(uiColumnIndex); final GridCell<?> cell = gridModel.getCell(uiRowIndex, uiColumnIndex); column.edit(cell, context, value -> { gridModel.setCellValue(uiRowIndex, uiColumnIndex, (GridCellValue<?>) value); gridWidget.getLayer().batch(); }); } }
@SuppressWarnings("unchecked") protected void doEdit(final GridBodyCellEditContext context) { final int uiRowIndex = context.getRowIndex(); final int uiColumnIndex = context.getColumnIndex(); final GridData gridModel = gridWidget.getModel(); final GridColumn column = gridModel.getColumns().get(uiColumnIndex); final GridCell<?> cell = gridModel.getCell(uiRowIndex, uiColumnIndex); column.edit(cell, context, value -> { gridModel.setCellValue(uiRowIndex, uiColumnIndex, (GridCellValue<?>) value); gridWidget.getLayer().batch(); }); } }
@Test @SuppressWarnings("unchecked") public void startEditingCellPointCoordinateWithinGridBounds() { final Point2D editedAtPoint = new Point2D(col1.getWidth() + col2.getWidth() / 2, HEADER_HEIGHT + ROW_HEIGHT / 2); cellSelectionManager.startEditingCell(editedAtPoint); verify(col2, times(1)).edit(any(GridCell.class), contextArgumentCaptor.capture(), any(Consumer.class)); verify(col2, times(1)).edit(any(GridCell.class), editContextArgumentCaptor.capture(), any(Consumer.class)); final GridBodyCellRenderContext context = contextArgumentCaptor.getValue(); assertEquals(0, context.getRowIndex()); assertEquals(1, context.getColumnIndex()); final GridBodyCellEditContext editContext = editContextArgumentCaptor.getValue(); assertTrue(editContext.getRelativeLocation().isPresent()); assertEquals(editedAtPoint.add(gridWidget.getComputedLocation()), editContext.getRelativeLocation().get()); }
@Test @SuppressWarnings("unchecked") public void startEditingCellPointCoordinateWithinGridBounds() { final Point2D editedAtPoint = new Point2D(col1.getWidth() + col2.getWidth() / 2, HEADER_HEIGHT + ROW_HEIGHT / 2); cellSelectionManager.startEditingCell(editedAtPoint); verify(col2, times(1)).edit(any(GridCell.class), contextArgumentCaptor.capture(), any(Consumer.class)); verify(col2, times(1)).edit(any(GridCell.class), editContextArgumentCaptor.capture(), any(Consumer.class)); final GridBodyCellRenderContext context = contextArgumentCaptor.getValue(); assertEquals(0, context.getRowIndex()); assertEquals(1, context.getColumnIndex()); final GridBodyCellEditContext editContext = editContextArgumentCaptor.getValue(); assertTrue(editContext.getRelativeLocation().isPresent()); assertEquals(editedAtPoint.add(gridWidget.getComputedLocation()), editContext.getRelativeLocation().get()); }