public int getHeight() { return (rowNamesTable == null) ? 0 : rowNamesTable.getHeight(); }
public int getNumberOfRows() { return logicalTable.getHeight() - 1; }
/** * Gets the table body without header and properties section. * * @return table body, without header and properties section (if exists). */ public ILogicalTable getTableBody() { int startRow = !hasPropertiesDefinedInTable() ? 1 : 2; if (table.getHeight() <= startRow) { return null; } return table.getRows(startRow); }
public static int countTypes(ILogicalTable table, OpenL openl, IBindingContext cxt) { int height = table.getHeight(); int count = 1; // The first cell is always type name, there is no need to check it. Start from the second one. for (int i = 1; i < height; ++i) { try { IOpenClass type = makeType(table.getRow(i), openl, cxt); if (type != null) { count += 1; } } catch (Exception t) { // Ignore exception. } } return count; }
public void preLoad(OpenlToolAdaptor openlAdapter) throws Exception { int rows = logicalTable.getHeight(); int startRow = getStartRowForData(); dataArray = Array.newInstance(dataModel.getInstanceClass(), rows - startRow); for (int rowNum = startRow; rowNum < rows; rowNum++) { processRow(openlAdapter, startRow, rowNum); } }
/** * * @return table with 1 column, if necessary transposed, caller is * responsible to check that table is either 1xN or Nx1 */ public static ILogicalTable make1ColumnTable(ILogicalTable t) { if (t.getWidth() == 1) { return t; } if (t.getHeight() == 1) { return t.transpose(); } // caller is responsible to check that table is either 1xN or Nx1 return t; }
public static int calculateHeight(ILogicalTable table) { int height = table.getHeight(); int last = -1; for (int i = 0; i < height; i++) { String source = table.getRow(i).getSource().getCell(0, 0).getStringValue(); if (source != null && source.trim().length() != 0) { last = i; } } return last + 1; }
private static int[] getRowOffsets(ILogicalTable table) { if (table instanceof LogicalTable) { return ((LogicalTable)table).getRowOffset(); } return calculateRowOffsets(table.getHeight(), table.getSource()); }
public static ILogicalTable getPropertiesTableSection(ILogicalTable table) { if (table.getHeight() < 2) { return null; } ILogicalTable propTable = table.getRows(1, 1); String header = propTable.getSource().getCell(0, 0).getStringValue(); if (!PROPERTIES_HEADER.equals(header)) { return null; } return propTable.getColumns(1); }
private IOpenSourceCodeModule getSourceCodeModule(ILogicalTable bodyTable) { int height = bodyTable.getHeight(); IOpenSourceCodeModule[] cellSources = new IOpenSourceCodeModule[height]; for (int i = 0; i < height; i++) { cellSources[i] = new GridCellSourceCodeModule(bodyTable.getRow(i).getSource(), null); } return new CompositeSourceCodeModule(cellSources, "\n"); } }
private Integer getlookupValuesTableHeight(ILogicalTable originaltable, int firstLookupGridColumn, IGrid grid) { String stringValue = originaltable.getCell(0, 0).getStringValue(); if (stringValue == null) { stringValue = ""; } stringValue = stringValue.toUpperCase(); ILogicalTable valueTable = originaltable.getRows(DISPLAY_ROW + 1); if (DecisionTableHelper.isValidRuleHeader(stringValue) || DecisionTableHelper .isValidMergedConditionHeader(stringValue)) { return valueTable.getHeight(); } else { return null; } }
@Override public List<Object> getUniqueValues(int colIdx) throws SyntaxNodeException { List<Object> values = new ArrayList<>(); int rows = logicalTable.getHeight(); for (int i = 1; i < rows; i++) { IGridTable gridTable = logicalTable.getSubtable(colIdx, i, 1, 1).getSource(); Object value = gridTable.getCell(0, 0).getObjectValue(); if (value == null) { throw SyntaxNodeExceptionUtils.createError("Empty key in an unique index", new GridCellSourceCodeModule(gridTable)); } if (values.contains(value)) { throw SyntaxNodeExceptionUtils.createError("Duplicated key in an unique index: " + value, new GridCellSourceCodeModule(gridTable)); } values.add(value); } return values; }
private Object getArrayValues(ILogicalTable valuesTable, OpenlToolAdaptor ota, IOpenClass aggregateType, IOpenClass paramType) throws SyntaxNodeException { if (valuesTable.getHeight() == 1 && valuesTable.getWidth() == 1) { return RuleRowHelper.loadCommaSeparatedParam(aggregateType, paramType, field.getName(), null, valuesTable.getRow(0), ota); } return loadMultiRowArray(valuesTable, ota, paramType, aggregateType); }
private void addConstants(final IBindingContext cxt) throws Exception { final ILogicalTable dataTable = DatatypeHelper.getNormalizedDataPartTable(table, openl, cxt); normalizedData = dataTable; int tableHeight = 0; if (dataTable != null) { tableHeight = dataTable.getHeight(); } SyntaxNodeExceptionCollector syntaxNodeExceptionCollector = new SyntaxNodeExceptionCollector(); for (int i = 0; i < tableHeight; i++) { final int index = i; syntaxNodeExceptionCollector.run(new Runnable() { @Override public void run() throws Exception { ILogicalTable row = dataTable.getRow(index); processRow(row, cxt); } }); } syntaxNodeExceptionCollector.throwIfAny(); }
private void validateTableBody(TableSyntaxNode tableSyntaxNode, IBindingContext bindingContext) throws SyntaxNodeException { ILogicalTable tableBody = tableSyntaxNode.getTableBody(); if (tableBody == null) { throw SyntaxNodeExceptionUtils.createError("Table has no body! Try to merge header cell horizontally to identify table.", getTableSyntaxNode()); } int height = tableBody.getHeight(); int width = tableBody.getWidth(); if (height < 2 || width < 2) { String message = "Spreadsheet has empty body. Spreadsheet table should has at least 2x3 cells."; BindHelper.processWarn(message, tableSyntaxNode, bindingContext); } }
public String[] getParamPresentation() { int length = paramsTable.getHeight(); String[] result = new String[length]; int fromHeight = 0; for (int i = 0; i < result.length; i++) { int gridHeight = paramsTable.getRow(i).getSource().getHeight(); IGridTable singleParamGridTable = presentationTable.getSource().getRows(fromHeight, fromHeight + gridHeight - 1); result[i] = singleParamGridTable.getCell(0, 0).getStringValue(); fromHeight += gridHeight; } return result; }
@Override public CellMetaInfo getBodyMetaInfo(int row, int col) { ILogicalTable body = getTableSyntaxNode().getTableBody(); int height = body.getHeight(); for (int i = 0; i < height; i++) { ICell cell = body.getCell(0, i); if (isNeededCell(cell, row, col)) { List<CellMetaInfo> metaInfoList = OpenLCellExpressionsCompiler.getMetaInfo( getSourceCodeModule(body), ((TableMethod) getBoundNode().getMethod()).getCompositeMethod() ); return metaInfoList.get(i); } } return null; }
private boolean isProperties(int row, int col) { TableSyntaxNode tableSyntaxNode = getTableSyntaxNode(); if (!tableSyntaxNode.hasPropertiesDefinedInTable()) { return false; } ILogicalTable propertiesSection = tableSyntaxNode.getTableProperties().getPropertiesSection(); ICell firstCell = propertiesSection.getCell(0, 0); int r = row - firstCell.getAbsoluteRow(); int c = col - firstCell.getAbsoluteColumn(); // When c == -1 and r == 0 it's the "properties" keyword. return c >= -1 && r >= 0 && r < propertiesSection.getHeight() && c < propertiesSection.getWidth(); }
public void build(ILogicalTable tableBody) throws Exception { if (tableBody == null) { throw SyntaxNodeExceptionUtils.createError("Invalid table. Provide table body", null, tsn); } if (tableBody.getHeight() <= 2) { throw SyntaxNodeExceptionUtils.createError("Unsufficient rows. Must be more than 2!", null, tsn); } prepareColumns(tableBody); // parse data, row=2..* List<AlgorithmRow> algorithmRows = buildRows(tableBody); RowParser rowParser = new RowParser(algorithmRows, AlgorithmTableParserManager.getInstance() .getAlgorithmSpecification()); List<AlgorithmTreeNode> parsedNodes = rowParser.parse(); AlgorithmCompiler compiler = new AlgorithmCompiler(bindingContext, algorithm.getHeader(), parsedNodes); compiler.compile(algorithm); }
public void build(ILogicalTable tableBody) throws Exception { if (tableBody.getHeight() < 4) { throw SyntaxNodeExceptionUtils.createError("Unsufficient rows. At least 4 are expected!", null, tsn); } prepareColumns(tableBody); List<TableRow> rows = buildRows(tableBody); columnMatch.setColumns(columns); columnMatch.setRows(rows); IOpenSourceCodeModule alg = columnMatch.getAlgorithm(); String nameOfAlgorithm = (alg != null) ? alg.getCode() : null; IMatchAlgorithmCompiler algorithm; try { algorithm = MatchAlgorithmFactory.getAlgorithm(nameOfAlgorithm); } catch (Exception ex) { throw SyntaxNodeExceptionUtils.createError(ex, columnMatch.getSyntaxNode()); } algorithm.compile(bindingContext, columnMatch); }