incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fh...@apache.org
Subject svn commit: r1503557 - in /incubator/odf/trunk/simple/src: main/java/org/odftoolkit/simple/table/Row.java main/java/org/odftoolkit/simple/table/Table.java test/java/org/odftoolkit/simple/table/TableTest.java
Date Tue, 16 Jul 2013 04:58:06 GMT
Author: fhopf
Date: Tue Jul 16 04:58:06 2013
New Revision: 1503557

URL: http://svn.apache.org/r1503557
Log:
ODFTOOLKIT-355 Rows can be removed from documents

Modified:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Row.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Table.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableTest.java

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Row.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Row.java?rev=1503557&r1=1503556&r2=1503557&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Row.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Row.java Tue Jul
16 04:58:06 2013
@@ -958,16 +958,19 @@ public class Row extends Component {
 		Table table = getTable();
 		for (int i = 0; i < table.getColumnCount();) {
 			Cell cell = getCellByIndex(i);
-			if (cell.isCoveredElement()) {
-				// cell is a cover cell
-				Cell coverCell = cell.getCoverCellInSameColumn();
-				if (coverCell != null) {
-					coverCell.setRowSpannedNumber(coverCell.getRowSpannedNumber() - getRowsRepeatedNumber());
-				}
-				getOdfElement().removeChild(cell.getOdfElement());
+			if (cell == null) {
+				// cell might be null for empty row
+				i++;
 			} else {
-				// cell is not a cover cell and it span more rows
-				if (cell.getRowSpannedNumber() > 1) {
+				if (cell.isCoveredElement()) {
+					// cell is a cover cell
+					Cell coverCell = cell.getCoverCellInSameColumn();
+					if (coverCell != null) {
+						coverCell.setRowSpannedNumber(coverCell.getRowSpannedNumber() - getRowsRepeatedNumber());
+					}
+					getOdfElement().removeChild(cell.getOdfElement());
+				} else if (cell.getRowSpannedNumber() > 1) {
+					// cell is not a cover cell and it span more rows
 					// split the cell under this cell to a single cell
 					Row nextRow = table.getRowByIndex(getRowIndex() + 1);
 					if (nextRow.getRowsRepeatedNumber() > 1) {
@@ -990,8 +993,8 @@ public class Row extends Component {
 					coveredCell.getOdfElement().getParentNode().replaceChild(newCellEle, coveredCell.getOdfElement());
 					table.updateRepositoryWhenCellElementChanged(startRow, endRow, startClm, endClm, newCellEle);
 				}
+				i += cell.getColumnSpannedNumber();
 			}
-			i += cell.getColumnSpannedNumber();
 		}
 	}
 }

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Table.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Table.java?rev=1503557&r1=1503556&r2=1503557&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Table.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Table.java Tue Jul
16 04:58:06 2013
@@ -2467,7 +2467,7 @@ public class Table extends Component {
 			}
 		}
 		// 2. if mediumRow becomes as top row, revise style
-		if (deleted && startIndex == 0) {
+		if (deleted && startIndex == 0 && getRowCount() > 0) {
 			Row aRow = getRowByIndex(0);
 			reviseStyleFromMediumRowToTopRow(aRow);
 		}

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableTest.java?rev=1503557&r1=1503556&r2=1503557&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableTest.java (original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableTest.java Tue
Jul 16 04:58:06 2013
@@ -1175,6 +1175,18 @@ public class TableTest {
 		}
 	}
 
+	@Test
+	public void testDeleteRowsOnEmptyTable() throws Exception {
+		SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
+		Table odfTable = doc.addTable();
+		// two rows are created by default
+		Assert.assertEquals(2, odfTable.getRowCount());
+		while(odfTable.getRowCount() != 0) {
+			odfTable.removeRowsByIndex(0, 1);
+		}
+		Assert.assertEquals(0, odfTable.getRowCount());
+	}
+
 	private void testAppendRow(TableTableElement table) {
 		Table fTable = Table.getInstance(table);
 		int count = fTable.getRowCount();



Mime
View raw message