Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2023-01-09 11:34:05 +0000
committerDirk Fauth2023-01-09 11:34:05 +0000
commit63fb609615ff39abca58430b1ed3a3a9eaedddca (patch)
tree9a79f4a4671379fb58864417a02b49e241b2dfab
parent5f483a5408a00f74f8409687cd52bf4b82f914dc (diff)
downloadorg.eclipse.nebula.widgets.nattable-63fb609615ff39abca58430b1ed3a3a9eaedddca.tar.gz
org.eclipse.nebula.widgets.nattable-63fb609615ff39abca58430b1ed3a3a9eaedddca.tar.xz
org.eclipse.nebula.widgets.nattable-63fb609615ff39abca58430b1ed3a3a9eaedddca.zip
Bug 581303 - [Filter Row] - rendering glitch in scrolled state
Fixed also a rendering glitch if a filter cell editor is activated if it is only partly visible scrolled out of the viewport to the left. Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com> Change-Id: I9bb9f9a8422acc9382756ae0700e0fb1bf1d0b9a
-rw-r--r--org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/viewport/ShowInViewportCommandTest.java31
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/config/DefaultFilterRowConfiguration.java6
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/action/ShowColumnInViewportAction.java36
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommand.java65
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommandHandler.java9
5 files changed, 137 insertions, 10 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/viewport/ShowInViewportCommandTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/viewport/ShowInViewportCommandTest.java
index 59287825..50630c8b 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/viewport/ShowInViewportCommandTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/viewport/ShowInViewportCommandTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018, 2022 Dirk Fauth.
+ * Copyright (c) 2018, 2023 Dirk Fauth.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -14,16 +14,20 @@ package org.eclipse.nebula.widgets.nattable.viewport;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.eclipse.nebula.widgets.nattable.layer.FixedScalingDpiConverter;
+import org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand;
import org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack;
import org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture;
import org.eclipse.nebula.widgets.nattable.viewport.command.ShowCellInViewportCommand;
import org.eclipse.nebula.widgets.nattable.viewport.command.ShowColumnInViewportCommand;
import org.eclipse.nebula.widgets.nattable.viewport.command.ShowRowInViewportCommand;
+import org.eclipse.swt.graphics.Rectangle;
import org.junit.jupiter.api.Test;
public class ShowInViewportCommandTest {
- NatTableFixture natTable = new NatTableFixture(new DummyGridLayerStack(10, 50), 220, 220, true);
+ DummyGridLayerStack gridLayer = new DummyGridLayerStack(10, 50);
+ NatTableFixture natTable = new NatTableFixture(this.gridLayer, 220, 220, true);
@Test
public void shouldShowColumnInViewport() {
@@ -66,4 +70,27 @@ public class ShowInViewportCommandTest {
assertEquals(0, this.natTable.getColumnIndexByPosition(1));
assertEquals(0, this.natTable.getRowIndexByPosition(1));
}
+
+ @Test
+ public void shouldShowColumnCompletelyInViewport() {
+ this.natTable.doCommand(new ConfigureScalingCommand(new FixedScalingDpiConverter(96)));
+
+ Rectangle bounds = this.natTable.getCellByPosition(1, 1).getBounds();
+ assertEquals(40, bounds.x);
+
+ // scroll 90 pixels to the right so the first column is only half
+ // visible (40 pixels row header, 50 pixels half cell width)
+ ViewportLayer viewportLayer = this.gridLayer.getBodyLayer().getViewportLayer();
+ viewportLayer.invalidateHorizontalStructure();
+ viewportLayer.setOriginX(90);
+
+ bounds = this.natTable.getCellByPosition(1, 1).getBounds();
+ assertEquals(-50, bounds.x);
+
+ // bring the first column completely into the viewport again
+ this.natTable.doCommand(new ShowColumnInViewportCommand(this.natTable, 1));
+
+ bounds = this.natTable.getCellByPosition(1, 1).getBounds();
+ assertEquals(40, bounds.x);
+ }
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/config/DefaultFilterRowConfiguration.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/config/DefaultFilterRowConfiguration.java
index b63e5518..48bcc92f 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/config/DefaultFilterRowConfiguration.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/config/DefaultFilterRowConfiguration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2020 Original authors and others.
+ * Copyright (c) 2012, 2023 Original authors and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -31,6 +31,7 @@ import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorat
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
import org.eclipse.nebula.widgets.nattable.ui.matcher.KeyEventMatcher;
+import org.eclipse.nebula.widgets.nattable.viewport.action.ShowColumnInViewportAction;
import org.eclipse.swt.SWT;
//fields are public by design to make it easy for adapters to customize configuration
@@ -82,6 +83,9 @@ public class DefaultFilterRowConfiguration extends AbstractRegistryConfiguration
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
+ uiBindingRegistry.registerFirstMouseDownBinding(
+ new FilterRowMouseEventMatcher(),
+ new ShowColumnInViewportAction());
uiBindingRegistry.registerFirstSingleClickBinding(
new FilterRowMouseEventMatcher(),
new MouseEditAction());
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/action/ShowColumnInViewportAction.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/action/ShowColumnInViewportAction.java
new file mode 100644
index 00000000..b646320d
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/action/ShowColumnInViewportAction.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2023 Original authors and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.viewport.action;
+
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.ui.action.IMouseAction;
+import org.eclipse.nebula.widgets.nattable.viewport.command.ShowColumnInViewportCommand;
+import org.eclipse.swt.events.MouseEvent;
+
+/**
+ * Action to move a cell into the viewport.
+ *
+ * @since 2.1
+ */
+public class ShowColumnInViewportAction implements IMouseAction {
+
+ @Override
+ public void run(NatTable natTable, MouseEvent event) {
+ // only perform the selection if the cursor is null
+ if (natTable.getCursor() == null)
+ natTable.doCommand(
+ new ShowColumnInViewportCommand(
+ natTable,
+ natTable.getColumnPositionByX(event.x)));
+ }
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommand.java
index 0952fcf6..e74480d9 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2020 Original authors and others.
+ * Copyright (c) 2012, 2023 Original authors and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -12,16 +12,21 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.viewport.command;
-import org.eclipse.nebula.widgets.nattable.command.AbstractContextFreeCommand;
+import org.eclipse.nebula.widgets.nattable.command.AbstractColumnCommand;
+import org.eclipse.nebula.widgets.nattable.command.ILayerCommand;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
/**
* Command to show a column position in the viewport.
*/
-public class ShowColumnInViewportCommand extends AbstractContextFreeCommand {
+public class ShowColumnInViewportCommand extends AbstractColumnCommand {
private final int columnPosition;
/**
+ * Create a command with a fixed column position based on the underlying
+ * layer of the ViewportLayer that does not get converted while processing.
+ *
* @param columnPosition
* The column position in the underlying layer of the
* ViewportLayer that should be shown in the viewport.
@@ -29,15 +34,67 @@ public class ShowColumnInViewportCommand extends AbstractContextFreeCommand {
* @since 1.6
*/
public ShowColumnInViewportCommand(int columnPosition) {
+ super(null, columnPosition);
this.columnPosition = columnPosition;
}
/**
+ * Create a command with a ColumnPositionCoordinate that gets converted
+ * while processing down the layer stack.
+ *
+ * @param layer
+ * The {@link ILayer} to which the column position correlate.
+ * @param columnPosition
+ * The column position related to the given layer for which the
+ * command should be processed.
+ *
+ * @since 2.1
+ */
+ public ShowColumnInViewportCommand(ILayer layer, int columnPosition) {
+ super(layer, columnPosition);
+ this.columnPosition = -1;
+ }
+
+ /**
+ * Clone constructor.
+ *
+ * @param command
+ * The command to clone.
+ *
+ * @since 2.1
+ */
+ protected ShowColumnInViewportCommand(ShowColumnInViewportCommand command) {
+ super(command);
+ this.columnPosition = command.columnPosition;
+ }
+
+ /**
* @return The column position in the layer below the ViewportLayer to be
- * shown.
+ * shown or the column position related to the ILayer that was
+ * passed at command creation.
*/
+ @Override
public int getColumnPosition() {
+ if (getLayer() != null) {
+ return super.getColumnPosition();
+ }
return this.columnPosition;
}
+ @Override
+ public boolean convertToTargetLayer(ILayer targetLayer) {
+ if (getLayer() != null) {
+ return super.convertToTargetLayer(targetLayer);
+ }
+ return true;
+ }
+
+ @Override
+ public ILayerCommand cloneCommand() {
+ if (getLayer() != null) {
+ return new ShowColumnInViewportCommand(this);
+ }
+ return this;
+ }
+
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommandHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommandHandler.java
index 38d9b4f1..6145bc92 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommandHandler.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/command/ShowColumnInViewportCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2020 Original authors and others.
+ * Copyright (c) 2012, 2023 Original authors and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -30,8 +30,11 @@ public class ShowColumnInViewportCommandHandler extends AbstractLayerCommandHand
@Override
protected boolean doCommand(ShowColumnInViewportCommand command) {
- this.viewportLayer.moveColumnPositionIntoViewport(command.getColumnPosition());
- return true;
+ if (command.convertToTargetLayer(this.viewportLayer.getScrollableLayer())) {
+ this.viewportLayer.moveColumnPositionIntoViewport(command.getColumnPosition());
+ return true;
+ }
+ return false;
}
}

Back to the top