@Override public void endElement(String uri, String localName, String qName) { if ("f".equals(localName)) { readFormula = false; if (sharedFormulaIndex != null && sharedFormulaRef != null) { sharedFormulas.put(sharedFormulaIndex, new SharedFormulaDefinition(formula.toString(), sharedFormulaRef)); } if (IGridRegion.Tool.contains(tableRegion, current.getColumn(), current.getRow())) { try { String value = formula.toString(); if (sharedFormulaIndex != null && sharedFormulaRef == null) { value = convertSharedFormula(sharedFormulas.get(sharedFormulaIndex)); } formulas.put(current, value); } catch (Exception e) { log.error(e.getMessage(), e); } } formula.setLength(0); } }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { if ("c".equals(localName)) { String cellRef = attributes.getValue("r"); current = new CellAddress(cellRef); if (IGridRegion.Tool.contains(tableRegion, current.getColumn(), current.getRow())) { String cellStyleStr = attributes.getValue("s"); int styleIndex = cellStyleStr != null ? Integer.parseInt(cellStyleStr) : 0; int internalRow = current.getRow() - tableRegion.getTop(); int internalCol = current.getColumn() - tableRegion.getLeft(); cellIndexes[internalRow][internalCol] = styleIndex; } } else if ("f".equals(localName)) { sharedFormulaIndex = attributes.getValue("si"); sharedFormulaRef = attributes.getValue("ref"); if (IGridRegion.Tool.contains(tableRegion, current.getColumn(), current.getRow()) || sharedFormulaIndex != null && sharedFormulaRef != null) { readFormula = true; } } }
private void saveSimpleRulesMetaInfo(DecisionTable decisionTable, IGridRegion region) { for (Map.Entry<CellKey, Pair<String, IOpenClass>> entry : simpleRulesConditionMap.entrySet()) { String conditionStatement = entry.getValue().getLeft(); IOpenClass conditionType = entry.getValue().getRight(); CellKey key = entry.getKey(); int row = key.getRow(); int col = key.getColumn(); if (!IGridRegion.Tool.contains(region, col, row)) { continue; } // SimpleRules or SimpleLookup IGrid grid = getTableSyntaxNode().getGridTable().getGrid(); String cellValue = grid.getCell(col, row).getStringValue(); if (StringUtils.isBlank(cellValue)) { continue; } String text = String.format("Condition for %s: %s", conditionStatement, conditionType.getDisplayName(0)); SimpleNodeUsage simpleNodeUsage = new SimpleNodeUsage(0, cellValue.length() - 1, text, null, NodeType.OTHER); setPreparedMetaInfo(row, col, new CellMetaInfo(JavaOpenClass.STRING, false, Collections.singletonList(simpleNodeUsage))); } }
IGridRegion existingMergedRegion = grid.getMergedRegion(i); if (IGridRegion.Tool.contains(regionOfTable, existingMergedRegion.getLeft(), existingMergedRegion .getTop())) { if (isRegionMustBeResized(existingMergedRegion, firstRowOrColumn, numberOfRowsOrColumns, isColumns,
int col = cell.getAbsoluteColumn(); if (!IGridRegion.Tool.contains(region, col, row)) { continue;
private void saveDescriptionMetaInfo(FunctionalRow funcRow, IGridRegion region) { // Condition/Action code (expression) ICell codeCell = funcRow.getCodeTable().getCell(0, 0); int row = codeCell.getAbsoluteRow(); int col = codeCell.getAbsoluteColumn(); if (IGridRegion.Tool.contains(region, col, row)) { List<CellMetaInfo> metaInfoList = OpenLCellExpressionsCompiler.getMetaInfo( funcRow.getSourceCodeModule(), funcRow.getMethod() ); // Decision table always contains 1 meta info setPreparedMetaInfo(row, col, metaInfoList.get(0)); } // Condition/Action type definition ILogicalTable paramsTable = funcRow.getParamsTable(); // In the case of errors params will be null IParameterDeclaration[] params = funcRow.getParams(); if (params != null && params.length > 0 && params[0] != null) { IParameterDeclaration param = params[0]; ICell paramCell = paramsTable.getCell(0, 0); row = paramCell.getAbsoluteRow(); col = paramCell.getAbsoluteColumn(); if (IGridRegion.Tool.contains(region, col, row)) { setPreparedMetaInfo(row, col, getMetaInfo(paramsTable, param.getType())); } } }
private TableStyles readTableStyles(int row, int column) { if (workbookPath == null) { // No need to show styles in read only mode (when access workbook through stream) return null; } TableStyles styles = null; for (IGridTable table : tables) { IGridRegion region = table.getRegion(); // Sometimes we need extra column and row to show the border of a table. // We need to know the styles of the cells lefter, above, righter and below the table. int left = region.getLeft() == 0 ? 0 : region.getLeft() - 1; int top = region.getTop() == 0 ? 0 : region.getTop() - 1; IGridRegion extendedRegion = new GridRegion(top, left, region.getBottom() + 1, region.getRight() + 1); if (IGridRegion.Tool.contains(extendedRegion, column, row)) { try (ExcelReader excelReader = ExcelReaderFactory.sequentialFactory().create(workbookPath)) { styles = excelReader.getTableStyles(sheetDescriptor, extendedRegion); } catch (Exception e) { // Fallback to empty style log.error("Can't read styles for sheet '{}'", sheetDescriptor.getName(), e); styles = new EmptyTableStyles(extendedRegion); } break; } } return styles; }
private void saveCompoundReturnColumn(IGridRegion region) { for (Map.Entry<CellKey, String> entry : simpleRulesReturnDescriptions.entrySet()) { CellKey key = entry.getKey(); int row = key.getRow(); int col = key.getColumn(); if (!IGridRegion.Tool.contains(region, col, row)) { continue; } ICell cell = getTableSyntaxNode().getGridTable().getGrid().getCell(col, row); String stringValue = cell.getStringValue(); if (StringUtils.isBlank(stringValue)) { continue; } SimpleNodeUsage simpleNodeUsage = new SimpleNodeUsage(0, stringValue.length() - 1, entry.getValue(), null, NodeType.OTHER); CellMetaInfo metaInfo = new CellMetaInfo(JavaOpenClass.STRING, false, Collections.singletonList(simpleNodeUsage)); setPreparedMetaInfo(row, col, metaInfo); } }
/** * Transformes current grid coordinates to appropriate table coordinates. * * @param col grid column index * @param row grid row index * @return {@link Transform} that contains coordinates to cell in the * appropriate grid. */ private Transform transform(int col, int row) { for (int i = 0; i < mappedRegions.length; i++) { // find the region to which this coordinates belong to if (IGridRegion.Tool.contains(mappedRegions[i], col, row)) { // according to the found region, get the appropriate table // region. IGridRegion reg = gridTables[i].getRegion(); // transform grid coordinates to table grid one. int transformedCol = reg.getLeft() + col - mappedRegions[i].getLeft(); int transformedRow = reg.getTop() + row - mappedRegions[i].getTop(); // return the transformer, with coordinates to source cell. return new Transform(gridTables[i].getGrid(), transformedCol, transformedRow); } } return null; }
@Override public final CellMetaInfo getMetaInfo(int row, int col) { try { if (!IGridRegion.Tool.contains(getTableSyntaxNode().getGridTable().getRegion(), col, row)) { return null; } NodeUsage nodeUsage = constantsMap.get(CellKey.CellKeyFactory.getCellKey(col, row)); if (nodeUsage != null) { return new CellMetaInfo(JavaOpenClass.STRING, false, Collections.singletonList(nodeUsage)); } if (isHeaderRow(row)) { // Header can be merged with several cells. First cell can contain meta info, others can't. return isHeaderCell(row, col) ? getHeaderMetaInfo() : null; } if (isProperties(row, col)) { return getPropertiesMetaInfo(row, col); } return getBodyMetaInfo(row, col); } catch (Exception e) { log.error(e.getMessage(), e); return 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); } }
public void doAction(IGridTable table) { IWritableGrid grid = (IWritableGrid) table.getGrid(); removedRegions = new ArrayList<IGridRegion>(); int nregions = grid.getNumberOfMergedRegions(); for (int i = 0; i < nregions; i++) { IGridRegion reg = grid.getMergedRegion(i); if (IGridRegion.Tool.contains(region, reg.getLeft(), reg.getTop())) { removedRegions.add(reg); } } for(IGridRegion regionToRemove :removedRegions){ grid.removeMergedRegion(regionToRemove); } grid.addMergedRegion(region); }
protected TableStyles getTableStyles(int row, int column) { int internalRow = row - getFirstRowNum(); int internalCol = column - getFirstColNum(); if (internalRow >= 0 && internalCol >= 0 && cells.length > internalRow && cells[internalRow].length > internalCol) { CellRowCol topLeft = findTopLeft(internalRow, internalCol); row -= internalRow - topLeft.row; column -= internalCol - topLeft.col; } if (currentTableStyles == null || !IGridRegion.Tool.contains(currentTableStyles.getRegion(), column, row)) { currentTableStyles = readTableStyles(row, column); } return currentTableStyles; }
public boolean isInOneMergedRegion(int firstCellColumn, int firstCellRow, int secondCellColumn, int secondCellRow) { IGridRegion region = getRegionContaining(firstCellColumn, firstCellRow); if (region != null && org.openl.rules.table.IGridRegion.Tool.contains(region, secondCellColumn, secondCellRow)) { return true; } return false; } }
public IGridRegion getRegionContaining(int col, int row) { int nregions = getNumberOfMergedRegions(); for (int i = 0; i < nregions; i++) { IGridRegion reg = getMergedRegion(i); if (IGridRegion.Tool.contains(reg, col, row)) { return reg; } } return null; }
private boolean contains(int col, int row) { for (int i = 0; i < regions.length; i++) { if (IGridRegion.Tool.contains(regions[i], col, row)) { return true; } } return false; }