GridWidgetDnDMouseMoveHandler implements NodeMouseMoveHandler { protected double adjustColumnWidth(double columnNewWidth, GridColumn<?> activeGridColumn, GridWidget activeGridWidget) { final GridData activeGridModel = activeGridWidget.getModel(); double originalLeftColumnWidth = activeGridColumn.getWidth(); double delta = originalLeftColumnWidth - columnNewWidth; int visibleWidth = activeGridModel.getVisibleWidth(); double gridWidgetWidth = activeGridWidget.getWidth(); double newGridWidth = gridWidgetWidth - delta; if (newGridWidth < visibleWidth && delta > 0) { Optional<GridColumn<?>> rightGridColumn = getFirstRightAutoColumn(activeGridColumn, activeGridModel); if (rightGridColumn.isPresent()) { GridColumn<?> rightColumn = rightGridColumn.get(); double originalRightColumnWidth = rightColumn.getWidth(); double widthWithoutColumn = gridWidgetWidth - originalRightColumnWidth; double newWidth = visibleWidth - widthWithoutColumn + delta; rightColumn.setWidth(newWidth); } else if (GridColumn.ColumnWidthMode.isAuto(activeGridColumn)) { double widthWithoutColumn = gridWidgetWidth - originalLeftColumnWidth; columnNewWidth = visibleWidth - widthWithoutColumn; } } return columnNewWidth; } GridWidgetDnDMouseMoveHandler(final GridLayer layer,
                                         final GridWidgetDnDHandlersState state); @Override @SuppressWarnings("unchecked") void onNodeMouseMove(final NodeMouseMoveEvent event);  }
@Test public void adjustColumnWidth() { double proposedNewWidth = 100; uiModel.setVisibleSizeAndRefresh(10, 0); assertEquals(proposedNewWidth, handler.adjustColumnWidth(proposedNewWidth, column, gridWidget), 0.1); uiModel.setVisibleSizeAndRefresh(1000, 0); proposedNewWidth = 300; assertEquals(proposedNewWidth, handler.adjustColumnWidth(proposedNewWidth, column, gridWidget), 0.1); proposedNewWidth = 50; uiColumn2.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); int visibleWidth = gridWidget.getModel().getVisibleWidth(); double adjustedWidth = handler.adjustColumnWidth(proposedNewWidth, uiColumn2, gridWidget); double widthWithoutColumn = gridWidget.getModel() .getColumns().stream() .filter(col -> !col.equals(uiColumn2)) .mapToDouble(GridColumn::getWidth) .sum(); assertEquals(visibleWidth - widthWithoutColumn, adjustedWidth, 0.1); column.setColumnWidthMode(GridColumn.ColumnWidthMode.FIXED); uiModel.appendColumn(column); uiModel.appendColumn(rightColumn); rightColumn.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); assertEquals(proposedNewWidth, handler.adjustColumnWidth(proposedNewWidth, column, gridWidget), 0.1); double columnDelta = column.getWidth() - proposedNewWidth; double widthWithoutRightColumn = gridWidget.getWidth() - originalRightColumnWidth; double newRightColumnWidth = visibleWidth - widthWithoutRightColumn + columnDelta; assertEquals(newRightColumnWidth, rightColumn.getWidth(), 0.1); }