private void parseHeader(TablePart tablePart) throws OpenLCompilationException { GridCellSourceCodeModule src = new GridCellSourceCodeModule(tablePart.getTable()); String header = src.getCode(); Matcher m = pattern.matcher(header); if (!m.matches()) { String message = "Valid Syntax: TablePart <table_id> <row|column> <npart(1 to total_number_of_parts)> of <total_number_of_parts>"; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); } String tableId = m.group(1); String colOrRow = m.group(2); String npart = m.group(3); String totalParts = m.group(4); tablePart.setPartName(tableId); tablePart.setPart(Integer.parseInt(npart)); tablePart.setSize(Integer.parseInt(totalParts)); tablePart.setVertical(colOrRow.equals("row")); }
private synchronized void addToParts(TablePart tablePart) throws OpenLCompilationException { String key = tablePart.getPartName(); TreeSet<TablePart> set = tableParts.get(key); if (set == null) { set = new TreeSet<TablePart>(); tableParts.put(key, set); } boolean res = set.add(tablePart); if (!res) { String message = "Duplicated TablePart part # = " + tablePart.getPart(); throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); } }
if (tablePart.getPart() != cnt + 1) { String message = "TablePart number " + tablePart.getPart() + " is out of order"; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); if (tablePart.getSize() != n) { String message = "TablePart " + tablePart.getPartName() + " number " + tablePart .getPart() + " has wrong number of parts: " + tablePart .getSize() + ". There are " + n + " parts with the same name"; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); ICell cell00 = tablePart.getTable().getCell(0, 0); IGridTable table = tablePart.getTable().getRows(cell00.getHeight()); if (table == null) { String message = "TablePart " + tablePart.getPartName() + " number " + tablePart .getPart() + " has wrong content."; throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); boolean myVert = tablePart.isVertical(); int myDim = myVert ? table.getWidth() : table.getHeight(); if (myVert != vertical) { String message = "TablePart number " + tablePart .getPart() + " must use " + (vertical ? "row" : "column"); throw new OpenLCompilationException(message, null, null, makeSourceModule(tablePart.getTable())); .getPart() + " has " + (vertical ? "width" : "height") + " = " + myDim + " instead of " + dimension; if (vertical) {
private WorkbookSyntaxNode createWorkbookNode(TablePartProcessor tablePartProcessor, XlsWorkbookSourceCodeModule workbookSourceModule, WorksheetSyntaxNode[] sheetNodes) { TableSyntaxNode[] mergedNodes = {}; try { List<TablePart> tableParts = tablePartProcessor.mergeAllNodes(); int n = tableParts.size(); mergedNodes = new TableSyntaxNode[n]; for (int i = 0; i < n; i++) { mergedNodes[i] = preprocessTable(tableParts.get(i).getTable(), tableParts.get(i).getSource(), tablePartProcessor); } } catch (OpenLCompilationException e) { messages.add(OpenLMessagesUtils.newErrorMessage(e)); } return new WorkbookSyntaxNode(sheetNodes, mergedNodes, workbookSourceModule); }
public void register(IGridTable table, XlsSheetSourceCodeModule source) throws OpenLCompilationException { TablePart tablePart = new TablePart(table, source); parseHeader(tablePart); addToParts(tablePart); }