GridWidgetDnDMouseMoveHandler implements NodeMouseMoveHandler { protected void handleRowMove(final NodeMouseMoveEvent event) { final GridWidget activeGridWidget = state.getActiveGridWidget(); final List<GridRow> activeGridRows = state.getActiveGridRows(); final GridData activeGridModel = activeGridWidget.getModel(); final List<GridColumn<?>> allGridColumns = activeGridModel.getColumns(); final BaseGridRendererHelper rendererHelper = activeGridWidget.getRendererHelper(); final GridRenderer renderer = activeGridWidget.getRenderer(); final double headerHeight = renderer.getHeaderHeight(); final GridRow leadRow = activeGridRows.get(0); final int leadRowIndex = activeGridModel.getRows().indexOf(leadRow); final Point2D ap = CoordinateUtilities.convertDOMToGridCoordinate(activeGridWidget, new Point2D(event.getX(), event.getY())); final double cy = ap.getY(); if (cy < headerHeight || cy > activeGridWidget.getHeight()) { return; } GridRow row; int uiRowIndex = 0; double offsetY = cy - headerHeight; while ((row = activeGridModel.getRow(uiRowIndex)).getHeight() < offsetY) { offsetY = offsetY - row.getHeight(); uiRowIndex++; } if (uiRowIndex < 0 || uiRowIndex > activeGridModel.getRowCount() - 1) { return; } if (uiRowIndex == leadRowIndex) { return; } else if (uiRowIndex < activeGridModel.getRows().indexOf(leadRow)) { if (offsetY > activeGridModel.getRow(uiRowIndex).getHeight() / 2) { return; } } else if (uiRowIndex > activeGridModel.getRows().indexOf(leadRow)) { if (offsetY < activeGridModel.getRow(uiRowIndex).getHeight() / 2) { return; } } destroyColumns(allGridColumns); activeGridModel.moveRowsTo(uiRowIndex, activeGridRows); final double rowOffsetY = rendererHelper.getRowOffset(leadRow) + headerHeight; state.getEventColumnHighlight().setY(activeGridWidget.getComputedLocation().getY() + rowOffsetY); state.setOperation(GridWidgetDnDHandlersState.GridWidgetHandlersOperation.ROW_MOVE); layer.batch(); } GridWidgetDnDMouseMoveHandler(final GridLayer layer,
                                         final GridWidgetDnDHandlersState state); @Override @SuppressWarnings("unchecked") void onNodeMouseMove(final NodeMouseMoveEvent event);  }
@Test public void handleRowMove() { final List<GridRow> existingRowOrder = new ArrayList<>(uiModel.getRows()); final GridWidgetDnDProxy highlight = mock(GridWidgetDnDProxy.class); when(state.getEventColumnHighlight()).thenReturn(highlight); 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() / 2); when(event.getX()).thenReturn(eventX); when(event.getY()).thenReturn(eventY); handler.onNodeMouseMove(event); final int eventNewY = (int) (gridWidget.getComputedLocation().getY() + renderer.getHeaderHeight() + uiModel.getRow(0).getHeight() + uiModel.getRow(1).getHeight() / 2); when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.ROW_MOVE); when(event.getY()).thenReturn(eventNewY); handler.onNodeMouseMove(event); verify(highlight).setY(gridWidget.getComputedLocation().getY() + renderer.getHeaderHeight()); verify(layer).batch(); assertEquals(existingRowOrder.get(0), uiModel.getRow(1)); assertEquals(existingRowOrder.get(1), uiModel.getRow(0)); assertEquals(existingRowOrder.get(2), uiModel.getRow(2)); }