@Override public String toString() { return grid.getCell(x, y).getUri(); }
public ICell getCell(int column, int row) { if (isEmpty(column, row)) { delegate.getCell(column, row); } return getFormattedCell(column, row); }
private static int getPropertyRowIndex(IGridRegion tableRegion, IGrid grid, String newPropName) { int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int firstPropertyRow = IGridRegion.Tool.height(grid.getCell(leftCell, topCell).getAbsoluteRegion()); String propsHeader = grid.getCell(leftCell, topCell + firstPropertyRow).getStringValue(); if (tableWithoutPropertySection(propsHeader)) { return -1; } int propsCount = grid.getCell(leftCell, topCell + 1).getHeight(); int propNameCellOffset = grid.getCell(leftCell, topCell + 1).getWidth(); for (int i = 0; i < propsCount; i++) { String propNameFromTable = grid.getCell(leftCell + propNameCellOffset, topCell + 1 + i) .getStringValue(); if (propNameFromTable != null && propNameFromTable.equals(newPropName)) { return topCell + 1 + i; } } return -1; }
private static IUndoableGridTableAction setExistingPropertyValue(IGridRegion tableRegion, IGrid grid, Object newPropValue, int propertyRowIndex, MetaInfoWriter metaInfoWriter) { int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int propNameCellOffset = grid.getCell(leftCell, topCell + 1).getWidth(); int propValueCellOffset = propNameCellOffset + grid.getCell(leftCell + propNameCellOffset, topCell + 1).getWidth(); Object propValueFromTable = grid.getCell(leftCell + propValueCellOffset, propertyRowIndex) .getObjectValue(); if (propValueFromTable != null && propValueFromTable.equals(newPropValue)) { // Property with such name and value already exists return null; } return new UndoableSetValueAction(leftCell + propValueCellOffset, propertyRowIndex, newPropValue, metaInfoWriter); }
public GridTableCell(int column, int row, IGridTable table) { this.column = column; this.row = row; this.table = table; int gridColumn = table.getGridColumn(column, row); int gridRow = table.getGridRow(column, row); this.cell = table.getGrid().getCell(gridColumn, gridRow); }
private synchronized FormattedCell getFormattedCell(int col, int row) { ICell cell = delegate.getCell(col, row); CellMetaInfo metaInfo = metaInfoReader.getMetaInfo(row, col); FormattedCell cellToFormat = new FormattedCell(cell, metaInfo); formatCell(cellToFormat, col, row); return cellToFormat; }
/** * Checks if the table specified by its region contains property. */ private CellKey getPropertyCoordinates(IGridRegion region, IGrid grid, String propName) { int left = region.getLeft(); int top = region.getTop(); ICell propsHeaderCell = grid.getCell(left, top + 1); String propsHeader = propsHeaderCell.getStringValue(); if (propsHeader == null || !propsHeader.equals(PropertiesHelper.PROPERTIES_HEADER)) { // There is no properties return null; } int propsCount = propsHeaderCell.getHeight(); for (int i = 0; i < propsCount; i++) { ICell propNameCell = grid.getCell(left + propsHeaderCell.getWidth(), top + 1 + i); String pName = propNameCell.getStringValue(); if (pName != null && pName.equals(propName)) { return CellKey.CellKeyFactory.getCellKey(1, 1 + i); } } return null; }
/** * Checks if the table specified by its region contains property. */ private CellKey getPropertyCoordinates(IGridRegion region, IGrid grid, String propName) { int left = region.getLeft(); int top = region.getTop(); ICell propsHeaderCell = grid.getCell(left, top + 1); String propsHeader = propsHeaderCell.getStringValue(); if (propsHeader == null || !propsHeader.equals(PropertiesHelper.PROPERTIES_HEADER)) { // There is no properties return null; } int propsCount = propsHeaderCell.getHeight(); for (int i = 0; i < propsCount; i++) { ICell propNameCell = grid.getCell(left + propsHeaderCell.getWidth(), top + 1 + i); String pName = propNameCell.getStringValue(); if (pName != null && pName.equals(propName)) { return CellKey.CellKeyFactory.getCellKey(1, 1 + i); } } return null; }
private static List<IUndoableGridTableAction> emptyCells(int colFrom, int rowFrom, int nCols, int nRows, IGrid grid, MetaInfoWriter metaInfoWriter) { List<IUndoableGridTableAction> actions = new ArrayList<>(); for (int i = nCols - 1; i >= 0; i--) { for (int j = nRows - 1; j >= 0; j--) { int cFrom = colFrom + i; int rFrom = rowFrom + j; if (grid.isTopLeftCellInMergedRegion(cFrom, rFrom)) { ICell cell = grid.getCell(cFrom, rFrom); if (cell.getHeight() > nRows || cell.getWidth() > nCols) { // Don't clear merged cells which are bigger than the cleaned region. continue; } } else if (grid.isPartOfTheMergedRegion(cFrom, rFrom)) { // Don't clear middle of the merged cells. continue; } actions.add(new UndoableSetValueAction(cFrom, rFrom, null, metaInfoWriter)); } } return actions; }
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))); } }
int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int firstPropertyRow = IGridRegion.Tool.height(grid.getCell(leftCell, topCell).getAbsoluteRegion()); .width(tableRegion) * rowsToMove); String propsHeader = grid.getCell(leftCell, topCell + firstPropertyRow).getStringValue(); int propNameCellOffset; int propValueCellOffset; actions.add(insertRows(1, firstPropertyRow, tableRegion, grid, true, metaInfoWriter)); actions.add(resizePropertiesHeader(tableRegion, grid, metaInfoWriter)); propNameCellOffset = grid.getCell(leftCell, topCell + firstPropertyRow).getWidth(); propValueCellOffset = propNameCellOffset + grid.getCell(leftCell + propNameCellOffset, topCell + firstPropertyRow).getWidth();
private static AUndoableCellAction shiftCell(int colFrom, int rowFrom, int colTo, int rowTo, IGrid grid, MetaInfoWriter metaInfoWriter) { if (!grid.isPartOfTheMergedRegion(colFrom, rowFrom) || grid.isTopLeftCellInMergedRegion(colFrom, rowFrom)) { // non top left cell of merged region have to be skipped return new UndoableShiftValueAction(colFrom, rowFrom, colTo, rowTo, metaInfoWriter); } return new SetBorderStyleAction(colTo, rowTo, grid.getCell(colFrom, rowFrom).getStyle(), false, metaInfoWriter); }
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); } }
private static IUndoableGridTableAction resizePropertiesHeader(IGridRegion tableRegion, IGrid grid, MetaInfoWriter metaInfoWriter) { int leftCell = tableRegion.getLeft(); int topCell = tableRegion.getTop(); int firstPropertyRow = IGridRegion.Tool.height(grid.getCell(leftCell, topCell).getAbsoluteRegion()); int propsCount = grid.getCell(leftCell, topCell + firstPropertyRow).getHeight(); if (propsCount == 1) { IGridRegion propHeaderRegion = grid.getRegionContaining(leftCell, topCell + firstPropertyRow); if (propHeaderRegion == null) { propHeaderRegion = new GridRegion(topCell + firstPropertyRow, leftCell, topCell + firstPropertyRow, leftCell); } return new UndoableResizeMergedRegionAction(propHeaderRegion, 1, INSERT, ROWS); } else { return new UndoableCompositeAction(resizeMergedRegions(grid, firstPropertyRow, 1, INSERT, ROWS, tableRegion, metaInfoWriter)); } }
private static CellStyle makeNewPropStyle(IGrid grid, int col, int row, int regionLeftCell, int regionWidth) { ICell cell = grid.getCell(col, row); CellStyle newCellStyle = new CellStyle(cell.getStyle()); ICellStyle cellStyle = cell.getStyle(); BorderStyle[] borderStyle = cellStyle != null ? cellStyle.getBorderStyle() : null; /*Create new cell style*/ if (borderStyle != null && col == regionLeftCell) { // Only left border will be set if (borderStyle.length == 4) { borderStyle = new BorderStyle[] { BorderStyle.NONE, BorderStyle.NONE, BorderStyle.NONE, borderStyle[3] }; } } else if (borderStyle != null && (col - regionLeftCell == regionWidth - 1)) { // Only right border will be set if (borderStyle.length == 4) { borderStyle = new BorderStyle[]{BorderStyle.NONE, borderStyle[1], BorderStyle.NONE, BorderStyle.NONE}; /*FIXME add bottom border for expender row (only for last) if (actionType != null && actionType == ActionType.EXPAND) { borderStyle = new short[]{CellStyle.BORDER_NONE, borderStyle[1], borderStyle[2], CellStyle.BORDER_NONE}; } else { borderStyle = new short[]{CellStyle.BORDER_NONE, borderStyle[1], CellStyle.BORDER_NONE, CellStyle.BORDER_NONE}; } */ } } else { borderStyle = new BorderStyle[] { BorderStyle.NONE, BorderStyle.NONE, BorderStyle.NONE, BorderStyle.NONE }; } newCellStyle.setBorderStyle(borderStyle); return newCellStyle; }
private CellMetaInfo searchMetaInfo(ColumnMatch columnMatch, int rowNum, int colNum, SubValue[] subValues, Object[] values) { IGrid grid = columnMatch.getSyntaxNode().getTableBody().getSource().getGrid(); for (int sv = 0; sv < subValues.length; sv++) { SubValue subValue = subValues[sv]; IGridRegion region = subValue.getGridRegion(); ICell cell = grid.getCell(region.getLeft(), region.getTop()); if (isNeededCell(cell, rowNum, colNum)) { // "values" column // We must check actual value because we can find IntRange instead of Integer there. Object value = values[sv]; return value == null ? null : new CellMetaInfo(JavaOpenClass.getOpenClass(value.getClass()), false); } } return NOT_FOUND; }
private boolean isSpecialRow(int rowNum) { ColumnMatch columnMatch = getBoundNode().getColumnMatch(); IGrid grid = columnMatch.getSyntaxNode().getTableBody().getSource().getGrid(); int firstNameRowNum = getSpecialRowCount(columnMatch); IGridRegion firstNameRegion = columnMatch.getRows().get(firstNameRowNum).get(NAMES)[0].getGridRegion(); ICell cell = grid.getCell(firstNameRegion.getLeft(), firstNameRegion.getTop()); return rowNum < cell.getAbsoluteRow(); }
public synchronized void setCellValue(int row, int col, String value, IFormatter formatter) { IGridRegion originalRegion = getOriginalTableRegion(); int gcol = originalRegion.getLeft() + col; int grow = originalRegion.getTop() + row; IFormatter dataFormatter; if (formatter != null) { dataFormatter = formatter; } else { ICell cell = gridTable.getGrid().getCell(gcol, grow); dataFormatter = cell.getDataFormatter(); } Object result; if (dataFormatter != null) { result = dataFormatter.parse(value); } else { result = value; } IUndoableGridTableAction action = new UndoableSetValueAction(gcol, grow, result); action.doAction(gridTable); actions.addNewAction(action); }
protected void setMetaInfoForConstant(IBindingContext bindingContext, ColumnMatch columnMatch, SubValue sv, String s, ConstantOpenField constantOpenField) { if (!bindingContext.isExecutionMode()) { IGridTable tableBodyGrid = columnMatch.getSyntaxNode().getTableBody().getSource(); IGrid grid = tableBodyGrid.getGrid(); IGridRegion gridRegion = sv.getGridRegion(); ICell cell = grid.getCell(gridRegion.getLeft(), gridRegion.getTop()); MetaInfoReader metaInfoReader = columnMatch.getSyntaxNode().getMetaInfoReader(); if (metaInfoReader instanceof BaseMetaInfoReader) { SimpleNodeUsage nodeUsage = RuleRowHelper.createConstantNodeUsage(s, constantOpenField); ((BaseMetaInfoReader) metaInfoReader).addConstant(cell, nodeUsage); } } }