001: package org.drools.brms.client.decisiontable.model;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: public class DecisionTable {
023: private Row headerRow = new HeaderRow(this );
024: private List rows = new ArrayList();
025: private List columns = new ArrayList();
026:
027: void addRow() {
028:
029: }
030:
031: void addColumn(final Column column) {
032: columns.add(column);
033: }
034:
035: public Row createRow() {
036: Row row = new Row(this );
037: rows.add(row);
038: return row;
039: }
040:
041: public Column createColumn() {
042: Column column = new Column(this );
043: columns.add(column);
044: return column;
045: }
046:
047: public Cell createCell(Row row, Column column) {
048: Cell cell = new Cell(row, column);
049: row.addCell(cell);
050: column.addCell(cell);
051: return cell;
052: }
053:
054: public Row getHeaderRow() {
055: return headerRow;
056: }
057:
058: public List getColumns() {
059: return columns;
060: }
061:
062: public List getRows() {
063: return rows;
064: }
065:
066: public Row getRow(int index) {
067: return (Row) rows.get(index);
068: }
069:
070: public int getRowIndex(Row row) {
071: return rows.indexOf(row);
072: }
073:
074: public int getColumnIndex(Column column) {
075: return columns.indexOf(column);
076: }
077:
078: public void mergeCol(Cell currentCell) {
079: Row row = currentCell.getRow();
080: int currentColspan = currentCell.getColspan();
081: int nextCellColumnIndex = currentCell.getColumnIndex()
082: + currentColspan;
083: Column nextColumn = (Column) columns.get(nextCellColumnIndex);
084: Cell nextCell = row.getCell(nextColumn);
085: currentCell.setColspan(currentColspan + nextCell.getColspan());
086: row.removeColumn(nextColumn);
087: nextColumn.removeCell(nextCell);
088: }
089:
090: public void mergeRow(Cell currentCell) {
091: Column column = currentCell.getColumn();
092: int currentRowspan = currentCell.getRowspan();
093: int nextCellRowIndex = currentCell.getRowIndex()
094: + currentRowspan;
095: Row nextRow = (Row) rows.get(nextCellRowIndex);
096: Cell nextCell = nextRow.getCell(column);
097: currentCell.setRowspan(currentRowspan + nextCell.getRowspan());
098: nextRow.removeColumn(column);
099: column.removeCell(nextCell);
100: }
101: }
|