Skip to content

Commit

Permalink
DROOLS-5442: Asume column visibility during keyboard navigation (#998)
Browse files Browse the repository at this point in the history
DROOLS-5442: Asume column visibility during keyboard navigation (#998)
  • Loading branch information
Jozef Marko committed Jul 22, 2020
1 parent 4f621a2 commit 83f99d5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ private boolean moveInHeaderHorizontally(final SelectionExtension direction,
columnHeaderMetaData,
selectedHeaderCell.getRowIndex(),
uiColumnIndex);

int proposedUiColumnIndex = uiColumnIndex + direction.getDeltaX();
final int hiddenColumnXCompensation = computeHiddenColumnsCompensation(proposedUiColumnIndex, direction);
proposedUiColumnIndex = proposedUiColumnIndex + hiddenColumnXCompensation;

if (direction == SelectionExtension.LEFT) {
proposedUiColumnIndex = Math.min(headerBlockStartIndex - 1,
Expand Down Expand Up @@ -313,6 +314,25 @@ private int findMaxUiColumnIndex(final GridData.SelectedCell origin) {
return maxUiColumnIndex;
}

/**
* @return count of hidden columns that are as one hidden section starting on given index
*/
private int computeHiddenColumnsCompensation(final int startingIndex,
final SelectionExtension direction) {
int index = startingIndex;
int hiddenColumnsCount = 0;
if (gridModel.getColumnCount() > 0) {
while (!gridModel.getColumns().get(index).isVisible()) {
hiddenColumnsCount++;
index += direction.getDeltaX();
if (index < 0 || index >= gridModel.getColumnCount()) {
break;
}
}
}
return hiddenColumnsCount * direction.getDeltaX();
}

private boolean moveSelection(final GridData.SelectedCell origin,
final SelectionExtension direction) {
final int dx = direction.getDeltaX();
Expand All @@ -321,7 +341,9 @@ private boolean moveSelection(final GridData.SelectedCell origin,
final int currentUiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(gridModel.getColumns(),
origin.getColumnIndex());
final int proposedUiRowIndex = currentUiRowIndex + dy;
final int proposedUiColumnIndex = currentUiColumnIndex + dx;
int proposedUiColumnIndex = currentUiColumnIndex + dx;
final int hiddenColumnXCompensation = computeHiddenColumnsCompensation(proposedUiColumnIndex, direction);
proposedUiColumnIndex = proposedUiColumnIndex + hiddenColumnXCompensation;

if (canMoveFromDataToHeader(direction, proposedUiRowIndex)) {
return moveFromDataToHeader(proposedUiColumnIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class BaseCellSelectionManagerTest {
100));
private GridColumn<String> col2 = spy(new BaseGridTest.MockMergableGridColumn<>("col2",
100));
private GridColumn<String> col3 = spy(new BaseGridTest.MockMergableGridColumn<>("col3",
100));

private Bounds visibleBounds = new BaseBounds(-1000,
-1000,
Expand All @@ -119,6 +121,7 @@ public void setup() {
gridWidgetData.appendRow(new BaseGridRow(ROW_HEIGHT));
gridWidgetData.appendColumn(col1);
gridWidgetData.appendColumn(col2);
gridWidgetData.appendColumn(col3);

when(gridWidget.getModel()).thenReturn(gridWidgetData);

Expand All @@ -128,7 +131,7 @@ public void setup() {
when(gridWidget.getRenderer()).thenReturn(gridWidgetRenderer);
when(gridWidget.getRendererHelper()).thenReturn(gridWidgetRendererHelper);
when(gridWidget.getLayer()).thenReturn(gridLayer);
when(gridWidget.getWidth()).thenReturn(200.0);
when(gridWidget.getWidth()).thenReturn(300.0);
when(gridWidget.getHeader()).thenReturn(gridWidgetHeader);
when(gridWidget.getHeight()).thenReturn(HEADER_HEIGHT + (ROW_HEIGHT * 2));
when(gridWidget.getViewport()).thenReturn(viewport);
Expand Down Expand Up @@ -254,7 +257,7 @@ public void selectCellColumnCoordinateLessThanZero() {
@Test
public void selectCellColumnCoordinateGreaterThanColumnCount() {
cellSelectionManager.selectCell(0,
2,
3,
false,
false);

Expand Down Expand Up @@ -381,6 +384,28 @@ public void adjustSelectionLeft() {
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionLeftAndFindVisible() {
// DROOLS-5442
when(col2.isVisible()).thenReturn(false);

cellSelectionManager.selectCell(0,
2,
false,
false);
cellSelectionManager.adjustSelection(SelectionExtension.LEFT,
false);

final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells();
assertEquals(1,
selectedCells.size());
assertTrue(selectedCells.contains(new GridData.SelectedCell(0,
0)));
assertEquals(new GridData.SelectedCell(0,
0),
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionLeftWithShiftKey() {
cellSelectionManager.selectCell(0,
Expand Down Expand Up @@ -421,6 +446,28 @@ public void adjustSelectionRight() {
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionRightAndFindVisible() {
// DROOLS-5442
when(col2.isVisible()).thenReturn(false);

cellSelectionManager.selectCell(0,
0,
false,
false);
cellSelectionManager.adjustSelection(SelectionExtension.RIGHT,
false);

final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells();
assertEquals(1,
selectedCells.size());
assertTrue(selectedCells.contains(new GridData.SelectedCell(0,
2)));
assertEquals(new GridData.SelectedCell(0,
2),
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionRightWithShiftKey() {
cellSelectionManager.selectCell(0,
Expand Down

0 comments on commit 83f99d5

Please sign in to comment.