BaseCellSelectionManager implements CellSelectionManager { @Override public boolean selectCell(final Point2D rp, final boolean isShiftKeyDown, final boolean isControlKeyDown) { final Integer uiRowIndex = CoordinateUtilities.getUiRowIndex(gridWidget, rp.getY()); final Integer uiColumnIndex = CoordinateUtilities.getUiColumnIndex(gridWidget, rp.getX()); if (uiRowIndex == null || uiColumnIndex == null) { return false; } return selectCell(uiRowIndex, uiColumnIndex, isShiftKeyDown, isControlKeyDown); } BaseCellSelectionManager(final GridWidget gridWidget); @Override boolean selectCell(final Point2D rp,
                              final boolean isShiftKeyDown,
                              final boolean isControlKeyDown); @Override boolean selectCell(final int uiRowIndex,
                              final int uiColumnIndex,
                              final boolean isShiftKeyDown,
                              final boolean isControlKeyDown); @Override boolean selectHeaderCell(final Point2D rp,
                                    final boolean isShiftKeyDown,
                                    final boolean isControlKeyDown); @Override boolean selectHeaderCell(final int uiHeaderRowIndex,
                                    final int uiHeaderColumnIndex,
                                    final boolean isShiftKeyDown,
                                    final boolean isControlKeyDown); @Override boolean adjustSelection(final SelectionExtension direction,
                                   final boolean isShiftKeyDown); @Override boolean startEditingCell(final Point2D rp); @Override boolean startEditingCell(final int uiRowIndex,
                                    final int uiColumnIndex);  }
@Test public void selectCellPointCoordinateOutsideGridBounds() { cellSelectionManager.selectCell(new Point2D(-10, -10), false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertTrue(selectedCells.isEmpty()); }
@Test public void selectCellPointCoordinateWithinGridBounds() { cellSelectionManager.selectCell(new Point2D(50, 42), false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertEquals(1, selectedCells.size()); assertEquals(0, selectedCells.get(0).getRowIndex()); assertEquals(0, selectedCells.get(0).getColumnIndex()); }
@Test public void selectCellPointCoordinateWithinGridBoundsWithShiftKey() { cellSelectionManager.selectCell(new Point2D(50, 42), false, false); cellSelectionManager.selectCell(new Point2D(150, 62), true, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertEquals(4, selectedCells.size()); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 0))); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 1))); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 1))); assertTrue(selectedCells.contains(new GridData.SelectedCell(1, 1))); assertEquals(new GridData.SelectedCell(0, 0), gridWidgetData.getSelectedCellsOrigin()); }
@Test public void selectCellPointCoordinateWithinGridBoundsWithControlKey() { cellSelectionManager.selectCell(new Point2D(50, 42), false, false); cellSelectionManager.selectCell(new Point2D(150, 62), false, true); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertEquals(2, selectedCells.size()); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 0))); assertTrue(selectedCells.contains(new GridData.SelectedCell(1, 1))); assertEquals(new GridData.SelectedCell(0, 0), gridWidgetData.getSelectedCellsOrigin()); }
@Test public void selectCellRowCoordinateLessThanZero() { cellSelectionManager.selectCell(-1, 0, false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertTrue(selectedCells.isEmpty()); }
@Test public void selectCellRowCoordinateGreaterThanRowCount() { cellSelectionManager.selectCell(2, 0, false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertTrue(selectedCells.isEmpty()); }
@Test public void selectCellColumnCoordinateLessThanZero() { cellSelectionManager.selectCell(0, -1, false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertTrue(selectedCells.isEmpty()); }
@Test public void selectCellColumnCoordinateGreaterThanColumnCount() { cellSelectionManager.selectCell(0, 3, false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertTrue(selectedCells.isEmpty()); }
@Test public void selectCellWithoutShiftKeyWithoutControlKey() { cellSelectionManager.selectCell(0, 0, false, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertEquals(1, selectedCells.size()); assertEquals(0, selectedCells.get(0).getRowIndex()); assertEquals(0, selectedCells.get(0).getColumnIndex()); assertEquals(new GridData.SelectedCell(0, 0), gridWidgetData.getSelectedCellsOrigin()); }
@Test public void selectCellWithShiftKey() { cellSelectionManager.selectCell(0, 0, false, false); cellSelectionManager.selectCell(1, 1, true, false); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertEquals(4, selectedCells.size()); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 0))); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 1))); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 1))); assertTrue(selectedCells.contains(new GridData.SelectedCell(1, 1))); assertEquals(new GridData.SelectedCell(0, 0), gridWidgetData.getSelectedCellsOrigin()); }
@Test public void selectCellWithControlKey() { cellSelectionManager.selectCell(0, 0, false, false); cellSelectionManager.selectCell(1, 1, false, true); final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells(); assertEquals(2, selectedCells.size()); assertTrue(selectedCells.contains(new GridData.SelectedCell(0, 0))); assertTrue(selectedCells.contains(new GridData.SelectedCell(1, 1))); }