Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2023-01-03 23:07:38 +0000
committerDirk Fauth2023-01-04 22:43:30 +0000
commit5f0acc553b648a7b81874c29b1c2cc0c4cd7e8e0 (patch)
tree877dab05120117d3dbe0bc7344ad68dd9bc5349c
parent0edf2b6ecd7e29fd4199ffb0522810f7775e1fc6 (diff)
downloadorg.eclipse.nebula.widgets.nattable-5f0acc553b648a7b81874c29b1c2cc0c4cd7e8e0.tar.gz
org.eclipse.nebula.widgets.nattable-5f0acc553b648a7b81874c29b1c2cc0c4cd7e8e0.tar.xz
org.eclipse.nebula.widgets.nattable-5f0acc553b648a7b81874c29b1c2cc0c4cd7e8e0.zip
Bug 581283 - SelectCellCommand#forcingEntireCellIntoViewport has no
effect Change-Id: I38e219ff83baa7a090dccb3d75b23c0ddc0a7000 Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java6
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java18
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectCellCommand.java10
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/event/CellSelectionEvent.java76
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java21
5 files changed, 106 insertions, 25 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java
index eaa51535..e22a7d48 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/RowSelectionProvider.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
@@ -263,7 +263,9 @@ public class RowSelectionProvider<T> implements ISelectionProvider, ILayerListen
this.selectionLayer.fireCellSelectionEvent(
this.selectionLayer.getLastSelectedCell().columnPosition,
this.selectionLayer.getLastSelectedCell().rowPosition,
- false, false, false);
+ true,
+ false,
+ false);
}
}
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java
index 58993cd2..37d1b275 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/SelectionLayer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2022 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
@@ -176,7 +176,9 @@ public class SelectionLayer extends AbstractIndexLayerTransform {
fireCellSelectionEvent(
getLastSelectedCell().columnPosition,
getLastSelectedCell().rowPosition,
- false, false, false);
+ true,
+ false,
+ false);
}
}
@@ -257,7 +259,7 @@ public class SelectionLayer extends AbstractIndexLayerTransform {
fireCellSelectionEvent(
updateCoordinate.columnPosition,
updateCoordinate.rowPosition,
- false,
+ true,
false,
false);
}
@@ -666,8 +668,11 @@ public class SelectionLayer extends AbstractIndexLayerTransform {
return super.doCommand(command);
}
- public void fireCellSelectionEvent(int columnPosition, int rowPosition,
- boolean forcingEntireCellIntoViewport, boolean withShiftMask,
+ public void fireCellSelectionEvent(
+ int columnPosition,
+ int rowPosition,
+ boolean forcingEntireCellIntoViewport,
+ boolean withShiftMask,
boolean withControlMask) {
int column = columnPosition;
@@ -684,7 +689,8 @@ public class SelectionLayer extends AbstractIndexLayerTransform {
column,
row,
withShiftMask,
- withControlMask);
+ withControlMask,
+ forcingEntireCellIntoViewport);
fireLayerEvent(selectionEvent);
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectCellCommand.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectCellCommand.java
index 8f9cb652..0fe82d5e 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectCellCommand.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/command/SelectCellCommand.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,10 +30,9 @@ public class SelectCellCommand extends AbstractPositionCommand {
private boolean shiftMask;
private boolean controlMask;
- private boolean forcingEntireCellIntoViewport = false;
+ private boolean forcingEntireCellIntoViewport = true;
- public SelectCellCommand(ILayer layer, int columnPosition, int rowPosition,
- boolean shiftMask, boolean controlMask) {
+ public SelectCellCommand(ILayer layer, int columnPosition, int rowPosition, boolean shiftMask, boolean controlMask) {
super(layer, columnPosition, rowPosition);
this.shiftMask = shiftMask;
this.controlMask = controlMask;
@@ -58,8 +57,7 @@ public class SelectCellCommand extends AbstractPositionCommand {
return this.forcingEntireCellIntoViewport;
}
- public void setForcingEntireCellIntoViewport(
- boolean forcingEntireCellIntoViewport) {
+ public void setForcingEntireCellIntoViewport(boolean forcingEntireCellIntoViewport) {
this.forcingEntireCellIntoViewport = forcingEntireCellIntoViewport;
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/event/CellSelectionEvent.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/event/CellSelectionEvent.java
index 63c6555d..7ea2b19b 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/event/CellSelectionEvent.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/selection/event/CellSelectionEvent.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
@@ -16,8 +16,7 @@ import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
-public class CellSelectionEvent extends CellVisualChangeEvent implements
- ISelectionEvent {
+public class CellSelectionEvent extends CellVisualChangeEvent implements ISelectionEvent {
private final SelectionLayer selectionLayer;
@@ -25,13 +24,60 @@ public class CellSelectionEvent extends CellVisualChangeEvent implements
private boolean withShiftMask = false;
private boolean withControlMask = false;
+ private boolean forcingEntireCellIntoViewport = true;
+
+ /**
+ * Creates a {@link CellSelectionEvent} that will move a selected cell into
+ * the viewport if it is currently not visible.
+ *
+ * @param selectionLayer
+ * The {@link SelectionLayer}.
+ * @param columnPosition
+ * The column position of the selected cell.
+ * @param rowPosition
+ * The row position of the selected cell.
+ * @param withShiftMask
+ * <code>true</code> if the SHIFT key was pressed.
+ * @param withControlMask
+ * <code>true</code> if the CTRL key was pressed.
+ */
+ public CellSelectionEvent(SelectionLayer selectionLayer,
+ int columnPosition, int rowPosition,
+ boolean withShiftMask, boolean withControlMask) {
+ super(selectionLayer, columnPosition, rowPosition);
+ this.selectionLayer = selectionLayer;
+ this.withControlMask = withControlMask;
+ this.withShiftMask = withShiftMask;
+ }
+
+ /**
+ * Creates a {@link CellSelectionEvent}.
+ *
+ * @param selectionLayer
+ * The {@link SelectionLayer}.
+ * @param columnPosition
+ * The column position of the selected cell.
+ * @param rowPosition
+ * The row position of the selected cell.
+ * @param withShiftMask
+ * <code>true</code> if the SHIFT key was pressed.
+ * @param withControlMask
+ * <code>true</code> if the CTRL key was pressed.
+ * @param forcingEntireCellIntoViewport
+ * <code>true</code> if the selected cell should be moved into
+ * the viewport, <code>false</code> if not.
+ *
+ * @since 2.1
+ */
public CellSelectionEvent(SelectionLayer selectionLayer,
- int columnPosition, int rowPosition, boolean withShiftMask,
- boolean withControlMask) {
+ int columnPosition, int rowPosition,
+ boolean withShiftMask, boolean withControlMask,
+ boolean forcingEntireCellIntoViewport) {
super(selectionLayer, columnPosition, rowPosition);
this.selectionLayer = selectionLayer;
this.withControlMask = withControlMask;
this.withShiftMask = withShiftMask;
+ this.forcingEntireCellIntoViewport = forcingEntireCellIntoViewport;
}
// Copy constructor
@@ -40,6 +86,7 @@ public class CellSelectionEvent extends CellVisualChangeEvent implements
this.selectionLayer = event.selectionLayer;
this.withControlMask = event.withControlMask;
this.withShiftMask = event.withShiftMask;
+ this.forcingEntireCellIntoViewport = event.forcingEntireCellIntoViewport;
}
@Override
@@ -52,14 +99,33 @@ public class CellSelectionEvent extends CellVisualChangeEvent implements
return new CellSelectionEvent(this);
}
+ /**
+ *
+ * @return <code>true</code> if the SHIFT key was pressed.
+ */
public boolean isWithShiftMask() {
return this.withShiftMask;
}
+ /**
+ *
+ * @return <code>true</code> if the CTRL key was pressed.
+ */
public boolean isWithControlMask() {
return this.withControlMask;
}
+ /**
+ *
+ * @return <code>true</code> if the selected cell should be moved into the
+ * viewport, <code>false</code> if not.
+ *
+ * @since 2.1
+ */
+ public boolean isForcingEntireCellIntoViewport() {
+ return this.forcingEntireCellIntoViewport;
+ }
+
@Override
public boolean convertToLocal(ILayer localLayer) {
if (this.columnPosition == SelectionLayer.NO_SELECTION
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java
index 8314cc7c..14edbbc8 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2021 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
@@ -27,6 +27,7 @@ import org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer;
import org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand;
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
import org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent;
+import org.eclipse.nebula.widgets.nattable.layer.event.VisualRefreshEvent;
import org.eclipse.nebula.widgets.nattable.print.command.PrintEntireGridCommand;
import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand;
import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand;
@@ -1513,11 +1514,19 @@ public class ViewportLayer extends AbstractLayerTransform implements IUniqueInde
* The event to handle
*/
private void processSelection(CellSelectionEvent selectionEvent) {
- moveCellPositionIntoViewport(
- selectionEvent.getColumnPosition(),
- selectionEvent.getRowPosition());
- adjustHorizontalScrollBar();
- adjustVerticalScrollBar();
+ if (selectionEvent.isForcingEntireCellIntoViewport()) {
+ moveCellPositionIntoViewport(
+ selectionEvent.getColumnPosition(),
+ selectionEvent.getRowPosition());
+ adjustHorizontalScrollBar();
+ adjustVerticalScrollBar();
+ } else {
+ // if the selected cell is not moved into the viewport, a
+ // VisualRefreshEvent needs to be fired to ensure a consistent view,
+ // e.g. a currently selected cell is not selected after the
+ // selection command.
+ fireLayerEvent(new VisualRefreshEvent(this));
+ }
}
/**

Back to the top