/** * Get the x-offset for a given Column in the model relative to zero. * @param column The GridColumn. * @return */ public double getColumnOffset(final GridColumn<?> column) { final GridData model = view.getModel(); final int columnIndex = model.getColumns().indexOf(column); if (columnIndex == -1) { return 0; } return getColumnOffset(columnIndex); }
/** * Get the x-offset for a given Column in the model relative to zero. * @param column The GridColumn. * @return */ public double getColumnOffset(final GridColumn<?> column) { final GridData model = view.getModel(); final int columnIndex = model.getColumns().indexOf(column); if (columnIndex == -1) { return 0; } return getColumnOffset(columnIndex); }
private BaseGridRendererHelper.ColumnInformation getBodyColumnInformation(final int uiColumnIndex) { final GridColumn<?> column = gridModel.getColumns().get(uiColumnIndex); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation(); final BaseGridRendererHelper.RenderingBlockInformation bodyBlockInformation = renderingInformation.getBodyBlockInformation(); final List<GridColumn<?>> bodyColumns = bodyBlockInformation.getColumns(); if (!bodyColumns.contains(column)) { return null; } return new BaseGridRendererHelper.ColumnInformation(column, uiColumnIndex, bodyBlockInformation.getX() + rendererHelper.getColumnOffset(bodyColumns, bodyColumns.indexOf(column))); }
private BaseGridRendererHelper.ColumnInformation getFloatingColumnInformation(final int uiColumnIndex) { final GridColumn<?> column = gridModel.getColumns().get(uiColumnIndex); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation(); final BaseGridRendererHelper.RenderingBlockInformation floatingBlockInformation = renderingInformation.getFloatingBlockInformation(); final List<GridColumn<?>> floatingColumns = floatingBlockInformation.getColumns(); if (!floatingColumns.contains(column)) { return null; } return new BaseGridRendererHelper.ColumnInformation(column, uiColumnIndex, floatingBlockInformation.getX() + rendererHelper.getColumnOffset(floatingColumns, floatingColumns.indexOf(column))); }
private BaseGridRendererHelper.ColumnInformation getFloatingColumnInformation(final int uiColumnIndex) { final GridColumn<?> column = gridModel.getColumns().get(uiColumnIndex); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation(); final BaseGridRendererHelper.RenderingBlockInformation floatingBlockInformation = renderingInformation.getFloatingBlockInformation(); final List<GridColumn<?>> floatingColumns = floatingBlockInformation.getColumns(); if (!floatingColumns.contains(column)) { return null; } return new BaseGridRendererHelper.ColumnInformation(column, uiColumnIndex, floatingBlockInformation.getX() + rendererHelper.getColumnOffset(floatingColumns, floatingColumns.indexOf(column))); }
private BaseGridRendererHelper.ColumnInformation getBodyColumnInformation(final int uiColumnIndex) { final GridColumn<?> column = gridModel.getColumns().get(uiColumnIndex); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation(); final BaseGridRendererHelper.RenderingBlockInformation bodyBlockInformation = renderingInformation.getBodyBlockInformation(); final List<GridColumn<?>> bodyColumns = bodyBlockInformation.getColumns(); if (!bodyColumns.contains(column)) { return null; } return new BaseGridRendererHelper.ColumnInformation(column, uiColumnIndex, bodyBlockInformation.getX() + rendererHelper.getColumnOffset(bodyColumns, bodyColumns.indexOf(column))); }
@Test public void testEditWhenHeaderCellSelected() { final GridColumn.HeaderMetaData headerMetaDataC1 = mock(GridColumn.HeaderMetaData.class); final GridColumn.HeaderMetaData headerMetaDataC2 = mock(GridColumn.HeaderMetaData.class); final GridColumn<?> gridColumnOne = mockGridColumn(100.0, Arrays.asList(headerMetaDataC1)); final GridColumn<?> gridColumnTwo = mockGridColumn(100.0, Arrays.asList(headerMetaDataC2)); doReturn(0).when(gridColumnOne).getIndex(); doReturn(1).when(gridColumnTwo).getIndex(); final double secondColumnXCoordinate = gridColumnOne.getWidth() + gridColumnTwo.getWidth() / 2; doReturn(ci).when(gridRendererHelper).getColumnInformation(secondColumnXCoordinate); doReturn(gridColumnOne.getWidth()).when(gridRendererHelper).getColumnOffset(gridColumnTwo); doReturn(gridColumnTwo).when(ci).getColumn(); doReturn(0.0).when(ci).getOffsetX(); doReturn(1).when(ci).getUiColumnIndex(); doReturn(Arrays.asList(gridColumnOne, gridColumnTwo)).when(ri).getAllColumns(); gridWidget.getModel().appendColumn(gridColumnOne); gridWidget.getModel().appendColumn(gridColumnTwo); gridWidget.getModel().selectHeaderCell(0, 1); CellContextUtilities.editSelectedCell(gridWidget); verify(headerMetaDataC1, never()).edit(any(GridBodyCellEditContext.class)); verify(headerMetaDataC2).edit(gridBodyCellEditContextCaptor.capture()); final GridBodyCellEditContext gridBodyCellEditContext = gridBodyCellEditContextCaptor.getValue(); assertThat(gridBodyCellEditContext) .hasFieldOrPropertyWithValue("columnIndex", 1) .hasFieldOrPropertyWithValue("rowIndex", 0); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void testEditWhenHeaderCellSelected() { final GridColumn.HeaderMetaData headerMetaDataC1 = mock(GridColumn.HeaderMetaData.class); final GridColumn.HeaderMetaData headerMetaDataC2 = mock(GridColumn.HeaderMetaData.class); final GridColumn<?> gridColumnOne = mockGridColumn(100.0, Arrays.asList(headerMetaDataC1)); final GridColumn<?> gridColumnTwo = mockGridColumn(100.0, Arrays.asList(headerMetaDataC2)); doReturn(0).when(gridColumnOne).getIndex(); doReturn(1).when(gridColumnTwo).getIndex(); final double secondColumnXCoordinate = gridColumnOne.getWidth() + gridColumnTwo.getWidth() / 2; doReturn(ci).when(gridRendererHelper).getColumnInformation(secondColumnXCoordinate); doReturn(gridColumnOne.getWidth()).when(gridRendererHelper).getColumnOffset(gridColumnTwo); doReturn(gridColumnTwo).when(ci).getColumn(); doReturn(0.0).when(ci).getOffsetX(); doReturn(1).when(ci).getUiColumnIndex(); doReturn(Arrays.asList(gridColumnOne, gridColumnTwo)).when(ri).getAllColumns(); gridWidget.getModel().appendColumn(gridColumnOne); gridWidget.getModel().appendColumn(gridColumnTwo); gridWidget.getModel().selectHeaderCell(0, 1); CellContextUtilities.editSelectedCell(gridWidget); verify(headerMetaDataC1, never()).edit(any(GridBodyCellEditContext.class)); verify(headerMetaDataC2).edit(gridBodyCellEditContextCaptor.capture()); final GridBodyCellEditContext gridBodyCellEditContext = gridBodyCellEditContextCaptor.getValue(); assertThat(gridBodyCellEditContext) .hasFieldOrPropertyWithValue("columnIndex", 1) .hasFieldOrPropertyWithValue("rowIndex", 0); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
public static void editSelectedCell(final GridWidget gridWidget) { final GridData gridModel = gridWidget.getModel(); if (gridModel.getSelectedHeaderCells().size() > 0) { final GridData.SelectedCell selectedCell = gridModel.getSelectedHeaderCells().get(0); final int uiHeaderRowIndex = selectedCell.getRowIndex(); final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(gridModel.getColumns(), selectedCell.getColumnIndex()); final GridColumn<?> column = gridModel.getColumns().get(uiColumnIndex); final GridColumn.HeaderMetaData headerMetaData = column.getHeaderMetaData().get(uiHeaderRowIndex); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation ri = rendererHelper.getRenderingInformation(); final double columnXCoordinate = rendererHelper.getColumnOffset(column) + column.getWidth() / 2; final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(columnXCoordinate); final GridBodyCellEditContext context = CellContextUtilities.makeRenderContext(gridWidget, ri, ci, null, uiHeaderRowIndex); headerMetaData.edit(context); } else if (gridModel.getSelectedCells().size() > 0) { final GridData.SelectedCell origin = gridModel.getSelectedCellsOrigin(); if (origin == null) { return; } gridWidget.startEditingCell(origin.getRowIndex(), ColumnIndexUtilities.findUiColumnIndex(gridModel.getColumns(), origin.getColumnIndex())); } }
public static void editSelectedCell(final GridWidget gridWidget) { final GridData gridModel = gridWidget.getModel(); if (gridModel.getSelectedHeaderCells().size() > 0) { final GridData.SelectedCell selectedCell = gridModel.getSelectedHeaderCells().get(0); final int uiHeaderRowIndex = selectedCell.getRowIndex(); final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(gridModel.getColumns(), selectedCell.getColumnIndex()); final GridColumn<?> column = gridModel.getColumns().get(uiColumnIndex); final GridColumn.HeaderMetaData headerMetaData = column.getHeaderMetaData().get(uiHeaderRowIndex); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation ri = rendererHelper.getRenderingInformation(); final double columnXCoordinate = rendererHelper.getColumnOffset(column) + column.getWidth() / 2; final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(columnXCoordinate); final GridBodyCellEditContext context = CellContextUtilities.makeRenderContext(gridWidget, ri, ci, null, uiHeaderRowIndex); headerMetaData.edit(context); } else if (gridModel.getSelectedCells().size() > 0) { final GridData.SelectedCell origin = gridModel.getSelectedCellsOrigin(); if (origin == null) { return; } gridWidget.startEditingCell(origin.getRowIndex(), ColumnIndexUtilities.findUiColumnIndex(gridModel.getColumns(), origin.getColumnIndex())); } }
when( rendererHelper.getColumnOffset( uiColumn1 ) ).thenReturn( 0.0 ); when( rendererHelper.getColumnOffset( uiColumn2 ) ).thenReturn( uiColumn1.getWidth() );
private int getScreenX(final GuidedDecisionTableModellerView modellerView, final GuidedDecisionTableView.Presenter dtPresenter, final int uiColumnIndex) { final GridWidget gridWidget = dtPresenter.getView(); final GridColumn<?> uiColumn = gridWidget.getModel().getColumns().get(uiColumnIndex); final double gx = gridWidget.getX(); final GridLayer layer = modellerView.getGridLayerView(); final int containerX = layer.getDomElementContainer().getAbsoluteLeft(); final double vx = layer.getVisibleBounds().getX(); final Transform t = layer.getViewport().getTransform(); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation ri = rendererHelper.getRenderingInformation(); final BaseGridRendererHelper.RenderingBlockInformation floatingBlockInformation = ri.getFloatingBlockInformation(); final double offsetX = floatingBlockInformation.getColumns().contains(uiColumn) ? floatingBlockInformation.getX() : 0; final int screenX = containerX + (int) ((gx - vx + offsetX + rendererHelper.getColumnOffset(uiColumn) + uiColumn.getWidth() / 2) * t.getScaleX()); return screenX; }
private int getScreenX(final GuidedDecisionTableModellerView modellerView, final GuidedDecisionTableView.Presenter dtPresenter, final int uiColumnIndex) { final GridWidget gridWidget = dtPresenter.getView(); final GridColumn<?> uiColumn = gridWidget.getModel().getColumns().get(uiColumnIndex); final double gx = gridWidget.getX(); final GridLayer layer = modellerView.getGridLayerView(); final int containerX = layer.getDomElementContainer().getAbsoluteLeft(); final double vx = layer.getVisibleBounds().getX(); final Transform t = layer.getViewport().getTransform(); final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation ri = rendererHelper.getRenderingInformation(); final BaseGridRendererHelper.RenderingBlockInformation floatingBlockInformation = ri.getFloatingBlockInformation(); final double offsetX = floatingBlockInformation.getColumns().contains(uiColumn) ? floatingBlockInformation.getX() : 0; final int screenX = containerX + (int) ((gx - vx + offsetX + rendererHelper.getColumnOffset(uiColumn) + uiColumn.getWidth() / 2) * t.getScaleX()); return screenX; }
private double getCellScrollDeltaX(final GridWidget gridWidget) { final GridData gridModel = gridWidget.getModel(); final List<GridColumn<?>> columns = gridModel.getColumns(); final GridData.SelectedCell origin = gridModel.getSelectedCellsOrigin(); final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(columns, origin.getColumnIndex()); double dx = 0; final Bounds bounds = gridLayer.getVisibleBounds(); final double columnWidth = columns.get(uiColumnIndex).getWidth(); final double gridCellX = gridWidget.getX() + gridWidget.getRendererHelper().getColumnOffset(uiColumnIndex); if (gridCellX + columnWidth >= bounds.getX() + bounds.getWidth()) { dx = bounds.getX() + bounds.getWidth() - gridCellX - columnWidth; } else if (gridCellX <= bounds.getX()) { dx = bounds.getX() - gridCellX; } return dx; }
private double getCellScrollDeltaX(final GridWidget gridWidget) { final GridData gridModel = gridWidget.getModel(); final List<GridColumn<?>> columns = gridModel.getColumns(); final GridData.SelectedCell origin = gridModel.getSelectedCellsOrigin(); final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(columns, origin.getColumnIndex()); double dx = 0; final Bounds bounds = gridLayer.getVisibleBounds(); final double columnWidth = columns.get(uiColumnIndex).getWidth(); final double gridCellX = gridWidget.getX() + gridWidget.getRendererHelper().getColumnOffset(uiColumnIndex); if (gridCellX + columnWidth >= bounds.getX() + bounds.getWidth()) { dx = bounds.getX() + bounds.getWidth() - gridCellX - columnWidth; } else if (gridCellX <= bounds.getX()) { dx = bounds.getX() - gridCellX; } return dx; }
final double columnWidth = column.getWidth(); final double columnRelativeX = rendererHelper.getColumnOffset(blockColumns, blockColumns.indexOf(column)) + absoluteColumnOffsetX; final boolean isFloating = floatingBlockInformation.getColumns().contains(column);
selectedCellsHeightStrategy); if (cs != null) { final double csx = rendererHelper.getColumnOffset(blockColumns, _selectedRange.getUiColumnIndex() - minVisibleUiColumnIndex); final double csy = selectedCellsYOffsetStrategy.apply(_selectedRange, minVisibleUiRowIndex);
selectedCellsHeightStrategy); if (cs != null) { final double csx = rendererHelper.getColumnOffset(blockColumns, _selectedRange.getUiColumnIndex() - minVisibleUiColumnIndex); final double csy = selectedCellsYOffsetStrategy.apply(_selectedRange, minVisibleUiRowIndex);
@SuppressWarnings("unchecked") protected void showColumnHighlight(final GridWidget view, final List<GridColumn<?>> activeGridColumns) { final BaseGridRendererHelper rendererHelper = view.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation(); if (renderingInformation == null) { return; } final Group header = view.getHeader(); final double headerRowsYOffset = renderingInformation.getHeaderRowsYOffset(); final double headerMinY = (header == null ? headerRowsYOffset : header.getY() + headerRowsYOffset); final Bounds bounds = renderingInformation.getBounds(); final double activeColumnX = rendererHelper.getColumnOffset(activeGridColumns.get(0)); final double highlightWidth = getHighlightWidth(activeGridColumns); final double highlightHeight = getHighlightHeight(bounds, view, headerMinY); state.getEventColumnHighlight().setWidth(highlightWidth) .setHeight(highlightHeight) .setX(view.getAbsoluteX() + activeColumnX) .setY(view.getAbsoluteY() + headerMinY); layer.add(state.getEventColumnHighlight()); layer.getLayer().batch(); }
@SuppressWarnings("unchecked") protected void showColumnHighlight(final GridWidget view, final List<GridColumn<?>> activeGridColumns) { final BaseGridRendererHelper rendererHelper = view.getRendererHelper(); final BaseGridRendererHelper.RenderingInformation renderingInformation = rendererHelper.getRenderingInformation(); if (renderingInformation == null) { return; } final Group header = view.getHeader(); final double headerRowsYOffset = renderingInformation.getHeaderRowsYOffset(); final double headerMinY = (header == null ? headerRowsYOffset : header.getY() + headerRowsYOffset); final Bounds bounds = renderingInformation.getBounds(); final double activeColumnX = rendererHelper.getColumnOffset(activeGridColumns.get(0)); final double highlightWidth = getHighlightWidth(activeGridColumns); final double highlightHeight = getHighlightHeight(bounds, view, headerMinY); state.getEventColumnHighlight().setWidth(highlightWidth) .setHeight(highlightHeight) .setX(view.getAbsoluteX() + activeColumnX) .setY(view.getAbsoluteY() + headerMinY); layer.add(state.getEventColumnHighlight()); layer.getLayer().batch(); }