diff options
| author | Dirk Fauth | 2023-01-11 15:52:21 +0000 |
|---|---|---|
| committer | Dirk Fauth | 2023-01-11 15:52:21 +0000 |
| commit | c6cbcc598e0b349573fb3d26a1a6015f6bbde6dc (patch) | |
| tree | d9242101ca700d345de4d0e2ff5f23430e78fe9a | |
| parent | d442cdfbd33a79fe1dfd55ab427cd34768a65614 (diff) | |
| download | org.eclipse.nebula.widgets.nattable-c6cbcc598e0b349573fb3d26a1a6015f6bbde6dc.tar.gz org.eclipse.nebula.widgets.nattable-c6cbcc598e0b349573fb3d26a1a6015f6bbde6dc.tar.xz org.eclipse.nebula.widgets.nattable-c6cbcc598e0b349573fb3d26a1a6015f6bbde6dc.zip | |
Bug 581328 - Hover not working with performance grouping
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
Change-Id: I50d997a5af46f6c72c2fed71bdaf13e19578ba2f
4 files changed, 220 insertions, 12 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 7992e362..bdacd671 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Dirk Fauth. + * Copyright (c) 2019, 2023 Dirk Fauth. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -55,6 +55,7 @@ import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer; import org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand; import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand; import org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand; +import org.eclipse.nebula.widgets.nattable.hover.HoverLayer; import org.eclipse.nebula.widgets.nattable.layer.DataLayer; import org.eclipse.nebula.widgets.nattable.layer.FixedScalingDpiConverter; import org.eclipse.nebula.widgets.nattable.layer.ILayer; @@ -62,6 +63,7 @@ import org.eclipse.nebula.widgets.nattable.layer.LabelStack; import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator; import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; import org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand; +import org.eclipse.nebula.widgets.nattable.layer.event.CellVisualUpdateEvent; import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer; import org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand; import org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderEndCommand; @@ -72,6 +74,8 @@ import org.eclipse.nebula.widgets.nattable.resize.command.MultiRowResizeCommand; import org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand; import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; import org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand; +import org.eclipse.nebula.widgets.nattable.style.DisplayMode; +import org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture; import org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider; import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer; import org.eclipse.nebula.widgets.nattable.viewport.command.ShowColumnInViewportCommand; @@ -85,6 +89,8 @@ import org.junit.jupiter.api.Test; public class ColumnGroupHeaderLayerTest { GroupModel groupModel; + HoverLayer columnHeaderHoverLayer; + ColumnHeaderLayer columnHeaderLayer; ColumnGroupHeaderLayer columnGroupHeaderLayer; ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer; SelectionLayer selectionLayer; @@ -134,8 +140,9 @@ public class ColumnGroupHeaderLayerTest { // build the column header layer IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap); DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider); - ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, this.selectionLayer); - this.columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, this.selectionLayer); + this.columnHeaderHoverLayer = new HoverLayer(columnHeaderDataLayer); + this.columnHeaderLayer = new ColumnHeaderLayer(this.columnHeaderHoverLayer, viewportLayer, this.selectionLayer); + this.columnGroupHeaderLayer = new ColumnGroupHeaderLayer(this.columnHeaderLayer, this.selectionLayer); this.groupModel = this.columnGroupHeaderLayer.getGroupModel(); @@ -11609,6 +11616,95 @@ public class ColumnGroupHeaderLayerTest { } @Test + public void shouldReturnConfigLabelsFromColumnHeader() { + // set config label accumulator + this.columnHeaderLayer.setConfigLabelAccumulator((configLabels, columnPosition, rowPosition) -> { + if (rowPosition == 0) { + configLabels.addLabel("columnHeaderRow"); + } + if (columnPosition == 0 || columnPosition == 3) { + configLabels.addLabel("custom"); + } + }); + + // check column group + LabelStack stack = this.columnGroupHeaderLayer.getConfigLabelsByPosition(0, 0); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel(GridRegion.COLUMN_GROUP_HEADER)); + assertTrue(stack.hasLabel(GroupHeaderConfigLabels.GROUP_EXPANDED_CONFIG_TYPE)); + + // check column header row + stack = this.columnGroupHeaderLayer.getConfigLabelsByPosition(0, 1); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel("columnHeaderRow")); + assertTrue(stack.hasLabel("custom")); + + // remove last column from first group + this.columnGroupHeaderLayer.removePositionsFromGroup(0, 3); + + // check ungrouped + stack = this.columnGroupHeaderLayer.getConfigLabelsByPosition(3, 0); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel("columnHeaderRow")); + assertTrue(stack.hasLabel("custom")); + + stack = this.columnGroupHeaderLayer.getConfigLabelsByPosition(3, 1); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel("columnHeaderRow")); + assertTrue(stack.hasLabel("custom")); + } + + @Test + public void shouldReturnDisplayModeFromColumnHeader() { + // remove last column from first group + this.columnGroupHeaderLayer.removePositionsFromGroup(0, 3); + + // the column group header only supports DisplayMode#NORMAL + assertEquals(DisplayMode.NORMAL, this.columnGroupHeaderLayer.getDisplayModeByPosition(0, 0)); + + // select a cell in the body + this.selectionLayer.selectCell(0, 0, false, false); + + assertEquals(DisplayMode.NORMAL, this.columnGroupHeaderLayer.getDisplayModeByPosition(0, 0)); + assertEquals(DisplayMode.SELECT, this.columnGroupHeaderLayer.getDisplayModeByPosition(0, 1)); + + // select a cell in the column that was removed from the group + this.selectionLayer.selectCell(3, 0, false, false); + + assertEquals(DisplayMode.SELECT, this.columnGroupHeaderLayer.getDisplayModeByPosition(3, 0)); + assertEquals(DisplayMode.SELECT, this.columnGroupHeaderLayer.getDisplayModeByPosition(3, 1)); + + // set a column header cell hovered + this.columnHeaderHoverLayer.setCurrentHoveredCellByIndex(0, 0); + assertEquals(DisplayMode.NORMAL, this.columnGroupHeaderLayer.getDisplayModeByPosition(0, 0)); + assertEquals(DisplayMode.HOVER, this.columnGroupHeaderLayer.getDisplayModeByPosition(0, 1)); + + // set a column header cell hovered in the column that was removed from + // the group + this.columnHeaderHoverLayer.setCurrentHoveredCellByIndex(3, 0); + assertEquals(DisplayMode.SELECT_HOVER, this.columnGroupHeaderLayer.getDisplayModeByPosition(3, 0)); + assertEquals(DisplayMode.SELECT_HOVER, this.columnGroupHeaderLayer.getDisplayModeByPosition(3, 1)); + } + + @Test + public void shouldConvertPositionsInEvent() { + LayerListenerFixture listener = new LayerListenerFixture(); + this.gridLayer.addLayerListener(listener); + + // fire a CellVisualChangeEvent + this.columnHeaderLayer.fireLayerEvent(new CellVisualUpdateEvent(this.columnHeaderLayer, 2, 0)); + + assertTrue(listener.containsInstanceOf(CellVisualUpdateEvent.class)); + CellVisualUpdateEvent event = (CellVisualUpdateEvent) listener.getReceivedEvent(CellVisualUpdateEvent.class); + + // column position changed from 2 to 3 because of the row header layer + assertEquals(3, event.getColumnPosition()); + // row position changed from 0 to 1 because of the column group header + // layer + assertEquals(1, event.getRowPosition()); + } + + @Test public void shouldCalculateRowHeightByPosition() { this.columnGroupHeaderLayer.clearAllGroups(); this.columnGroupHeaderLayer.setRowHeight(100); 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 aba80912..8cbd278a 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Dirk Fauth. + * Copyright (c) 2019, 2023 Dirk Fauth. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -56,6 +56,7 @@ import org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer; import org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand; import org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand; import org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand; +import org.eclipse.nebula.widgets.nattable.hover.HoverLayer; import org.eclipse.nebula.widgets.nattable.layer.DataLayer; import org.eclipse.nebula.widgets.nattable.layer.FixedScalingDpiConverter; import org.eclipse.nebula.widgets.nattable.layer.ILayer; @@ -63,6 +64,7 @@ import org.eclipse.nebula.widgets.nattable.layer.LabelStack; import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator; import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell; import org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand; +import org.eclipse.nebula.widgets.nattable.layer.event.CellVisualUpdateEvent; import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer; import org.eclipse.nebula.widgets.nattable.reorder.command.MultiRowReorderCommand; import org.eclipse.nebula.widgets.nattable.reorder.command.ResetRowReorderCommand; @@ -73,6 +75,8 @@ import org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand; import org.eclipse.nebula.widgets.nattable.resize.command.MultiColumnResizeCommand; import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; +import org.eclipse.nebula.widgets.nattable.style.DisplayMode; +import org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture; import org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider; import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer; import org.eclipse.nebula.widgets.nattable.viewport.command.ShowRowInViewportCommand; @@ -86,6 +90,8 @@ import org.junit.jupiter.api.Test; public class RowGroupHeaderLayerTest { GroupModel groupModel; + HoverLayer rowHeaderHoverLayer; + RowHeaderLayer rowHeaderLayer; RowGroupHeaderLayer rowGroupHeaderLayer; RowGroupExpandCollapseLayer rowGroupExpandCollapseLayer; SelectionLayer selectionLayer; @@ -140,9 +146,10 @@ public class RowGroupHeaderLayerTest { // build the row header layer IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider); DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider); - ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, this.selectionLayer); + this.rowHeaderHoverLayer = new HoverLayer(rowHeaderDataLayer); + this.rowHeaderLayer = new RowHeaderLayer(this.rowHeaderHoverLayer, viewportLayer, this.selectionLayer); - this.rowGroupHeaderLayer = new RowGroupHeaderLayer(rowHeaderLayer, this.selectionLayer); + this.rowGroupHeaderLayer = new RowGroupHeaderLayer(this.rowHeaderLayer, this.selectionLayer); this.groupModel = this.rowGroupHeaderLayer.getGroupModel(); @@ -11587,6 +11594,95 @@ public class RowGroupHeaderLayerTest { } @Test + public void shouldReturnConfigLabelsFromRowHeader() { + // set config label accumulator + this.rowHeaderLayer.setConfigLabelAccumulator((configLabels, columnPosition, rowPosition) -> { + if (columnPosition == 0) { + configLabels.addLabel("rowHeaderColumn"); + } + if (rowPosition == 0 || rowPosition == 3) { + configLabels.addLabel("custom"); + } + }); + + // check row group + LabelStack stack = this.rowGroupHeaderLayer.getConfigLabelsByPosition(0, 0); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel(GridRegion.ROW_GROUP_HEADER)); + assertTrue(stack.hasLabel(GroupHeaderConfigLabels.GROUP_EXPANDED_CONFIG_TYPE)); + + // check row header column + stack = this.rowGroupHeaderLayer.getConfigLabelsByPosition(1, 0); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel("rowHeaderColumn")); + assertTrue(stack.hasLabel("custom")); + + // remove last row from first group + this.rowGroupHeaderLayer.removePositionsFromGroup(0, 3); + + // check ungrouped + stack = this.rowGroupHeaderLayer.getConfigLabelsByPosition(0, 3); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel("rowHeaderColumn")); + assertTrue(stack.hasLabel("custom")); + + stack = this.rowGroupHeaderLayer.getConfigLabelsByPosition(1, 3); + assertEquals(2, stack.size()); + assertTrue(stack.hasLabel("rowHeaderColumn")); + assertTrue(stack.hasLabel("custom")); + } + + @Test + public void shouldReturnDisplayModeFromColumnHeader() { + // remove last column from first group + this.rowGroupHeaderLayer.removePositionsFromGroup(0, 3); + + // the column group header only supports DisplayMode#NORMAL + assertEquals(DisplayMode.NORMAL, this.rowGroupHeaderLayer.getDisplayModeByPosition(0, 0)); + + // select a cell in the body + this.selectionLayer.selectCell(0, 0, false, false); + + assertEquals(DisplayMode.NORMAL, this.rowGroupHeaderLayer.getDisplayModeByPosition(0, 0)); + assertEquals(DisplayMode.SELECT, this.rowGroupHeaderLayer.getDisplayModeByPosition(1, 0)); + + // select a cell in the column that was removed from the group + this.selectionLayer.selectCell(0, 3, false, false); + + assertEquals(DisplayMode.SELECT, this.rowGroupHeaderLayer.getDisplayModeByPosition(0, 3)); + assertEquals(DisplayMode.SELECT, this.rowGroupHeaderLayer.getDisplayModeByPosition(1, 3)); + + // set a column header cell hovered + this.rowHeaderHoverLayer.setCurrentHoveredCellByIndex(0, 0); + assertEquals(DisplayMode.NORMAL, this.rowGroupHeaderLayer.getDisplayModeByPosition(0, 0)); + assertEquals(DisplayMode.HOVER, this.rowGroupHeaderLayer.getDisplayModeByPosition(1, 0)); + + // set a column header cell hovered in the column that was removed from + // the group + this.rowHeaderHoverLayer.setCurrentHoveredCellByIndex(0, 3); + assertEquals(DisplayMode.SELECT_HOVER, this.rowGroupHeaderLayer.getDisplayModeByPosition(0, 3)); + assertEquals(DisplayMode.SELECT_HOVER, this.rowGroupHeaderLayer.getDisplayModeByPosition(1, 3)); + } + + @Test + public void shouldConvertPositionsInEvent() { + LayerListenerFixture listener = new LayerListenerFixture(); + this.gridLayer.addLayerListener(listener); + + // fire a CellVisualChangeEvent + this.rowHeaderLayer.fireLayerEvent(new CellVisualUpdateEvent(this.rowHeaderLayer, 0, 2)); + + assertTrue(listener.containsInstanceOf(CellVisualUpdateEvent.class)); + CellVisualUpdateEvent event = (CellVisualUpdateEvent) listener.getReceivedEvent(CellVisualUpdateEvent.class); + + // row position changed from 2 to 3 because of the column header layer + assertEquals(3, event.getRowPosition()); + // column position changed from 0 to 1 because of the row group header + // layer + assertEquals(1, event.getColumnPosition()); + } + + @Test public void shouldCalculateColumnWidthByPosition() { this.rowGroupHeaderLayer.clearAllGroups(); this.rowGroupHeaderLayer.setColumnWidth(100); 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 e2c604e9..7e42480c 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Dirk Fauth. + * Copyright (c) 2019, 2023 Dirk Fauth. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -713,6 +713,12 @@ public class ColumnGroupHeaderLayer extends AbstractLayerTransform { } } + @Override + public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition) { + int rowCount = this.model.size(); + return underlyingRowPosition + rowCount; + } + // Height private int getGroupingHeight() { @@ -1223,7 +1229,8 @@ public class ColumnGroupHeaderLayer extends AbstractLayerTransform { if (rowPosition < this.model.size() && isPartOfAGroup(getLevelForRowPosition(rowPosition), columnPosition)) { return DisplayMode.NORMAL; } else { - return this.underlyingLayer.getDisplayModeByPosition(columnPosition, rowPosition); + int rowPos = rowPosition < this.model.size() ? rowPosition : rowPosition - this.model.size(); + return this.underlyingLayer.getDisplayModeByPosition(columnPosition, rowPos); } } @@ -1250,7 +1257,8 @@ public class ColumnGroupHeaderLayer extends AbstractLayerTransform { return stack; } else { - return this.underlyingLayer.getConfigLabelsByPosition(columnPosition, rowPosition); + int rowPos = rowPosition < this.model.size() ? rowPosition : rowPosition - this.model.size(); + return this.underlyingLayer.getConfigLabelsByPosition(columnPosition, rowPos); } } 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 a0095b1a..660c470e 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2020 Dirk Fauth. + * Copyright (c) 2019, 2023 Dirk Fauth. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -706,6 +706,12 @@ public class RowGroupHeaderLayer extends AbstractLayerTransform { } } + @Override + public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) { + int columnCount = this.model.size(); + return underlyingColumnPosition + columnCount; + } + // Width private int getGroupingWidth() { @@ -1216,7 +1222,8 @@ public class RowGroupHeaderLayer extends AbstractLayerTransform { if (columnPosition < this.model.size() && isPartOfAGroup(getLevelForColumnPosition(columnPosition), rowPosition)) { return DisplayMode.NORMAL; } else { - return this.underlyingLayer.getDisplayModeByPosition(columnPosition, rowPosition); + int columnPos = columnPosition < this.model.size() ? columnPosition : columnPosition - this.model.size(); + return this.underlyingLayer.getDisplayModeByPosition(columnPos, rowPosition); } } @@ -1243,7 +1250,8 @@ public class RowGroupHeaderLayer extends AbstractLayerTransform { return stack; } else { - return this.underlyingLayer.getConfigLabelsByPosition(columnPosition, rowPosition); + int columnPos = columnPosition < this.model.size() ? columnPosition : columnPosition - this.model.size(); + return this.underlyingLayer.getConfigLabelsByPosition(columnPos, rowPosition); } } |
