Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2016-01-25 21:59:58 +0000
committerDirk Fauth2016-01-25 22:00:54 +0000
commit13d3eefce84e257e4f3e6c84b57e53f354d52320 (patch)
tree8d131fa746fc6b7d0fabafdb4d14321397545ca9
parent4988790ba81788901a9d0d907c2b09dff8e2fe16 (diff)
downloadorg.eclipse.nebula.widgets.nattable-13d3eefce84e257e4f3e6c84b57e53f354d52320.tar.gz
org.eclipse.nebula.widgets.nattable-13d3eefce84e257e4f3e6c84b57e53f354d52320.tar.xz
org.eclipse.nebula.widgets.nattable-13d3eefce84e257e4f3e6c84b57e53f354d52320.zip
Bug 486475 - Fill action doesn't work correctly for filling cells
horizontally Change-Id: I9ee0700551bc2cdd5120ea8d3145b8ccd9fdfb3b Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java50
1 files changed, 37 insertions, 13 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java
index 06ffc80d..31f9177c 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/fillhandle/action/FillHandleDragMode.java
@@ -135,18 +135,21 @@ public class FillHandleDragMode implements IDragMode {
int xStart = this.startIndex.x;
int yStart = this.startIndex.y;
+ Rectangle region = this.selectionLayer.getLastSelectedRegion();
+
// only increase range in one direction
- int xDiff = selectedColumnIndex - this.startIndex.x;
- if (xDiff < 0) {
- xDiff *= -1;
+ int xDiff = calculateIncreasedPositiveDiff(
+ event.x,
+ (event.x < this.startEvent.x) ? this.selectionCell.getBounds().x : this.startEvent.x);
+ int yDiff = calculateIncreasedPositiveDiff(
+ event.y,
+ (event.y < this.startEvent.y) ? this.selectionCell.getBounds().y : this.startEvent.y);
+ if (selectedColumnIndex >= region.x && selectedColumnIndex < (region.x + region.width)) {
+ xDiff = 0;
}
- xDiff++;
-
- int yDiff = selectedRowIndex - this.startIndex.y;
- if (yDiff < 0) {
- yDiff *= -1;
+ if (selectedRowIndex >= region.y && selectedRowIndex < (region.y + region.height)) {
+ yDiff = 0;
}
- yDiff++;
int width = -1;
int height = -1;
@@ -163,21 +166,23 @@ public class FillHandleDragMode implements IDragMode {
if (direction == FillDirection.VERTICAL
|| (direction == FillDirection.BOTH && yDiff >= xDiff)) {
- height = Math.max(yDiff, this.selectionLayer.getSelectedRowCount());
+ int diff = calculateIncreasedPositiveDiff(selectedRowIndex, this.startIndex.y);
+ height = Math.max(diff, this.selectionLayer.getSelectedRowCount());
width = this.selectionLayer.getSelectedColumnPositions().length;
this.direction = MoveDirectionEnum.DOWN;
if ((selectedRowIndex - this.startIndex.y) < 0) {
yStart = selectedRowIndex;
- height = yDiff + this.selectionLayer.getSelectedRowCount() - 1;
+ height = diff + this.selectionLayer.getSelectedRowCount() - 1;
this.direction = MoveDirectionEnum.UP;
}
} else {
+ int diff = calculateIncreasedPositiveDiff(selectedColumnIndex, this.startIndex.x);
height = this.selectionLayer.getSelectedRowCount();
- width = Math.max(xDiff, this.selectionLayer.getSelectedColumnPositions().length);
+ width = Math.max(diff, this.selectionLayer.getSelectedColumnPositions().length);
this.direction = MoveDirectionEnum.RIGHT;
if ((selectedColumnIndex - this.startIndex.x) < 0) {
xStart = selectedColumnIndex;
- width = xDiff + this.selectionLayer.getSelectedColumnPositions().length - 1;
+ width = diff + this.selectionLayer.getSelectedColumnPositions().length - 1;
this.direction = MoveDirectionEnum.LEFT;
}
}
@@ -194,6 +199,25 @@ public class FillHandleDragMode implements IDragMode {
}
}
+ /**
+ * Calculates the difference between the two given values and increases the
+ * value by one.
+ *
+ * @param selectedIndex
+ * The first value
+ * @param relativeIndex
+ * The second value
+ * @return The difference between the two given values increased by one.
+ */
+ protected int calculateIncreasedPositiveDiff(int selectedIndex, int relativeIndex) {
+ int diff = selectedIndex - relativeIndex;
+ if (diff < 0) {
+ diff *= -1;
+ }
+ diff++;
+ return diff;
+ }
+
@Override
public void mouseUp(final NatTable natTable, MouseEvent event) {
if (natTable.doCommand(

Back to the top