@Override public int getWidth() { return delegate.getWidth(); }
public int getWidth() { return delegate.getWidth(); }
/** * Get the column of a field in Spreadsheet. * * @return column number */ private static int getColumn(IGridTable spreadsheet, int columnFieldNumber) { int column = 0; // The column 0 contains row headers that's why "<=" instead of "<" for (int i = 0; i <= columnFieldNumber; i++) { column += spreadsheet.getCell(i, 0).getWidth(); } return column; }
public static int[] calculateColumnOffsets(int width, IGridTable gt) { int[] columnOffset = new int[width + 1]; int offset = 0; for (int i = 0, cellWidth = 0; i < width; offset += cellWidth, ++i) { columnOffset[i] = offset; cellWidth = gt.getCell(offset, 0).getWidth(); } columnOffset[width] = offset; //last+1 column offset is needed to determine last column's width return columnOffset; }
@Override protected int getNumberToRemove(IGridTable table) { int cellWidth = getOriginalTable(table).getCell(startCol, row).getWidth(); int numberToInsert = nCols; if (cellWidth > 1) { // merged cell numberToInsert += cellWidth - 1; } return numberToInsert; }
public int getWidth() { if (region == null){ return delegate.getWidth(); } return region.getRight() - region.getLeft() + 1; }
@Override protected int getNumberToInsert(IGridTable table) { int cellWidth = getOriginalTable(table).getCell(beforeCol, row).getWidth(); int colToInsert = nCols; if (cellWidth > 1) { // merged cell colToInsert += cellWidth - 1; } return colToInsert; }
public int getHeight() { return table.isNormalOrientation() ? cell.getHeight() : cell.getWidth(); }
public int getWidth() { return table.isNormalOrientation() ? cell.getWidth() : cell.getHeight(); }
/** * Gets the number of logical columns in the first table row.<br> * Each not merged cell is one logical column, several merged horizontal cells are one logical column too. * * @param table Original source grid table. * @return number of logical columns in the first table row. */ public static int calcLogicalColumns(IGridTable table) { int W = table.getWidth(); if (W == 1) return 1; int columns = 0; int cellWidth; for (int w = 0; w < W; w += cellWidth, columns++) { cellWidth = table.getCell(w, 0).getWidth(); } return columns; }
private static int calculateCompoundReturnColumnsCount(ILogicalTable originalTable, int numberOfConditions, int numberOfMergedRows) { IGridTable gt = originalTable.getSource().getRow(numberOfMergedRows); int w = gt.getWidth(); int w0 = 0; int i = 0; while (i < w) { i = i + gt.getCell(i, 0).getWidth(); w0++; } return w0 - numberOfConditions; }
private static IUndoableGridTableAction setExistingPropertyValue(IGridRegion tableRegion, IGrid grid, Object newPropValue, int propertyRowIndex, MetaInfoWriter metaInfoWriter) { int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int propNameCellOffset = grid.getCell(leftCell, topCell + 1).getWidth(); int propValueCellOffset = propNameCellOffset + grid.getCell(leftCell + propNameCellOffset, topCell + 1).getWidth(); Object propValueFromTable = grid.getCell(leftCell + propValueCellOffset, propertyRowIndex) .getObjectValue(); if (propValueFromTable != null && propValueFromTable.equals(newPropValue)) { // Property with such name and value already exists return null; } return new UndoableSetValueAction(leftCell + propValueCellOffset, propertyRowIndex, newPropValue, metaInfoWriter); }
private static List<IUndoableGridTableAction> emptyCells(int colFrom, int rowFrom, int nCols, int nRows, IGrid grid, MetaInfoWriter metaInfoWriter) { List<IUndoableGridTableAction> actions = new ArrayList<>(); for (int i = nCols - 1; i >= 0; i--) { for (int j = nRows - 1; j >= 0; j--) { int cFrom = colFrom + i; int rFrom = rowFrom + j; if (grid.isTopLeftCellInMergedRegion(cFrom, rFrom)) { ICell cell = grid.getCell(cFrom, rFrom); if (cell.getHeight() > nRows || cell.getWidth() > nCols) { // Don't clear merged cells which are bigger than the cleaned region. continue; } } else if (grid.isPartOfTheMergedRegion(cFrom, rFrom)) { // Don't clear middle of the merged cells. continue; } actions.add(new UndoableSetValueAction(cFrom, rFrom, null, metaInfoWriter)); } } return actions; }
/** * Checks if the table specified by its region contains property. */ private CellKey getPropertyCoordinates(IGridRegion region, IGrid grid, String propName) { int left = region.getLeft(); int top = region.getTop(); ICell propsHeaderCell = grid.getCell(left, top + 1); String propsHeader = propsHeaderCell.getStringValue(); if (propsHeader == null || !propsHeader.equals(PropertiesHelper.PROPERTIES_HEADER)) { // There is no properties return null; } int propsCount = propsHeaderCell.getHeight(); for (int i = 0; i < propsCount; i++) { ICell propNameCell = grid.getCell(left + propsHeaderCell.getWidth(), top + 1 + i); String pName = propNameCell.getStringValue(); if (pName != null && pName.equals(propName)) { return CellKey.CellKeyFactory.getCellKey(1, 1 + i); } } return null; }
/** * Checks if the table specified by its region contains property. */ private CellKey getPropertyCoordinates(IGridRegion region, IGrid grid, String propName) { int left = region.getLeft(); int top = region.getTop(); ICell propsHeaderCell = grid.getCell(left, top + 1); String propsHeader = propsHeaderCell.getStringValue(); if (propsHeader == null || !propsHeader.equals(PropertiesHelper.PROPERTIES_HEADER)) { // There is no properties return null; } int propsCount = propsHeaderCell.getHeight(); for (int i = 0; i < propsCount; i++) { ICell propNameCell = grid.getCell(left + propsHeaderCell.getWidth(), top + 1 + i); String pName = propNameCell.getStringValue(); if (pName != null && pName.equals(propName)) { return CellKey.CellKeyFactory.getCellKey(1, 1 + i); } } return null; }
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 void loadHorizConditionsAndReturnColumns(ILogicalTable rowHeader, int firstLookupColumn) throws OpenLCompilationException { int ncol = rowHeader.getWidth(); while (firstLookupColumn < ncol) { ILogicalTable htable = rowHeader.getColumn(firstLookupColumn); String headerStr = htable.getSource().getCell(0, 0).getStringValue(); if (headerStr != null) { headerStr = headerStr.toUpperCase(); if (DecisionTableHelper.isValidHConditionHeader(headerStr)) { loadHorizontalCondition(htable); } else if (DecisionTableHelper.isValidRetHeader(headerStr) || DecisionTableHelper.isValidCRetHeader(headerStr)) { loadReturnColumn(htable); } else { String message = String.format( "Lookup Table allows only %s or %s or %s columns after vertical conditions: %s", DecisionTableColumnHeaders.HORIZONTAL_CONDITION.getHeaderKey(), DecisionTableColumnHeaders.RETURN.getHeaderKey(), DecisionTableColumnHeaders.COLLECT_RETURN.getHeaderKey(), headerStr); throw new OpenLCompilationException(message); } } firstLookupColumn = firstLookupColumn + htable.getSource().getCell(0, 0).getWidth(); } }
public synchronized void removeTable(IGridTable table) throws TableServiceException { try { IGridRegion tableRegion = table.getRegion(); int left = tableRegion.getLeft(); int top = tableRegion.getTop(); int right = tableRegion.getRight(); int bottom = tableRegion.getBottom(); XlsSheetGridModel sheetModel = (XlsSheetGridModel) table.getGrid(); for (int row = top; row <= bottom; row++) { for (int col = left; col <= right; col++) { ICell cell = sheetModel.getCell(col, row); if (cell.getWidth() != 1 || cell.getHeight() != 1) { sheetModel.removeMergedRegion(col, row); } sheetModel.clearCell(col, row); } } } catch (Exception e) { throw new TableServiceException("Could not remove the table", e); } }
private CoordinatesTransformer getTransformer(ILogicalTable headerRow, ILogicalTable table, IGridTable lookupValuesTable, Integer lookupValuesTableHeight) throws OpenLCompilationException { int retColumnStart = findRetColumnStart(headerRow); int firstEmptyCell = findFirstEmptyCellInHeader(headerRow); int retTableWidth = retTable.getSource().getCell(0, 0).getWidth(); if (lookupValuesTableHeight == null) { lookupValuesTableHeight = lookupValuesTable.getHeight(); } scale = new DTScale(lookupValuesTableHeight, lookupValuesTable.getWidth() / retTableWidth); if (isRetLastColumn(retColumnStart, retTableWidth, firstEmptyCell)) { return new TwoDimensionDecisionTableTranformer(table.getSource(), lookupValuesTable, retTableWidth); } else { return new LookupHeadersTransformer(table .getSource(), lookupValuesTable, retTableWidth, retColumnStart, firstEmptyCell); } }
private static void writeMetaInfoForHConditions(ILogicalTable originalTable, DecisionTable decisionTable, Condition[] conditions, int numberOfHcondition, int numberOfConditions, int hColumn) { MetaInfoReader metaInfoReader = decisionTable.getSyntaxNode().getMetaInfoReader(); int j = 0; for (int i = numberOfConditions - numberOfHcondition; i < numberOfConditions; i++) { int c = hColumn; while (c <= originalTable.getSource().getWidth()) { ICell cell = originalTable.getSource().getCell(c, j); String cellValue = cell.getStringValue(); if (cellValue != null) { if (metaInfoReader instanceof DecisionTableMetaInfoReader) { ((DecisionTableMetaInfoReader) metaInfoReader).addSimpleRulesCondition(cell.getAbsoluteRow(), cell.getAbsoluteColumn(), decisionTable.getSignature().getParameterName(conditions[i].getParameterIndex()), decisionTable.getSignature().getParameterType(conditions[i].getParameterIndex())); } } c = c + cell.getWidth(); } j++; } }