GridWidgetDnDMouseDownHandler implements NodeMouseDownHandler { @Override public void onNodeMouseDown(final NodeMouseDownEvent event) { if (state.getActiveGridWidget() == null) { return; } final GridWidget activeGridWidget = state.getActiveGridWidget(); final Point2D ap = CoordinateUtilities.convertDOMToGridCoordinate(activeGridWidget, new Point2D(event.getX(), event.getY())); switch (state.getOperation()) { case COLUMN_RESIZE_PENDING: if (state.getActiveGridColumns().isEmpty()) { return; } state.setEventInitialX(ap.getX()); state.setEventInitialColumnWidth(state.getActiveGridColumns().get(0).getWidth()); state.setOperation(GridWidgetDnDHandlersState.GridWidgetHandlersOperation.COLUMN_RESIZE); break; case COLUMN_MOVE_PENDING: if (state.getActiveGridColumns().isEmpty()) { return; } state.setEventInitialX(ap.getX()); state.setOperation(GridWidgetDnDHandlersState.GridWidgetHandlersOperation.COLUMN_MOVE_INITIATED); showColumnHighlight(state.getActiveGridWidget(), state.getActiveGridColumns()); break; case ROW_MOVE_PENDING: if (state.getActiveGridRows().isEmpty()) { return; } state.setEventInitialX(ap.getX()); state.setOperation(GridWidgetDnDHandlersState.GridWidgetHandlersOperation.ROW_MOVE_INITIATED); showRowHighlight(state.getActiveGridWidget(), state.getActiveGridRows()); break; case GRID_MOVE_PENDING: state.setOperation(GridWidgetDnDHandlersState.GridWidgetHandlersOperation.GRID_MOVE); activeGridWidget.setDragMode(DragMode.SAME_LAYER); activeGridWidget.setDraggable(true); setCursor(Style.Cursor.MOVE); } } GridWidgetDnDMouseDownHandler(final GridLayer layer,
                                         final GridWidgetDnDHandlersState state); @Override void onNodeMouseDown(final NodeMouseDownEvent event);  }
@Test public void skipNonActiveGrid() { when(state.getActiveGridWidget()).thenReturn(null); handler.onNodeMouseDown(event); verify(event, never()).getX(); verify(event, never()).getY(); }
@Test public void stateColumnResizePendingMovesToColumnResize() { when(state.getActiveGridWidget()).thenReturn(gridWidget); when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.COLUMN_RESIZE_PENDING); when(state.getActiveGridColumns()).thenReturn(new ArrayList<GridColumn<?>>() {{ add(uiColumn); }}); handler.onNodeMouseDown(event); verify(state, times(1)).setOperation(GridWidgetHandlersOperation.COLUMN_RESIZE); }
@Test public void stateColumnResizePendingWithNoActiveColumn() { when(state.getActiveGridWidget()).thenReturn(gridWidget); when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.COLUMN_RESIZE_PENDING); when(state.getActiveGridColumns()).thenReturn(Collections.emptyList()); handler.onNodeMouseDown(event); verify(state, never()).setOperation(any(GridWidgetHandlersOperation.class)); }
@Test public void stateGridMovePendingMovesToGridMove() { when(state.getActiveGridWidget()).thenReturn(gridWidget); when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.GRID_MOVE_PENDING); handler.onNodeMouseDown(event); verify(state, times(1)).setOperation(GridWidgetHandlersOperation.GRID_MOVE); verify(gridWidget, times(1)).setDraggable(eq(true)); }
@Test @SuppressWarnings("unchecked") public void testColumnHighlight() { final GridWidgetDnDProxy highlight = mock(GridWidgetDnDProxy.class); final Bounds bounds = new BaseBounds(GRID_X, GRID_Y, GRID_WIDTH, GRID_HEIGHT); when(state.getEventColumnHighlight()).thenReturn(highlight); when(state.getActiveGridWidget()).thenReturn(gridWidget); when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.COLUMN_MOVE_PENDING); when(state.getActiveGridColumns()).thenReturn(Collections.singletonList(uiColumn)); when(rendererHelper.getRenderingInformation()).thenReturn(renderingInformation); when(rendererHelper.getRowOffset(anyInt(), any(List.class))).thenCallRealMethod(); when(renderingInformation.getBounds()).thenReturn(bounds); when(gridWidget.getHeader()).thenReturn(gridWidgetHeader); when(gridWidget.getHeight()).thenReturn(GRID_HEIGHT); when(uiColumn.getWidth()).thenReturn(COLUMN_WIDTH); handler.onNodeMouseDown(event); verify(highlight).setWidth(COLUMN_WIDTH); verify(highlight).setHeight(GRID_HEIGHT); verify(highlight).setX(GRID_X); verify(highlight).setY(GRID_Y); verify(layer).batch(); }
@Test public void testRowHighlight() { final GridWidgetDnDProxy highlight = mock(GridWidgetDnDProxy.class); final Bounds bounds = new BaseBounds(GRID_X, GRID_Y, GRID_WIDTH, GRID_HEIGHT); final GridData gridData = new BaseGridData(); gridData.appendRow(uiRow); when(state.getEventColumnHighlight()).thenReturn(highlight); when(state.getActiveGridWidget()).thenReturn(gridWidget); when(state.getOperation()).thenReturn(GridWidgetHandlersOperation.ROW_MOVE_PENDING); when(state.getActiveGridRows()).thenReturn(Collections.singletonList(uiRow)); when(rendererHelper.getRenderingInformation()).thenReturn(renderingInformation); when(renderingInformation.getBounds()).thenReturn(bounds); when(renderingInformation.getAllRowHeights()).thenReturn(Collections.singletonList(ROW_HEIGHT)); when(gridWidget.getModel()).thenReturn(gridData); when(gridWidget.getHeader()).thenReturn(gridWidgetHeader); when(gridWidget.getWidth()).thenReturn(GRID_WIDTH); when(uiRow.getHeight()).thenReturn(ROW_HEIGHT); handler.onNodeMouseDown(event); verify(highlight).setWidth(GRID_WIDTH); verify(highlight).setHeight(ROW_HEIGHT); verify(highlight).setX(GRID_X); verify(highlight).setY(GRID_Y + HEADER_HEIGHT); verify(layer).batch(); }