From 30a234b86518e2edbfad318f6f2302f648115434 Mon Sep 17 00:00:00 2001 From: Dirk Fauth Date: Wed, 30 Apr 2025 11:01:00 +0200 Subject: [PATCH] Fixes #151 - [Group] dimensions not updated if all grouped are hidden Fixed rendering issues when grouping rows are hidden. Signed-off-by: Dirk Fauth --- .../ColumnGroupHeaderLayerTest.java | 109 ++++++++++++++++-- .../performance/RowGroupHeaderLayerTest.java | 100 ++++++++++++++-- .../TwoLevelColumnGroupHeaderLayerTest.java | 100 +++++++++++++++- .../TwoLevelRowGroupHeaderLayerTest.java | 94 ++++++++++++++- .../performance/ColumnGroupHeaderLayer.java | 51 ++++---- .../performance/RowGroupHeaderLayer.java | 49 ++++---- 6 files changed, 442 insertions(+), 61 deletions(-) diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayerTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayerTest.java index ba35e986..e63a51b9 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayerTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayerTest.java @@ -11716,9 +11716,8 @@ public void shouldCalculateRowHeightByPosition() { // Test calculated height this.columnGroupHeaderLayer.setCalculateHeight(true); assertEquals(20, this.columnGroupHeaderLayer.getHeight()); - assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); - assertEquals(0, this.columnGroupHeaderLayer.getRowHeightByPosition(0)); - assertEquals(20, this.columnGroupHeaderLayer.getRowHeightByPosition(1)); + assertEquals(1, this.columnGroupHeaderLayer.getRowCount()); + assertEquals(20, this.columnGroupHeaderLayer.getRowHeightByPosition(0)); } @Test @@ -11749,9 +11748,8 @@ public void shouldCalculateRowHeightOnGroupModelChanges() { this.columnGroupHeaderLayer.clearAllGroups(); assertEquals(20, this.columnGroupHeaderLayer.getHeight()); - assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); - assertEquals(0, this.columnGroupHeaderLayer.getRowHeightByPosition(0)); - assertEquals(20, this.columnGroupHeaderLayer.getRowHeightByPosition(1)); + assertEquals(1, this.columnGroupHeaderLayer.getRowCount()); + assertEquals(20, this.columnGroupHeaderLayer.getRowHeightByPosition(0)); cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); assertEquals("Firstname", cell.getDataValue()); @@ -11760,7 +11758,7 @@ public void shouldCalculateRowHeightOnGroupModelChanges() { assertEquals(1, cell.getColumnSpan()); assertEquals(0, cell.getOriginRowPosition()); assertEquals(0, cell.getRowPosition()); - assertEquals(2, cell.getRowSpan()); + assertEquals(1, cell.getRowSpan()); this.columnGroupHeaderLayer.setCalculateHeight(false); @@ -14743,37 +14741,132 @@ public void shouldUpdateHeightOnHidingGroupedColumns() { this.columnGroupHeaderLayer.setCalculateHeight(true); + // test the group states assertTrue(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(40, this.columnGroupHeaderLayer.getHeight()); assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); + // test the first cell in the group header (grouped cell) + ILayerCell cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(0, cell.getColumnIndex()); + assertEquals(4, cell.getColumnSpan()); + assertEquals(1, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(400, cell.getBounds().width); + assertEquals(20, cell.getBounds().height); + + // test the first non grouped cell + cell = this.columnGroupHeaderLayer.getCellByPosition(8, 0); + assertEquals(8, cell.getOriginColumnPosition()); + assertEquals(8, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(2, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(800, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(40, cell.getBounds().height); + // hide columns in Person group this.gridLayer.doCommand(new MultiColumnHideCommand(this.gridLayer, 1, 2, 3, 4)); + // test the group states assertTrue(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(0, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(40, this.columnGroupHeaderLayer.getHeight()); assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); + // test the first cell in the group header (grouped cell) + cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(4, cell.getColumnIndex()); + assertEquals(4, cell.getColumnSpan()); + assertEquals(1, cell.getRowSpan()); + assertEquals("Address", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(400, cell.getBounds().width); + assertEquals(20, cell.getBounds().height); + + // test the first non grouped cell + cell = this.columnGroupHeaderLayer.getCellByPosition(4, 0); + assertEquals(4, cell.getOriginColumnPosition()); + assertEquals(4, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(2, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(400, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(40, cell.getBounds().height); + // hide columns in Address group this.gridLayer.doCommand(new MultiColumnHideCommand(this.gridLayer, 1, 2, 3, 4)); + // test the group states assertFalse(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(0, nameGroup.getVisibleSpan()); assertEquals(0, addressGroup.getVisibleSpan()); assertEquals(20, this.columnGroupHeaderLayer.getHeight()); - assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); + assertEquals(1, this.columnGroupHeaderLayer.getRowCount()); + + // test the first cell in the group header (now ungrouped cell) + cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(1, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(20, cell.getBounds().height); // show all columns again this.gridLayer.doCommand(new ShowAllColumnsCommand()); + // test the group states assertTrue(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(40, this.columnGroupHeaderLayer.getHeight()); assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); + + // test the first cell in the group header (grouped cell) + cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(0, cell.getColumnIndex()); + assertEquals(4, cell.getColumnSpan()); + assertEquals(1, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(400, cell.getBounds().width); + assertEquals(20, cell.getBounds().height); + + // test the first non grouped cell + cell = this.columnGroupHeaderLayer.getCellByPosition(8, 0); + assertEquals(8, cell.getOriginColumnPosition()); + assertEquals(8, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(2, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(800, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(40, cell.getBounds().height); } } diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayerTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayerTest.java index 0bb0b54a..e2b5871d 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayerTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayerTest.java @@ -11694,9 +11694,8 @@ public void shouldCalculateColumnWidthByPosition() { // Test calculated width this.rowGroupHeaderLayer.setCalculateWidth(true); assertEquals(40, this.rowGroupHeaderLayer.getWidth()); - assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); - assertEquals(0, this.rowGroupHeaderLayer.getColumnWidthByPosition(0)); - assertEquals(40, this.rowGroupHeaderLayer.getColumnWidthByPosition(1)); + assertEquals(1, this.rowGroupHeaderLayer.getColumnCount()); + assertEquals(40, this.rowGroupHeaderLayer.getColumnWidthByPosition(0)); } @Test @@ -11727,9 +11726,8 @@ public void shouldCalculateColumnWidthOnGroupModelChanges() { this.rowGroupHeaderLayer.clearAllGroups(); assertEquals(40, this.rowGroupHeaderLayer.getWidth()); - assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); - assertEquals(0, this.rowGroupHeaderLayer.getColumnWidthByPosition(0)); - assertEquals(40, this.rowGroupHeaderLayer.getColumnWidthByPosition(1)); + assertEquals(1, this.rowGroupHeaderLayer.getColumnCount()); + assertEquals(40, this.rowGroupHeaderLayer.getColumnWidthByPosition(0)); cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); assertEquals(1, cell.getDataValue()); @@ -11738,7 +11736,7 @@ public void shouldCalculateColumnWidthOnGroupModelChanges() { assertEquals(1, cell.getRowSpan()); assertEquals(0, cell.getOriginColumnPosition()); assertEquals(0, cell.getColumnPosition()); - assertEquals(2, cell.getColumnSpan()); + assertEquals(1, cell.getColumnSpan()); this.rowGroupHeaderLayer.setCalculateWidth(false); @@ -14719,38 +14717,124 @@ public void shouldUpdateWidthOnHidingGroupedColumns() { this.rowGroupHeaderLayer.setCalculateWidth(true); + // test the group states assertTrue(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(60, this.rowGroupHeaderLayer.getWidth()); assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); + // test the first cell in the group header (grouped cell) + ILayerCell cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(80, cell.getBounds().height); + assertEquals(20, cell.getBounds().width); + + // test the first non grouped cell + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 8); + assertEquals(8, cell.getOriginRowPosition()); + assertEquals(8, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(2, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(160, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(60, cell.getBounds().width); + // hide columns in Person group this.gridLayer.doCommand(new MultiRowHideCommand(this.gridLayer, 1, 2, 3, 4)); + // test the group states assertTrue(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(0, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(60, this.rowGroupHeaderLayer.getWidth()); assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); + // test the first cell in the group header (grouped cell) + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowSpan()); + assertEquals("Address", cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(80, cell.getBounds().height); + assertEquals(20, cell.getBounds().width); + + // test the first non grouped cell + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 4); + assertEquals(4, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(2, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(80, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(60, cell.getBounds().width); + // hide columns in Address group this.gridLayer.doCommand(new MultiRowHideCommand(this.gridLayer, 1, 2, 3, 4)); + // test the group states assertFalse(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(0, nameGroup.getVisibleSpan()); assertEquals(0, addressGroup.getVisibleSpan()); assertEquals(40, this.rowGroupHeaderLayer.getWidth()); - assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); + assertEquals(1, this.rowGroupHeaderLayer.getColumnCount()); + + // test the first cell in the group header (now ungrouped cell) + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(0, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(40, cell.getBounds().width); // show all columns again this.gridLayer.doCommand(new ShowAllRowsCommand()); + // test the group states assertTrue(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(60, this.rowGroupHeaderLayer.getWidth()); assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); + + // test the first cell in the group header (grouped cell) + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(80, cell.getBounds().height); + assertEquals(20, cell.getBounds().width); + + // test the first non grouped cell + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 8); + assertEquals(8, cell.getOriginRowPosition()); + assertEquals(8, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(2, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(160, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(60, cell.getBounds().width); } } diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelColumnGroupHeaderLayerTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelColumnGroupHeaderLayerTest.java index a183fa4d..cdda34bc 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelColumnGroupHeaderLayerTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelColumnGroupHeaderLayerTest.java @@ -2514,6 +2514,7 @@ public void shouldUpdateHeightOnHidingGroupedColumns() { this.columnGroupHeaderLayer.setCalculateHeight(true); + // test the group states assertTrue(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); @@ -2521,35 +2522,130 @@ public void shouldUpdateHeightOnHidingGroupedColumns() { assertEquals(60, this.columnGroupHeaderLayer.getHeight()); assertEquals(3, this.columnGroupHeaderLayer.getRowCount()); + // test the first cell in the group header (grouped cell) + ILayerCell cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(0, cell.getColumnIndex()); + assertEquals(4, cell.getColumnSpan()); + assertEquals(2, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(400, cell.getBounds().width); + assertEquals(40, cell.getBounds().height); + + // test the first non grouped cell + cell = this.columnGroupHeaderLayer.getCellByPosition(8, 0); + assertEquals(8, cell.getOriginColumnPosition()); + assertEquals(8, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(3, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(800, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(60, cell.getBounds().height); + // hide columns in Address group this.gridLayer.doCommand(new MultiColumnHideCommand(this.gridLayer, 5, 6, 7, 8)); // this hides Test group in level 1, so height is reduced by one line + + // test the group states assertTrue(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(0, addressGroup.getVisibleSpan()); assertEquals(0, testGroup.getVisibleSpan()); assertEquals(40, this.columnGroupHeaderLayer.getHeight()); - assertEquals(3, this.columnGroupHeaderLayer.getRowCount()); + assertEquals(2, this.columnGroupHeaderLayer.getRowCount()); + + // test the first cell in the group header (grouped cell) + cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(0, cell.getColumnIndex()); + assertEquals(4, cell.getColumnSpan()); + assertEquals(1, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(400, cell.getBounds().width); + assertEquals(20, cell.getBounds().height); + + // test the first non grouped cell + cell = this.columnGroupHeaderLayer.getCellByPosition(4, 0); + assertEquals(4, cell.getOriginColumnPosition()); + assertEquals(4, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(2, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(400, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(40, cell.getBounds().height); // hide columns in Person group this.gridLayer.doCommand(new MultiColumnHideCommand(this.gridLayer, 1, 2, 3, 4)); + // test the group states assertFalse(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(0, nameGroup.getVisibleSpan()); assertEquals(0, addressGroup.getVisibleSpan()); assertEquals(0, testGroup.getVisibleSpan()); assertEquals(20, this.columnGroupHeaderLayer.getHeight()); - assertEquals(3, this.columnGroupHeaderLayer.getRowCount()); + assertEquals(1, this.columnGroupHeaderLayer.getRowCount()); + + // test the first cell in the group header (now ungrouped cell) + cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(1, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(20, cell.getBounds().height); // show all columns again this.gridLayer.doCommand(new ShowAllColumnsCommand()); + // test the group states assertTrue(this.columnGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(4, testGroup.getVisibleSpan()); assertEquals(60, this.columnGroupHeaderLayer.getHeight()); assertEquals(3, this.columnGroupHeaderLayer.getRowCount()); + + // test the first cell in the group header (grouped cell) + cell = this.columnGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginColumnPosition()); + assertEquals(0, cell.getColumnPosition()); + assertEquals(0, cell.getColumnIndex()); + assertEquals(4, cell.getColumnSpan()); + assertEquals(2, cell.getRowSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(400, cell.getBounds().width); + assertEquals(40, cell.getBounds().height); + + // test the first non grouped cell + cell = this.columnGroupHeaderLayer.getCellByPosition(8, 0); + assertEquals(8, cell.getOriginColumnPosition()); + assertEquals(8, cell.getColumnPosition()); + assertEquals(8, cell.getColumnIndex()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(3, cell.getRowSpan()); + assertEquals("Age", cell.getDataValue()); + assertEquals(800, cell.getBounds().x); + assertEquals(0, cell.getBounds().y); + assertEquals(100, cell.getBounds().width); + assertEquals(60, cell.getBounds().height); } } diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelRowGroupHeaderLayerTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelRowGroupHeaderLayerTest.java index 4b3c274f..95360087 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelRowGroupHeaderLayerTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/group/performance/TwoLevelRowGroupHeaderLayerTest.java @@ -2507,6 +2507,7 @@ public void shouldUpdateWidthOnHidingGroupedRows() { this.rowGroupHeaderLayer.setCalculateWidth(true); + // test the group states assertTrue(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); @@ -2514,36 +2515,125 @@ public void shouldUpdateWidthOnHidingGroupedRows() { assertEquals(80, this.rowGroupHeaderLayer.getWidth()); assertEquals(3, this.rowGroupHeaderLayer.getColumnCount()); + // test the first cell in the group header (grouped cell) + ILayerCell cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowSpan()); + assertEquals(2, cell.getColumnSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(80, cell.getBounds().height); + assertEquals(40, cell.getBounds().width); + + // test the first non grouped cell + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 8); + assertEquals(8, cell.getOriginRowPosition()); + assertEquals(8, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(3, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(160, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(80, cell.getBounds().width); + // hide columns in Address group this.gridLayer.doCommand(new MultiRowHideCommand(this.gridLayer, 5, 6, 7, 8)); // this hides Test group in level 1, so height is reduced by one line + + // test the group states assertTrue(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(0, addressGroup.getVisibleSpan()); assertEquals(0, testGroup.getVisibleSpan()); assertEquals(60, this.rowGroupHeaderLayer.getWidth()); - assertEquals(3, this.rowGroupHeaderLayer.getColumnCount()); + assertEquals(2, this.rowGroupHeaderLayer.getColumnCount()); + + // test the first cell in the group header (grouped cell) + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowSpan()); + assertEquals(1, cell.getColumnSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(80, cell.getBounds().height); + assertEquals(20, cell.getBounds().width); + + // test the first non grouped cell + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 4); + assertEquals(4, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(2, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(80, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(60, cell.getBounds().width); // hide columns in Person group this.gridLayer.doCommand(new MultiRowHideCommand(this.gridLayer, 1, 2, 3, 4)); + // test the group states assertFalse(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(0, nameGroup.getVisibleSpan()); assertEquals(0, addressGroup.getVisibleSpan()); assertEquals(0, testGroup.getVisibleSpan()); assertEquals(40, this.rowGroupHeaderLayer.getWidth()); - assertEquals(3, this.rowGroupHeaderLayer.getColumnCount()); + assertEquals(1, this.rowGroupHeaderLayer.getColumnCount()); + + // test the first cell in the group header (now ungrouped cell) + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(0, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(1, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(40, cell.getBounds().width); // show all columns again this.gridLayer.doCommand(new ShowAllRowsCommand()); + // test the group states assertTrue(this.rowGroupHeaderLayer.getGroupModel().isVisible()); assertEquals(4, nameGroup.getVisibleSpan()); assertEquals(4, addressGroup.getVisibleSpan()); assertEquals(4, testGroup.getVisibleSpan()); assertEquals(80, this.rowGroupHeaderLayer.getWidth()); assertEquals(3, this.rowGroupHeaderLayer.getColumnCount()); + + // test the first cell in the group header (grouped cell) + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 0); + assertEquals(0, cell.getOriginRowPosition()); + assertEquals(4, cell.getRowSpan()); + assertEquals(2, cell.getColumnSpan()); + assertEquals("Person", cell.getDataValue()); + assertEquals(0, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(80, cell.getBounds().height); + assertEquals(40, cell.getBounds().width); + + // test the first non grouped cell + cell = this.rowGroupHeaderLayer.getCellByPosition(0, 8); + assertEquals(8, cell.getOriginRowPosition()); + assertEquals(8, cell.getRowPosition()); + assertEquals(8, cell.getRowIndex()); + assertEquals(1, cell.getRowSpan()); + assertEquals(3, cell.getColumnSpan()); + assertEquals(9, cell.getDataValue()); + assertEquals(160, cell.getBounds().y); + assertEquals(0, cell.getBounds().x); + assertEquals(20, cell.getBounds().height); + assertEquals(80, cell.getBounds().width); } } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayer.java index 7d663ddb..bfd4102d 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayer.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/ColumnGroupHeaderLayer.java @@ -684,19 +684,26 @@ public void loadState(String prefix, Properties properties) { // Rows + private int internalGetRowCount() { + if (!this.calculateHeight) { + return this.model.size(); + } + return (int) this.model.stream().filter(gm -> gm.isVisible()).count(); + } + @Override public int getRowCount() { - return this.underlyingLayer.getRowCount() + this.model.size(); + return this.underlyingLayer.getRowCount() + internalGetRowCount(); } @Override public int getPreferredRowCount() { - return this.underlyingLayer.getPreferredRowCount() + this.model.size(); + return this.underlyingLayer.getPreferredRowCount() + internalGetRowCount(); } @Override public int getRowIndexByPosition(int rowPosition) { - int rowCount = this.model.size(); + int rowCount = internalGetRowCount(); if (rowPosition < rowCount) { return rowPosition; } else { @@ -706,7 +713,7 @@ public int getRowIndexByPosition(int rowPosition) { @Override public int localToUnderlyingRowPosition(int localRowPosition) { - int rowCount = this.model.size(); + int rowCount = internalGetRowCount(); if (localRowPosition < rowCount) { return localRowPosition; } else { @@ -716,7 +723,7 @@ public int localToUnderlyingRowPosition(int localRowPosition) { @Override public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition) { - int rowCount = this.model.size(); + int rowCount = internalGetRowCount(); return underlyingRowPosition + rowCount; } @@ -749,7 +756,7 @@ public int getPreferredHeight() { @Override public int getRowHeightByPosition(int rowPosition) { - int rowCount = this.model.size(); + int rowCount = internalGetRowCount(); if (rowPosition < rowCount) { if (!this.calculateHeight) { return this.rowHeightConfig.getSize(rowPosition); @@ -805,7 +812,7 @@ public int getRowPositionForLevel(int level) { * @return The level for the given row position. */ public int getLevelForRowPosition(int rowPosition) { - return this.model.size() - rowPosition - 1; + return internalGetRowCount() - rowPosition - 1; } // Row resize @@ -838,16 +845,18 @@ public void setRowPositionResizable(int rowPosition, boolean resizable) { @Override public int getRowPositionByY(int y) { int groupHeight = getGroupingHeight(); - if (y <= groupHeight) { + if (y == 0) { + return 0; + } else if (y <= groupHeight) { return LayerUtil.getRowPositionByY(this, y); } else { - return this.model.size() + this.underlyingLayer.getRowPositionByY(y - groupHeight); + return internalGetRowCount() + this.underlyingLayer.getRowPositionByY(y - groupHeight); } } @Override public int getStartYOfRowPosition(int rowPosition) { - int rowCount = this.model.size(); + int rowCount = internalGetRowCount(); if (rowPosition < rowCount) { if (!this.calculateHeight) { return this.rowHeightConfig.getAggregateSize(rowPosition); @@ -863,7 +872,7 @@ public int getStartYOfRowPosition(int rowPosition) { } } else { return getGroupingHeight() - + this.underlyingLayer.getStartYOfRowPosition(rowPosition - this.model.size()); + + this.underlyingLayer.getStartYOfRowPosition(rowPosition - internalGetRowCount()); } } @@ -872,7 +881,7 @@ public int getStartYOfRowPosition(int rowPosition) { @Override public ILayerCell getCellByPosition(final int columnPosition, final int rowPosition) { // Column group header cell - if (rowPosition < this.model.size()) { + if (rowPosition < internalGetRowCount()) { int level = getLevelForRowPosition(rowPosition); Group group = getGroupByPosition(level, columnPosition); if (group != null) { @@ -883,7 +892,7 @@ public ILayerCell getCellByPosition(final int columnPosition, final int rowPosit // check if there is a level above that does not have a group int row = rowPosition; int rowSpan = 1; - while (level < (this.model.size() - 1)) { + while (level < (internalGetRowCount() - 1)) { level++; Group upperGroup = getGroupByPosition(level, columnPosition); if (upperGroup == null) { @@ -1001,12 +1010,12 @@ public int getOriginRowPosition() { int rowSpan = 1; // check for special case if a column header data provider supports // multiple rows - if (rowPosition - 1 < this.model.size()) { + if (rowPosition - 1 < internalGetRowCount()) { // check if one row above has a group int level = getLevelForRowPosition(rowPosition - 1); Group group = null; - while (level < this.model.size()) { + while (level < internalGetRowCount()) { group = getGroupByPosition(level, columnPosition); if (group == null) { rowSpan++; @@ -1239,10 +1248,10 @@ public int getColumnSpan(Group group) { @Override public DisplayMode getDisplayModeByPosition(int columnPosition, int rowPosition) { - if (rowPosition < this.model.size() && isPartOfAGroup(getLevelForRowPosition(rowPosition), columnPosition)) { + if (rowPosition < internalGetRowCount() && isPartOfAGroup(getLevelForRowPosition(rowPosition), columnPosition)) { return DisplayMode.NORMAL; } else { - int rowPos = rowPosition < this.model.size() ? rowPosition : rowPosition - this.model.size(); + int rowPos = rowPosition < internalGetRowCount() ? rowPosition : rowPosition - internalGetRowCount(); return this.underlyingLayer.getDisplayModeByPosition(columnPosition, rowPos); } } @@ -1253,7 +1262,7 @@ public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) Object[] found = findGroupForCoordinates(posColumn, rowPosition); Group group = found != null ? (Group) found[1] : null; - if (rowPosition < this.model.size() && group != null) { + if (rowPosition < internalGetRowCount() && group != null) { LabelStack stack = new LabelStack(); if (getConfigLabelAccumulator() != null) { getConfigLabelAccumulator().accumulateConfigLabels(stack, columnPosition, rowPosition); @@ -1270,14 +1279,14 @@ public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) return stack; } else { - int rowPos = rowPosition < this.model.size() ? rowPosition : rowPosition - this.model.size(); + int rowPos = rowPosition < internalGetRowCount() ? rowPosition : rowPosition - internalGetRowCount(); return this.underlyingLayer.getConfigLabelsByPosition(columnPosition, rowPos); } } @Override public Object getDataValueByPosition(int columnPosition, int rowPosition) { - if (rowPosition < this.model.size()) { + if (rowPosition < internalGetRowCount()) { int level = getLevelForRowPosition(rowPosition); Group group = getGroupByPosition(level, columnPosition); while (group == null && level > 0) { @@ -1296,7 +1305,7 @@ public Object getDataValueByPosition(int columnPosition, int rowPosition) { @Override public LabelStack getRegionLabelsByXY(int x, int y) { if (y < getGroupingHeight()) { - for (int i = 0; i < this.model.size(); i++) { + for (int i = 0; i < internalGetRowCount(); i++) { if (isPartOfAGroup(i, getColumnPositionByX(x))) { return new LabelStack(GridRegion.COLUMN_GROUP_HEADER); } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayer.java index 1ff54023..7b816a1e 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayer.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/group/performance/RowGroupHeaderLayer.java @@ -677,19 +677,26 @@ public void loadState(String prefix, Properties properties) { // Columns + private int internalGetColumnCount() { + if (!this.calculateWidth) { + return this.model.size(); + } + return (int) this.model.stream().filter(gm -> gm.isVisible()).count(); + } + @Override public int getColumnCount() { - return this.underlyingLayer.getColumnCount() + this.model.size(); + return this.underlyingLayer.getColumnCount() + internalGetColumnCount(); } @Override public int getPreferredColumnCount() { - return this.underlyingLayer.getPreferredColumnCount() + this.model.size(); + return this.underlyingLayer.getPreferredColumnCount() + internalGetColumnCount(); } @Override public int getColumnIndexByPosition(int columnPosition) { - int columnCount = this.model.size(); + int columnCount = internalGetColumnCount(); if (columnPosition < columnCount) { return columnPosition; } else { @@ -699,7 +706,7 @@ public int getColumnIndexByPosition(int columnPosition) { @Override public int localToUnderlyingColumnPosition(int localColumnPosition) { - int columnCount = this.model.size(); + int columnCount = internalGetColumnCount(); if (localColumnPosition < columnCount) { return localColumnPosition; } else { @@ -709,7 +716,7 @@ public int localToUnderlyingColumnPosition(int localColumnPosition) { @Override public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) { - int columnCount = this.model.size(); + int columnCount = internalGetColumnCount(); return underlyingColumnPosition + columnCount; } @@ -742,7 +749,7 @@ public int getPreferredWidth() { @Override public int getColumnWidthByPosition(int columnPosition) { - int columnCount = this.model.size(); + int columnCount = internalGetColumnCount(); if (columnPosition < columnCount) { if (!this.calculateWidth) { return this.columnWidthConfig.getSize(columnPosition); @@ -798,7 +805,7 @@ public int getColumnPositionForLevel(int level) { * @return The level for the given column position. */ public int getLevelForColumnPosition(int columnPosition) { - return this.model.size() - columnPosition - 1; + return internalGetColumnCount() - columnPosition - 1; } // Column resize @@ -831,16 +838,18 @@ public void setColumnPositionResizable(int columnPosition, boolean resizable) { @Override public int getColumnPositionByX(int x) { int groupWidth = getGroupingWidth(); - if (x <= groupWidth) { + if (x == 0) { + return 0; + } else if (x <= groupWidth) { return LayerUtil.getColumnPositionByX(this, x); } else { - return this.model.size() + this.underlyingLayer.getColumnPositionByX(x - groupWidth); + return internalGetColumnCount() + this.underlyingLayer.getColumnPositionByX(x - groupWidth); } } @Override public int getStartXOfColumnPosition(int columnPosition) { - int columnCount = this.model.size(); + int columnCount = internalGetColumnCount(); if (columnPosition < columnCount) { if (!this.calculateWidth) { return this.columnWidthConfig.getAggregateSize(columnPosition); @@ -856,7 +865,7 @@ public int getStartXOfColumnPosition(int columnPosition) { } } else { return getGroupingWidth() - + this.underlyingLayer.getStartXOfColumnPosition(columnPosition - this.model.size()); + + this.underlyingLayer.getStartXOfColumnPosition(columnPosition - internalGetColumnCount()); } } @@ -865,7 +874,7 @@ public int getStartXOfColumnPosition(int columnPosition) { @Override public ILayerCell getCellByPosition(final int columnPosition, final int rowPosition) { // Row group header cell - if (columnPosition < this.model.size()) { + if (columnPosition < internalGetColumnCount()) { int level = getLevelForColumnPosition(columnPosition); Group group = getGroupByPosition(level, rowPosition); if (group != null) { @@ -876,7 +885,7 @@ public ILayerCell getCellByPosition(final int columnPosition, final int rowPosit // check if there is a level above that does not have a group int column = columnPosition; int columnSpan = 1; - while (level < (this.model.size() - 1)) { + while (level < (internalGetColumnCount() - 1)) { level++; Group upperGroup = getGroupByPosition(level, rowPosition); if (upperGroup == null) { @@ -994,12 +1003,12 @@ public int getOriginColumnPosition() { int columnSpan = 1; // check for special case if a row header data provider supports // multiple columns - if (columnPosition - 1 < this.model.size()) { + if (columnPosition - 1 < internalGetColumnCount()) { // check if one column to the left has a group int level = getLevelForColumnPosition(columnPosition - 1); Group group = null; - while (level < this.model.size()) { + while (level < internalGetColumnCount()) { group = getGroupByPosition(level, rowPosition); if (group == null) { columnSpan++; @@ -1230,7 +1239,7 @@ public int getRowSpan(Group group) { @Override public DisplayMode getDisplayModeByPosition(int columnPosition, int rowPosition) { - if (columnPosition < this.model.size() && isPartOfAGroup(getLevelForColumnPosition(columnPosition), rowPosition)) { + if (columnPosition < internalGetColumnCount() && isPartOfAGroup(getLevelForColumnPosition(columnPosition), rowPosition)) { return DisplayMode.NORMAL; } else { int columnPos = columnPosition < this.model.size() ? columnPosition : columnPosition - this.model.size(); @@ -1244,7 +1253,7 @@ public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) Object[] found = findGroupForCoordinates(columnPosition, posRow); Group group = found != null ? (Group) found[1] : null; - if (columnPosition < this.model.size() && group != null) { + if (columnPosition < internalGetColumnCount() && group != null) { LabelStack stack = new LabelStack(); if (getConfigLabelAccumulator() != null) { getConfigLabelAccumulator().accumulateConfigLabels(stack, columnPosition, rowPosition); @@ -1261,14 +1270,14 @@ public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) return stack; } else { - int columnPos = columnPosition < this.model.size() ? columnPosition : columnPosition - this.model.size(); + int columnPos = columnPosition < internalGetColumnCount() ? columnPosition : columnPosition - internalGetColumnCount(); return this.underlyingLayer.getConfigLabelsByPosition(columnPos, rowPosition); } } @Override public Object getDataValueByPosition(int columnPosition, int rowPosition) { - if (columnPosition < this.model.size()) { + if (columnPosition < internalGetColumnCount()) { int level = getLevelForColumnPosition(columnPosition); Group group = getGroupByPosition(level, rowPosition); while (group == null && level > 0) { @@ -1287,7 +1296,7 @@ public Object getDataValueByPosition(int columnPosition, int rowPosition) { @Override public LabelStack getRegionLabelsByXY(int x, int y) { if (x < getGroupingWidth()) { - for (int i = 0; i < this.model.size(); i++) { + for (int i = 0; i < internalGetColumnCount(); i++) { if (isPartOfAGroup(i, getRowPositionByY(y))) { return new LabelStack(GridRegion.ROW_GROUP_HEADER); }