public void onInsertColumn(final int index) { final List<GridData.SelectedCell> selectedCells = gridData.getSelectedCells(); final List<Integer> rowsWithASelection = selectedCells.stream() .filter(sc -> { final int ri = sc.getRowIndex(); final int ci = sc.getColumnIndex(); final int _ci = ColumnIndexUtilities.findUiColumnIndex(gridData.getColumns(), ci); final GridCell<?> cell = gridData.getCell(ri, _ci); return cell != null && cell.getSelectionStrategy() instanceof RowSelectionStrategy; }) .map(GridData.SelectedCell::getRowIndex) .collect(Collectors.toList()); rowsWithASelection.forEach(rowIndex -> onSelectCell(rowIndex, index)); }
private int findMinRowIndex(final int rowIndex, final int columnIndex, final int minRowIndex, final GridCell<?> currentRowCell) { int minBlockRowIndex = rowIndex; if (currentRowCell != null) { boolean foundTopSplitMarker = currentRowCell.getMergedCellCount() > 0; while (minBlockRowIndex > minRowIndex) { final GridRow previousRow = gridData.getRow(minBlockRowIndex - 1); final GridCell<?> previousRowCell = previousRow.getCells().get(columnIndex); if (previousRowCell == null) { break; } if (previousRowCell.isCollapsed() && foundTopSplitMarker) { break; } if (!previousRowCell.equals(currentRowCell)) { break; } if (previousRowCell.getMergedCellCount() > 0) { foundTopSplitMarker = true; } minBlockRowIndex--; } } return minBlockRowIndex; }
assertEquals("Cell[" + columnIndex + ", " + rowIndex + "] actual isMerged() differs to expected.", expectedCellStates[rowIndex][columnIndex].isMerged, cell.isMerged()); assertEquals("Cell[" + columnIndex + ", " + rowIndex + "] actual getMergedCellCount() differs to expected.", expectedCellStates[rowIndex][columnIndex].mergedCellCount, cell.getMergedCellCount()); assertEquals("Cell[" + columnIndex + ", " + rowIndex + "] actual getValue() differs to expected.", expectedCellStates[rowIndex][columnIndex].value, cell.getValue().getValue());
private void initialiseRowData(final int rowIndex) { final List<BaseColumn> modelColumns = model.getExpandedColumns(); final List<DTCellValue52> modelRow = model.getData().get(rowIndex); for (int columnIndex = 0; columnIndex < modelColumns.size(); columnIndex++) { final BaseColumn modelColumn = modelColumns.get(columnIndex); final DTCellValue52 modelCell = makeModelCellValue(modelColumn); modelRow.add(modelCell); //BaseGridData is sparsely populated; only add values if needed. if (modelCell.hasValue()) { uiModel.setCellValueInternal(rowIndex, columnIndex, gridWidgetCellFactory.convertCell(modelCell, modelColumn, cellUtilities, columnUtilities)); } uiModel.indexColumn(columnIndex); //Set-up SelectionManager for Row Number column, to select entire row. if (modelColumn instanceof RowNumberCol52) { uiModel.getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE); } } }
protected static double getCellHeight(final int rowIndex, final GridData model, final GridCell<?> cell) { return IntStream.range(rowIndex, rowIndex + cell.getMergedCellCount()) .mapToDouble(index -> model.getRow(index).getHeight()) .sum(); }
/** * Checks if a {@link AbstractNodeMouseEvent} happened within a {@link GridCell}. If the * {@link AbstractNodeMouseEvent} is found to have happened within a cell, the {@link GridCell#getSupportedEditAction()} * is checked to {@link Object#equals(Object)} that for the {@link AbstractNodeMouseEvent}. If they equal then the * {@link GridCell} is put into "edit" mode via {@link GridWidget#startEditingCell(Point2D)}. */ @Override public boolean handleBodyCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiRowIndex, final int uiColumnIndex, final AbstractNodeMouseEvent event) { final GridData gridData = gridWidget.getModel(); if (gridData.getSelectedCells().size() == 1) { final GridCell<?> cell = gridData.getCell(uiRowIndex, uiColumnIndex); final GridCellEditAction cellEditAction = cell == null ? GridCell.DEFAULT_EDIT_ACTION : cell.getSupportedEditAction(); if (Objects.equals(cellEditAction, GridCellEditAction.getSupportedEditAction(event))) { return gridWidget.startEditingCell(relativeLocation); } } return false; } }
@Test public void testInitialSetup_NoMerging() { final GridData data = new BaseGridData(); final GridColumn<String> gc1 = new MockMergableGridColumn<String>("col1", 100); final GridColumn<String> gc2 = new MockMergableGridColumn<String>("col2", 100); data.appendColumn(gc1); data.appendColumn(gc2); data.appendRow(new BaseGridRow()); data.appendRow(new BaseGridRow()); data.appendRow(new BaseGridRow()); for (int rowIndex = 0; rowIndex < data.getRowCount(); rowIndex++) { for (int columnIndex = 0; columnIndex < data.getColumnCount(); columnIndex++) { data.setCellValue(rowIndex, columnIndex, new BaseGridCellValue<String>("(" + columnIndex + ", " + rowIndex + ")")); } } for (int rowIndex = 0; rowIndex < data.getRowCount(); rowIndex++) { assertFalse(data.getRow(rowIndex).isMerged()); for (int columnIndex = 0; columnIndex < data.getColumnCount(); columnIndex++) { final GridCell<?> cell = data.getCell(rowIndex, columnIndex); assertFalse(cell.isMerged()); assertEquals(1, cell.getMergedCellCount()); } } }
private void updateRowMergedCells(final GridRow row) { for (GridCell<?> cell : row.getCells().values()) { if (cell.isMerged()) { ((BaseGridRow) row).setHasMergedCells(true); return; } } ((BaseGridRow) row).setHasMergedCells(false); } }
assertEquals("Cell[" + columnIndex + ", " + rowIndex + "] actual isMerged() differs to expected.", expectedCellStates[rowIndex][columnIndex].isMerged, cell.isMerged()); assertEquals("Cell[" + columnIndex + ", " + rowIndex + "] actual getMergedCellCount() differs to expected.", expectedCellStates[rowIndex][columnIndex].mergedCellCount, cell.getMergedCellCount()); assertEquals("Cell[" + columnIndex + ", " + rowIndex + "] actual getValue() differs to expected.", expectedCellStates[rowIndex][columnIndex].value, cell.getValue().getValue());
private void initialiseRowData(final int rowIndex) { final List<BaseColumn> modelColumns = model.getExpandedColumns(); final List<DTCellValue52> modelRow = model.getData().get(rowIndex); for (int columnIndex = 0; columnIndex < modelColumns.size(); columnIndex++) { final BaseColumn modelColumn = modelColumns.get(columnIndex); final DTCellValue52 modelCell = makeModelCellValue(modelColumn); modelRow.add(modelCell); //BaseGridData is sparsely populated; only add values if needed. if (modelCell.hasValue()) { uiModel.setCellValueInternal(rowIndex, columnIndex, gridWidgetCellFactory.convertCell(modelCell, modelColumn, cellUtilities, columnUtilities)); } uiModel.indexColumn(columnIndex); //Set-up SelectionManager for Row Number column, to select entire row. if (modelColumn instanceof RowNumberCol52) { uiModel.getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE); } } }
protected static double getCellHeight(final int rowIndex, final GridData model, final GridCell<?> cell) { return IntStream.range(rowIndex, rowIndex + cell.getMergedCellCount()) .mapToDouble(index -> model.getRow(index).getHeight()) .sum(); }
/** * Checks if a {@link AbstractNodeMouseEvent} happened within a {@link GridCell}. If the * {@link AbstractNodeMouseEvent} is found to have happened within a cell, the {@link GridCell#getSupportedEditAction()} * is checked to {@link Object#equals(Object)} that for the {@link AbstractNodeMouseEvent}. If they equal then the * {@link GridCell} is put into "edit" mode via {@link GridWidget#startEditingCell(Point2D)}. */ @Override public boolean handleBodyCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiRowIndex, final int uiColumnIndex, final AbstractNodeMouseEvent event) { final GridData gridData = gridWidget.getModel(); if (gridData.getSelectedCells().size() == 1) { final GridCell<?> cell = gridData.getCell(uiRowIndex, uiColumnIndex); final GridCellEditAction cellEditAction = cell == null ? GridCell.DEFAULT_EDIT_ACTION : cell.getSupportedEditAction(); if (Objects.equals(cellEditAction, GridCellEditAction.getSupportedEditAction(event))) { return gridWidget.startEditingCell(relativeLocation); } } return false; } }
@Test public void testInitialSetup_NoMerging() { final GridData data = new BaseGridData(); final GridColumn<String> gc1 = new MockMergableGridColumn<String>("col1", 100); final GridColumn<String> gc2 = new MockMergableGridColumn<String>("col2", 100); data.appendColumn(gc1); data.appendColumn(gc2); data.appendRow(new BaseGridRow()); data.appendRow(new BaseGridRow()); data.appendRow(new BaseGridRow()); for (int rowIndex = 0; rowIndex < data.getRowCount(); rowIndex++) { for (int columnIndex = 0; columnIndex < data.getColumnCount(); columnIndex++) { data.setCellValue(rowIndex, columnIndex, new BaseGridCellValue<String>("(" + columnIndex + ", " + rowIndex + ")")); } } for (int rowIndex = 0; rowIndex < data.getRowCount(); rowIndex++) { assertFalse(data.getRow(rowIndex).isMerged()); for (int columnIndex = 0; columnIndex < data.getColumnCount(); columnIndex++) { final GridCell<?> cell = data.getCell(rowIndex, columnIndex); assertFalse(cell.isMerged()); assertEquals(1, cell.getMergedCellCount()); } } }
private void updateRowMergedCells(final GridRow row) { for (GridCell<?> cell : row.getCells().values()) { if (cell.isMerged()) { ((BaseGridRow) row).setHasMergedCells(true); return; } } ((BaseGridRow) row).setHasMergedCells(false); } }
private int findMinRowIndex(final int rowIndex, final int columnIndex, final int minRowIndex, final GridCell<?> currentRowCell) { int minBlockRowIndex = rowIndex; if (currentRowCell != null) { boolean foundTopSplitMarker = currentRowCell.getMergedCellCount() > 0; while (minBlockRowIndex > minRowIndex) { final GridRow previousRow = gridData.getRow(minBlockRowIndex - 1); final GridCell<?> previousRowCell = previousRow.getCells().get(columnIndex); if (previousRowCell == null) { break; } if (previousRowCell.isCollapsed() && foundTopSplitMarker) { break; } if (!previousRowCell.equals(currentRowCell)) { break; } if (previousRowCell.getMergedCellCount() > 0) { foundTopSplitMarker = true; } minBlockRowIndex--; } } return minBlockRowIndex; }
listSelector)); uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE); break; case INFORMATION_ITEM:
public void onInsertColumn(final int index) { final List<GridData.SelectedCell> selectedCells = gridData.getSelectedCells(); final List<Integer> rowsWithASelection = selectedCells.stream() .filter(sc -> { final int ri = sc.getRowIndex(); final int ci = sc.getColumnIndex(); final int _ci = ColumnIndexUtilities.findUiColumnIndex(gridData.getColumns(), ci); final GridCell<?> cell = gridData.getCell(ri, _ci); return cell != null && cell.getSelectionStrategy() instanceof RowSelectionStrategy; }) .map(GridData.SelectedCell::getRowIndex) .collect(Collectors.toList()); rowsWithASelection.forEach(rowIndex -> onSelectCell(rowIndex, index)); }
private double getClippedMergedCellHeight(final int uiRowIndex, final int uiColumnIndex) { final GridCell<?> cell = gridModel.getCell(uiRowIndex, uiColumnIndex); GridCell<?> _cell = cell; int _uiRowIndex = uiRowIndex; while (_cell.getMergedCellCount() == 0) { _uiRowIndex--; _cell = gridModel.getCell(_uiRowIndex, uiColumnIndex); } double height = 0; for (int i = _uiRowIndex; i < _uiRowIndex + _cell.getMergedCellCount(); i++) { height = height + gridModel.getRow(i).getHeight(); } return height; }