private void proc(int rowIndex, ComponentOpenClass rowOpenClass, int columnIndex, SpreadsheetHeaderDefinition columnHeader) { if (columnHeader == null) { return; } SpreadsheetCell cell = cells[rowIndex][columnIndex]; for (SymbolicTypeDefinition typeDefinition : columnHeader.getVars()) { String fieldName = (DOLLAR_SIGN + typeDefinition.getName().getIdentifier()).intern(); SpreadsheetCellField field = createSpreadsheetCellField(rowOpenClass, cell, fieldName); rowOpenClass.addField(field); } }
public IOpenClass makeType(SpreadsheetCell cell) { if (cell.getType() == null) { int rowIndex = cell.getRowIndex(); int columnIndex = cell.getColumnIndex(); IBindingContext rowContext = getRowContext(rowIndex); if (processingCells.contains(cell)) { throw new OpenlNotCheckedException("Spreadsheet Expression Loop:" + processingCells.toString()); } processingCells.add(cell); extractCellValue(rowContext, rowIndex, columnIndex); extractedCellValues.add(cell); processingCells.remove(cell); if (cell.getType() == null) { cell.setType(JavaOpenClass.OBJECT); } } return cell.getType(); }
/** * Extract cell values from the source spreadsheet table. * * @return cells of spreadsheet with its values */ public SpreadsheetCell[][] getCells() { extractCellValues(); return cells.clone(); }
String code = StringUtils.trimToNull(source.getCode()); String name = getSpreadsheetCellFieldName(columnHeaders.get(columnIndex).getFirstname(), rowHeaders.get(rowIndex).getFirstname()); IOpenClass declaringClass = spreadsheetHeader.getDeclaringClass(); IOpenMethodHeader header = new OpenMethodHeader(name, type, signature, declaringClass); IBindingContext columnBindingContext = getColumnContext(columnIndex, rowIndex, rowBindingContext); OpenL openl = columnBindingContext.getOpenL(); addError(SyntaxNodeExceptionUtils .createError(message, e, LocationUtils.createTextInterval(source.getCode()), source)); } catch (Exception e) { String message = "Cannot parse cell!"; addError(SyntaxNodeExceptionUtils.createError(message, e, null, source)); if (instanceClass == null) { String message = String.format("Type '%s' was loaded with errors", type.getName()); addError(SyntaxNodeExceptionUtils.createError(message, source)); IBindingContext bindingContext = getColumnContext(columnIndex, rowIndex, rowBindingContext); ICell theCellValue = cell.getCell(0, 0); Object result = null; } catch (Exception t) { String message = String.format("Cannot parse cell value: [%s] to the necessary type", code); addError(SyntaxNodeExceptionUtils.createError(message, t, null, source));
/** * Add to {@link SpreadsheetOpenClass} fields that are represented by spreadsheet cells. * * @param spreadsheetType open class of the spreadsheet */ public void addCellFields(SpreadsheetOpenClass spreadsheetType, boolean autoType) { IBindingContext generalBindingContext = componentsBuilder.getBindingContext(); CellsHeaderExtractor cellsHeadersExtractor = componentsBuilder.getCellsHeadersExtractor(); int rowsCount = cellsHeadersExtractor.getHeight(); int columnsCount = cellsHeadersExtractor.getWidth(); // create cells according to the size of the spreadsheet cells = new SpreadsheetCell[rowsCount][columnsCount]; // create the binding context for the spreadsheet level spreadsheetBindingContext = new SpreadsheetContext(generalBindingContext, spreadsheetType); for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++) { for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++) { // build spreadsheet cell SpreadsheetCell spreadsheetCell = buildCell(rowIndex, columnIndex, autoType); // init cells array with appropriate cell cells[rowIndex][columnIndex] = spreadsheetCell; // create and add field of the cell to the spreadsheetType addSpreadsheetFields(spreadsheetType, spreadsheetCell, rowIndex, columnIndex); } } }
/** * Creates a field from the spreadsheet cell and add it to the spreadsheetType */ private void addSpreadsheetFields(SpreadsheetOpenClass spreadsheetType, SpreadsheetCell spreadsheetCell, int rowIndex, int columnIndex) { SpreadsheetHeaderDefinition columnHeaders = componentsBuilder.getColumnHeaders().get(columnIndex); SpreadsheetHeaderDefinition rowHeaders = componentsBuilder.getRowHeaders().get(rowIndex); if (columnHeaders == null || rowHeaders == null) { return; } for (SymbolicTypeDefinition columnDefinition : columnHeaders.getVars()) { for (SymbolicTypeDefinition rowDefinition : rowHeaders.getVars()) { // get column name from the column definition String columnName = columnDefinition.getName().getIdentifier(); // get row name from the row definition String rowName = rowDefinition.getName().getIdentifier(); // create name of the field String fieldname = getSpreadsheetCellFieldName(columnName, rowName); // create spreadsheet cell field SpreadsheetCellField field = createSpreadsheetCellField(spreadsheetType, spreadsheetCell, fieldname); // add spreadsheet cell field to its open class spreadsheetType.addField(field); } } }
public void preBind(IBindingContext bindingContext) throws SyntaxNodeException { if (!bindingContext.isExecutionMode()) { getTableSyntaxNode().setMetaInfoReader(new SpreadsheetMetaInfoReader(this)); } TableSyntaxNode tableSyntaxNode = getTableSyntaxNode(); validateTableBody(tableSyntaxNode, bindingContext); IOpenMethodHeader header = getHeader(); this.bindingContext = bindingContext; componentsBuilder = new SpreadsheetComponentsBuilder(tableSyntaxNode, bindingContext); componentsBuilder.buildHeaders(header.getType()); structureBuilder = new SpreadsheetStructureBuilder(componentsBuilder, header); String headerType = header.getName() + "Type"; OpenL openL = bindingContext.getOpenL(); spreadsheetOpenClass = new SpreadsheetOpenClass(headerType, openL); Boolean autoType = tableSyntaxNode.getTableProperties().getAutoType(); structureBuilder.addCellFields(spreadsheetOpenClass, autoType); }
public void finalizeBind(IBindingContext bindingContext) throws Exception { super.finalizeBind(bindingContext); ILogicalTable tableBody = getTableSyntaxNode().getTableBody(); getTableSyntaxNode().getSubTables().put(IXlsTableNames.VIEW_BUSINESS, tableBody); cells = structureBuilder.getCells(); Spreadsheet spreadsheet = (Spreadsheet) getMethod(); spreadsheet.setCells(cells); spreadsheet.setResultBuilder(componentsBuilder.buildResultBuilder(spreadsheet)); }
private void extractCellValues() { CellsHeaderExtractor cellsHeadersExtractor = componentsBuilder.getCellsHeadersExtractor(); int rowsCount = cellsHeadersExtractor.getHeight(); int columnsCount = cellsHeadersExtractor.getWidth(); for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++) { IBindingContext rowBindingContext = getRowContext(rowIndex); for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++) { boolean found = false; for (SpreadsheetCell cell : extractedCellValues) { int row = cell.getRowIndex(); int column = cell.getColumnIndex(); if (row == rowIndex && columnIndex == column) { found = true; } } if (!found) { extractCellValue(rowBindingContext, rowIndex, columnIndex); } } } }