public int getWidth() { return (columnNamesTable == null) ? 0 : columnNamesTable.getWidth(); }
public int nValues() { return decisionTable.getWidth() - IDecisionTableConstants.SERVICE_COLUMNS_NUMBER; }
private ILogicalTable unmergeFirstRow(ILogicalTable toParse) { ILogicalTable unmerged = LogicalTableHelper.unmergeColumns(toParse, IDecisionTableConstants.SERVICE_COLUMNS_NUMBER, toParse.getWidth()); return unmerged; }
/** * Returns logical table that contains rule column. The column will contain * all return, action and condition cells for rule specified by index. * * @param ruleIndex Index of rule. * @return ILogicalTable that contains rule column. */ public ILogicalTable getRuleTable(int ruleIndex) { ILogicalTable dt = actionRows[0].getDecisionTable(); int starColumn = dt.getWidth() - columns; return dt.getColumn(starColumn + ruleIndex); }
/** * * @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; }
/** * Returns all regions of a table. * * @param table the table with regions. * @return a the regions of the table. */ public static List<IGridRegion> getGridRegions(ILogicalTable table) { int height = table.getHeight(); int width = table.getWidth(); List<IGridRegion> regions = new ArrayList<IGridRegion>(); // Go through all possible cells for (int row = 0; row < height; row++) { for (int column = 0; column < width; column++) { ICell cell = table.getCell(column, row); regions.add(cell.getAbsoluteRegion()); } } return regions; } }
private static int[] getColumnOffsets(ILogicalTable table) { if (table instanceof LogicalTable) { return ((LogicalTable)table).getColumnOffset(); } return calculateColumnOffsets(table.getWidth(), table.getSource()); }
private IOpenClass getFieldType(IBindingContext bindingContext, ILogicalTable row, GridCellSourceCodeModule tableSrc) throws SyntaxNodeException { IOpenClass fieldType = OpenLManager.makeType(openl, tableSrc, bindingContext); if (fieldType == null || fieldType instanceof NullOpenClass) { String errorMessage = String.format("Type %s is not found", tableSrc.getCode()); throw SyntaxNodeExceptionUtils.createError(errorMessage, null, null, tableSrc); } if (row.getWidth() < 2) { String errorMessage = "Bad table structure: must be {header} / {type | name}"; throw SyntaxNodeExceptionUtils.createError(errorMessage, null, null, tableSrc); } return fieldType; }
private IOpenClass getConstantType(IBindingContext bindingContext, ILogicalTable row, GridCellSourceCodeModule tableSrc) throws SyntaxNodeException { IOpenClass fieldType = OpenLManager.makeType(openl, tableSrc, bindingContext); if (fieldType == null || fieldType instanceof NullOpenClass) { String errorMessage = String.format("Type %s is not found", tableSrc.getCode()); throw SyntaxNodeExceptionUtils.createError(errorMessage, null, null, tableSrc); } if (row.getWidth() < 2) { String errorMessage = "Bad table structure: must be {header} / {type | name}"; throw SyntaxNodeExceptionUtils.createError(errorMessage, null, null, tableSrc); } return fieldType; }
/** * Foreign keys row is optional for data table. It consists reference for field value to other table. Foreign keys * always starts from {@value #INDEX_ROW_REFERENCE_START_SYMBOL} symbol. * * @param dataTable data table to check * @return <code>TRUE</code> if second row in data table body (next to the field row) consists even one value, in * any column, starts with {@value #INDEX_ROW_REFERENCE_START_SYMBOL} symbol. */ public static boolean hasForeignKeysRow(ILogicalTable dataTable) { ILogicalTable potentialForeignKeysRow = dataTable.getRows(1, 1); int columnsCount = potentialForeignKeysRow.getWidth(); for (int i = 0; i < columnsCount; i++) { ILogicalTable cell = potentialForeignKeysRow.getColumn(i); String value = cell.getSource().getCell(0, 0).getStringValue(); if (value == null || value.trim().length() == 0) { continue; } return value.charAt(0) == INDEX_ROW_REFERENCE_START_SYMBOL; } return false; }
private void prepareColumns(ILogicalTable tableBody) throws SyntaxNodeException { columns = new ArrayList<TableColumn>(); Set<String> addedIds = new HashSet<String>(); ILogicalTable ids = tableBody.getRow(0); // parse ids, row=0 for (int c = 0; c < ids.getWidth(); c++) { String id = safeId(ids.getColumn(c).getSource().getCell(0, 0).getStringValue()); if (id.length() == 0) { // ignore column with NO ID continue; } if (addedIds.contains(id)) { // duplicate ids throw SyntaxNodeExceptionUtils.createError("Duplicate column '" + id + "'!", null, tsn); } columns.add(new TableColumn(id, c)); addedIds.add(id); } }
public static int countHConditions(ILogicalTable table) { int width = table.getWidth(); int cnt = 0; for (int i = 0; i < width; i++) { String value = table.getColumn(i).getSource().getCell(0, 0).getStringValue(); if (value != null) { value = value.toUpperCase(); if (isValidHConditionHeader(value)) { ++cnt; } } } return cnt; }
public static int countConditionsAndActions(ILogicalTable table) { int width = table.getWidth(); int count = 0; for (int i = 0; i < width; i++) { String value = table.getColumn(i).getSource().getCell(0, 0).getStringValue(); if (value != null) { value = value.toUpperCase(); count += isValidConditionHeader(value) || isActionHeader(value) ? 1 : 0; } } return count; }
private void prepareColumns(ILogicalTable tableBody) throws SyntaxNodeException { columns = new HashMap<>(); ILogicalTable ids = tableBody.getRow(0); // parse ids, row=0 for (int c = 0; c < ids.getWidth(); c++) { String id = safeId(ids.getColumn(c).getSource().getCell(0, 0).getStringValue()); if (id.length() == 0) { // ignore column with NO ID continue; } if (columns.get(id) != null) { // duplicate ids throw SyntaxNodeExceptionUtils.createError("Duplicate column '" + id + "'!", null, tsn); } columns.put(id, new AlgorithmColumn(id, c)); } }
public static int countVConditions(ILogicalTable table) { int width = table.getWidth(); int cnt = 0; for (int i = 0; i < width; i++) { String value = table.getColumn(i).getSource().getCell(0, 0).getStringValue(); if (value != null) { value = value.toUpperCase(); if (isValidConditionHeader(value) || isValidMergedConditionHeader(value)) { ++cnt; } } } return cnt; }
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 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); } }
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(); }
private static void validateSimpleParam(ILogicalTable table, IBindingContext bindingContext) throws SyntaxNodeException { ICell theCell = table.getSource().getCell(0, 0); if (table.getWidth() > 1 || table.getHeight() > 1) { for (int i = 0; i < table.getHeight(); i++) { for (int j = 0; j < table.getWidth(); j++) { if ((!(i == 0 && j == 0))) { ICell cell = table.getCell(j, i); if ((theCell.getAbsoluteRegion().getTop() != cell.getAbsoluteRegion().getTop() || theCell .getAbsoluteRegion() .getLeft() != cell.getAbsoluteRegion().getLeft()) && cell.getStringValue() != null) { if (!cell.getStringValue().startsWith(COMMENTARY)) { IGridTable cellTable = getTopLeftCellFromMergedRegion(table.getSource()); throw SyntaxNodeExceptionUtils.createError( "Table structure is wrong. More than one cell with data found where only one cell is expected.", new GridCellSourceCodeModule(cellTable, bindingContext)); } } } } } } }