GridWidgetDnDMouseMoveHandler implements NodeMouseMoveHandler { protected void findMovableRows(final GridWidget view, final BaseGridRendererHelper.RenderingInformation renderingInformation, final double cx, final double cy) { if (!isOverRowDragHandleColumn(renderingInformation, cx)) { return; } final GridData gridModel = view.getModel(); final GridRenderer renderer = view.getRenderer(); final List<Double> allRowHeights = renderingInformation.getAllRowHeights(); if (gridModel.getRowCount() == 0) { return; } double rowHeight; int uiRowIndex = 0; double offsetY = cy - renderer.getHeaderHeight(); while ((rowHeight = allRowHeights.get(uiRowIndex)) < offsetY) { offsetY = offsetY - rowHeight; uiRowIndex++; } if (uiRowIndex < 0 || uiRowIndex > gridModel.getRowCount() - 1) { return; } final List<GridRow> rows = new ArrayList<>(); rows.add(gridModel.getRow(uiRowIndex)); GridRow collapsedRow; while (uiRowIndex + 1 < gridModel.getRowCount() && (collapsedRow = gridModel.getRow(uiRowIndex + 1)).isCollapsed()) { rows.add(collapsedRow); uiRowIndex++; } state.setActiveGridWidget(view); state.setActiveGridRows(rows); state.setOperation(GridWidgetDnDHandlersState.GridWidgetHandlersOperation.ROW_MOVE_PENDING); setCursor(Style.Cursor.MOVE); } GridWidgetDnDMouseMoveHandler(final GridLayer layer,
                                         final GridWidgetDnDHandlersState state); @Override @SuppressWarnings("unchecked") void onNodeMouseMove(final NodeMouseMoveEvent event);  }
@Test public void findMovableRows() { when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.NONE); when(gridWidget.isVisible()).thenReturn(true); when(layer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget)); final int eventX = (int) (gridWidget.getComputedLocation().getX() + uiColumn1.getWidth() / 2); final int eventY = (int) (gridWidget.getComputedLocation().getY() + renderer.getHeaderHeight() + uiModel.getRow(0).getHeight() + uiModel.getRow(1).getHeight() / 2); when(event.getX()).thenReturn(eventX); when(event.getY()).thenReturn(eventY); handler.onNodeMouseMove(event); verify(handler, times(1)).findGridColumn(eq(event)); verify(handler, never()).findMovableColumns(any(GridWidget.class), any(BaseGridRendererHelper.RenderingInformation.class), any(Double.class), any(Double.class), any(Double.class), any(Double.class)); verify(handler, times(1)).findMovableRows(any(GridWidget.class), any(BaseGridRendererHelper.RenderingInformation.class), any(Double.class), any(Double.class)); verify(handler, times(1)).findResizableColumn(any(GridWidget.class), any(BaseGridRendererHelper.RenderingInformation.class), any(Double.class)); verify(state, times(1)).setActiveGridWidget(eq(gridWidget)); verify(state, times(1)).setOperation(eq(GridWidgetHandlersOperation.ROW_MOVE_PENDING)); verify(state, times(1)).setActiveGridRows(uiRowsArgumentCaptor.capture()); final List<GridRow> uiRows = uiRowsArgumentCaptor.getValue(); assertNotNull(uiRows); assertEquals(1, uiRows.size()); assertTrue(uiRows.contains(uiModel.getRow(1))); }