public static IUndoableGridTableAction insertColumns(int nCols, int beforeColumns, IGridRegion region, IGrid grid, MetaInfoWriter metaInfoWriter) { int h = IGridRegion.Tool.height(region); int w = IGridRegion.Tool.width(region); int columnsToMove = w - beforeColumns; ArrayList<IUndoableGridTableAction> actions = new ArrayList<>(h * columnsToMove); int firstToMove = region.getLeft() + beforeColumns; int colTo = firstToMove + nCols; int top = region.getTop(); // shift cells by column, copy cells of inserted column and resize merged regions after actions.addAll(shiftColumns(colTo, nCols, INSERT, region, grid, metaInfoWriter)); actions.addAll(copyCells(firstToMove, top, colTo, top, nCols, h, grid, metaInfoWriter)); actions.addAll(resizeMergedRegions(grid, beforeColumns, nCols, INSERT, COLUMNS, region, metaInfoWriter)); actions.addAll(emptyCells(firstToMove, top, nCols, h, grid, metaInfoWriter)); return new UndoableCompositeAction(actions); }
public static IUndoableGridTableAction removeColumns(int nCols, int startColumn, IGridRegion region, IGrid grid, MetaInfoWriter metaInfoWriter) { int firstToMove = region.getLeft() + startColumn + nCols; int w = IGridRegion.Tool.width(region); int h = IGridRegion.Tool.height(region); ArrayList<IUndoableGridTableAction> actions = new ArrayList<>(h * (w - startColumn)); // resize merged regions -> shift cells by column -> clear cells actions.addAll(resizeMergedRegions(grid, startColumn, nCols, REMOVE, COLUMNS, region, metaInfoWriter)); actions.addAll(shiftColumns(firstToMove, nCols, REMOVE, region, grid, metaInfoWriter)); actions.addAll(clearCells(region.getRight() + 1 - nCols, nCols, region.getTop(), h, grid, metaInfoWriter)); return new UndoableCompositeAction(actions); }
public static IUndoableGridTableAction removeRows(int nRows, int startRow, IGridRegion region, IGrid grid, MetaInfoWriter metaInfoWriter) { int w = IGridRegion.Tool.width(region); int h = IGridRegion.Tool.height(region); int firstToMove = region.getTop() + startRow + nRows; ArrayList<IUndoableGridTableAction> actions = new ArrayList<>(w * (h - startRow)); // resize merged regions -> shift cells by row -> clear cells actions.addAll(resizeMergedRegions(grid, startRow, nRows, REMOVE, ROWS, region, metaInfoWriter)); actions.addAll(shiftRows(firstToMove, nRows, REMOVE, region, grid, metaInfoWriter)); actions.addAll(clearCells(region.getLeft(), w, region.getBottom() + 1 - nRows, nRows, grid, metaInfoWriter)); return new UndoableCompositeAction(actions); } }
public UndoableResizeMergedRegionAction(IGridRegion initialRegion, int numberOfRowsOrColumns, boolean isInsert, boolean isColumns) { this.initialRegion = initialRegion; int increase = isInsert ? numberOfRowsOrColumns : -numberOfRowsOrColumns; try { if (isColumns) { newRegion = new GridRegion(initialRegion.getTop(), initialRegion.getLeft(), initialRegion.getBottom(), initialRegion.getRight() + increase); } else { newRegion = new GridRegion(initialRegion.getTop(), initialRegion.getLeft(), initialRegion.getBottom() + increase, initialRegion.getRight()); } } catch (IllegalArgumentException e) { // Wrong region created newRegion = null; } if(IGridRegion.Tool.width(newRegion) == 1 && IGridRegion.Tool.height(newRegion) == 1){ newRegion = null; } }
/** * Checks if the specified region must be resized. * * If we delete all we remove all rows/columns in region then region * must be deleted(not resized). */ private static boolean isRegionMustBeResized(IGridRegion region, int firstRowOrColumn, int numberOfRowsOrColumns, boolean isColumns, IGridRegion regionOfTable) { if (isColumns) { // merged region contains column which we copy/remove return IGridRegion.Tool.width(region) > numberOfRowsOrColumns && IGridRegion.Tool.contains(region, regionOfTable.getLeft() + firstRowOrColumn, region .getTop()); } else { // merged region contains row which we copy/remove return IGridRegion.Tool.height(region) > numberOfRowsOrColumns && IGridRegion.Tool.contains(region, region.getLeft(), regionOfTable.getTop() + firstRowOrColumn); } }
private static int getPropertyRowIndex(IGridRegion tableRegion, IGrid grid, String newPropName) { int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int firstPropertyRow = IGridRegion.Tool.height(grid.getCell(leftCell, topCell).getAbsoluteRegion()); String propsHeader = grid.getCell(leftCell, topCell + firstPropertyRow).getStringValue(); if (tableWithoutPropertySection(propsHeader)) { return -1; } int propsCount = grid.getCell(leftCell, topCell + 1).getHeight(); int propNameCellOffset = grid.getCell(leftCell, topCell + 1).getWidth(); for (int i = 0; i < propsCount; i++) { String propNameFromTable = grid.getCell(leftCell + propNameCellOffset, topCell + 1 + i) .getStringValue(); if (propNameFromTable != null && propNameFromTable.equals(newPropName)) { return topCell + 1 + i; } } return -1; }
private static IUndoableGridTableAction resizePropertiesHeader(IGridRegion tableRegion, IGrid grid, MetaInfoWriter metaInfoWriter) { int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int firstPropertyRow = IGridRegion.Tool.height(grid.getCell(leftCell, topCell).getAbsoluteRegion()); int propsCount = grid.getCell(leftCell, topCell + firstPropertyRow).getHeight(); if (propsCount == 1) { IGridRegion propHeaderRegion = grid.getRegionContaining(leftCell, topCell + firstPropertyRow); if (propHeaderRegion == null) { propHeaderRegion = new GridRegion(topCell + firstPropertyRow, leftCell, topCell + firstPropertyRow, leftCell); } return new UndoableResizeMergedRegionAction(propHeaderRegion, 1, INSERT, ROWS); } else { return new UndoableCompositeAction(resizeMergedRegions(grid, firstPropertyRow, 1, INSERT, ROWS, tableRegion, metaInfoWriter)); } }
/** * Initialize width and height of current grid. According to the compose * direction. * */ private void initWidthAndHeight() { for (int i = 0; i < gridTables.length; i++) { IGridRegion reg = gridTables[i].getRegion(); if (vertical) { height += IGridRegion.Tool.height(reg); width = Math.max(width, IGridRegion.Tool.width(reg)); } else { width += IGridRegion.Tool.width(reg); height = Math.max(height, IGridRegion.Tool.height(reg)); } } }
public synchronized void moveTableTo(IGridTable table, IGridRegion destRegion) throws TableServiceException { if (Tool.height(destRegion) != table.getHeight() || Tool.width(destRegion) != table.getWidth()) { throw new TableServiceException("Bad destination region size."); } try { TableBuilder tableBuilder = new TableBuilder((XlsSheetGridModel) table.getGrid(), metaInfoWriter); tableBuilder.beginTable(destRegion); tableBuilder.writeGridTable(table); tableBuilder.endTable(); } catch (Exception e) { throw new TableServiceException("Could not move the table", e); } removeTable(table); } }
@Override protected boolean canPerformAction(IGridRegion gridRegion) { return !(startRow < 0 || startRow >= IGridRegion.Tool.height(gridRegion)); }
/** * Returns max number of rows to display. * * @return number of rows to display or -1 for all rows */ public static int getMaxNumRowsToDisplay(IGridTable table) { IGridRegion region = table.getRegion(); int cols = IGridRegion.Tool.width(region); int rows = IGridRegion.Tool.height(region); return getMaxNumRowsToDisplay(rows, cols); }
public StyleIndexHandler(IGridRegion tableRegion, int sheetIndex) { this.tableRegion = tableRegion; cellIndexes = new int[IGridRegion.Tool.height(tableRegion)][IGridRegion.Tool.width(tableRegion)]; this.sheetIndex = sheetIndex; formulaParsingWorkbook = new SAXFormulaParsingWorkbook(); }
void setGrid(TableModel tm) { int width = IGridRegion.Tool.width(reg); for (int i = 0; i <= width; i++) { setVerticalBorder(i, tm); } int height = IGridRegion.Tool.height(reg); for (int i = 0; i <= height; i++) { setHorizontalBorder(i, tm); } }
void setGrid(TableModel tm) { int width = IGridRegion.Tool.width(reg); for (int i = 0; i <= width; i++) { setVerticalBorder(i, tm); } int height = IGridRegion.Tool.height(reg); for (int i = 0; i <= height; i++) { setHorizontalBorder(i, tm); } }
public TableStyleListener(EventSheetDescriptor sheet, IGridRegion tableRegion) { this.sheet = sheet; this.tableRegion = tableRegion; cellIndexes = new int[IGridRegion.Tool.height(tableRegion)][IGridRegion.Tool.width(tableRegion)]; }
/** * Returns max number of rows to display. * * @return number of rows to display or -1 for all rows */ public static int getMaxNumRowsToDisplay(IGridTable table) { IGridRegion region = table.getRegion(); int cols = IGridRegion.Tool.width(region); int rows = IGridRegion.Tool.height(region); return getMaxNumRowsToDisplay(rows, cols); }
int getRowSpan(ICell cell) { IGridRegion gr = cell.getRegion(); if (gr == null) { return 1; } return IGridRegion.Tool.height(IGridRegion.Tool.intersect(reg, gr)); }
int getRowSpan(ICell cell) { IGridRegion gr = cell.getRegion(); if (gr == null) { return 1; } return IGridRegion.Tool.height(IGridRegion.Tool.intersect(reg, gr)); }