aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2015-02-25 16:16:10 +0200
committerPekka Hyvönen <pekka@vaadin.com>2015-02-25 16:31:28 +0200
commitb90e4d307c286a56a38fc3cc2ec2dd73017e9458 (patch)
tree6a95fbc8d369b4093e7465235d9c483db2bab8be
parentc2fdfcab42f663e46d8f5bff84aa7ca90f7a531e (diff)
downloadvaadin-framework-b90e4d307c286a56a38fc3cc2ec2dd73017e9458.tar.gz
vaadin-framework-b90e4d307c286a56a38fc3cc2ec2dd73017e9458.zip
Column reordering in Grid restricted to non-frozen columns. (#16643)
Can't drag frozen columns. Dragging no top of frozen column will keep drag element and drop marker on "right". Dropping on frozen column will drop the column to the right of the frozen columns. Change-Id: Ib04af96b21072e9f19dc7640a67bc68d49a9ae54
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java23
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java7
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java10
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java52
4 files changed, 74 insertions, 18 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 1d3f090a62..fc208843e4 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -2961,7 +2961,16 @@ public class Grid<T> extends ResizeComposite implements
}
}
dropMarkerLeft += autoScrollX;
- if (dropMarkerLeft > header.getElement().getOffsetWidth()
+
+ final double frozenColumnsWidth = getFrozenColumnsWidth();
+ if (dropMarkerLeft < frozenColumnsWidth) {
+ latestColumnDropIndex = getFrozenColumnCount();
+ if (getScrollLeft() == 0) {
+ dropMarkerLeft = frozenColumnsWidth;
+ } else {
+ dropMarkerLeft = -10000000;
+ }
+ } else if (dropMarkerLeft > header.getElement().getOffsetWidth()
|| dropMarkerLeft < 0) {
dropMarkerLeft = -10000000;
}
@@ -2971,6 +2980,11 @@ public class Grid<T> extends ResizeComposite implements
private void resolveDragElementHorizontalPosition(final int clientX) {
int left = clientX - table.getAbsoluteLeft();
left = Math.max(0, Math.min(left, table.getClientWidth()));
+ final double frozenColumnsWidth = getFrozenColumnsWidth();
+ if (left < frozenColumnsWidth) {
+ left = (int) frozenColumnsWidth;
+ }
+
left -= dragElement.getClientWidth() / 2;
dragElement.getStyle().setLeft(left, Unit.PX);
}
@@ -3071,6 +3085,13 @@ public class Grid<T> extends ResizeComposite implements
autoScroller.stop();
}
+ private double getFrozenColumnsWidth() {
+ double result = 0.0d;
+ for (int i = 0; i < getFrozenColumnCount(); i++) {
+ result += getColumn(i).getWidthActual();
+ }
+ return result;
+ }
};
/**
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
index e7fbc14d89..d387bbe22f 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
@@ -140,6 +140,11 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest {
getGridElement().getCell(row, column).click();
}
+ protected void setFrozenColumns(int numberOfFrozenColumns) {
+ selectMenuPath("Component", "State", "Frozen column count",
+ Integer.toString(numberOfFrozenColumns));
+ }
+
protected void assertColumnHeaderOrder(int... indices) {
List<TestBenchElement> headers = getGridHeaderRowCells();
for (int i = 0; i < indices.length; i++) {
@@ -158,7 +163,7 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest {
return headerRowCells.get(index);
}
- protected void dragDefaultColumnHeader(int draggedColumnHeaderIndex,
+ protected void dragAndDropDefaultColumnHeader(int draggedColumnHeaderIndex,
int onTopOfColumnHeaderIndex, int xOffsetFromColumnTopLeftCorner) {
new Actions(getDriver())
.clickAndHold(getDefaultColumnHeader(draggedColumnHeaderIndex))
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java
index 9f43c39b1e..ac267dc42e 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java
@@ -131,7 +131,7 @@ public class GridColumnReorderTest extends GridBasicClientFeaturesTest {
sortColumn(0);
// when
- dragDefaultColumnHeader(0, 2, 10);
+ dragAndDropDefaultColumnHeader(0, 2, 10);
// then
assertColumnIsSorted(1);
@@ -158,7 +158,7 @@ public class GridColumnReorderTest extends GridBasicClientFeaturesTest {
focusDefaultHeader(0);
// when
- dragDefaultColumnHeader(0, 3, 10);
+ dragAndDropDefaultColumnHeader(0, 3, 10);
// then
WebElement defaultColumnHeader = getDefaultColumnHeader(2);
@@ -173,7 +173,7 @@ public class GridColumnReorderTest extends GridBasicClientFeaturesTest {
focusCell(2, 2);
// when
- dragDefaultColumnHeader(2, 0, 10);
+ dragAndDropDefaultColumnHeader(2, 0, 10);
// then
assertFocusedCell(2, 0);
@@ -186,7 +186,7 @@ public class GridColumnReorderTest extends GridBasicClientFeaturesTest {
focusCell(1, 3);
// when
- dragDefaultColumnHeader(4, 1, 10);
+ dragAndDropDefaultColumnHeader(4, 1, 10);
// then
assertFocusedCell(1, 4);
@@ -199,7 +199,7 @@ public class GridColumnReorderTest extends GridBasicClientFeaturesTest {
focusCell(4, 2);
// when
- dragDefaultColumnHeader(0, 4, 10);
+ dragAndDropDefaultColumnHeader(0, 4, 10);
// then
assertFocusedCell(4, 1);
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java
index 2cc8610209..7ab66aad95 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java
@@ -48,7 +48,7 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
toggleColumnReordering();
// when
- dragDefaultColumnHeader(0, 2, 10);
+ dragAndDropDefaultColumnHeader(0, 2, 10);
// then
assertColumnHeaderOrder(1, 0, 2);
@@ -62,7 +62,7 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
toggleColumnReordering();
// when
- dragDefaultColumnHeader(0, 2, 110);
+ dragAndDropDefaultColumnHeader(0, 2, 110);
// then
assertColumnHeaderOrder(1, 2, 0);
@@ -76,13 +76,13 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
toggleColumnReordering();
// when
- dragDefaultColumnHeader(2, 0, 10);
+ dragAndDropDefaultColumnHeader(2, 0, 10);
// then
assertColumnHeaderOrder(2, 0, 1, 3);
// when
- dragDefaultColumnHeader(1, 3, 110);
+ dragAndDropDefaultColumnHeader(1, 3, 110);
// then
assertColumnHeaderOrder(2, 1, 3, 0);
@@ -95,7 +95,7 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
assertColumnHeaderOrder(0, 1, 2);
// when
- dragDefaultColumnHeader(0, 2, 110);
+ dragAndDropDefaultColumnHeader(0, 2, 110);
// then
assertColumnHeaderOrder(0, 1, 2);
@@ -109,7 +109,7 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
toggleColumnReordering();
// when
- dragDefaultColumnHeader(0, 2, 10);
+ dragAndDropDefaultColumnHeader(0, 2, 10);
assertColumnHeaderOrder(1, 0, 2);
moveColumnManuallyLeftByOne(0);
@@ -127,7 +127,7 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
// when
selectMenuPath(new String[] { "Component", "Internals",
"Update column order without updating client" });
- dragDefaultColumnHeader(2, 0, 10);
+ dragAndDropDefaultColumnHeader(2, 0, 10);
// then
assertColumnHeaderOrder(1, 0, 2);
@@ -141,7 +141,7 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
// when
toggleColumnReorderListener();
- dragDefaultColumnHeader(0, 2, 10);
+ dragAndDropDefaultColumnHeader(0, 2, 10);
// then
assertColumnReorderEvent(true);
@@ -152,19 +152,19 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
// given
openTestURL();
toggleColumnReordering();
- dragDefaultColumnHeader(0, 2, 10);
+ dragAndDropDefaultColumnHeader(0, 2, 10);
assertNoColumnReorderEvent();
// when
toggleColumnReorderListener();
- dragDefaultColumnHeader(0, 2, 110);
+ dragAndDropDefaultColumnHeader(0, 2, 110);
// then
assertColumnReorderEvent(true);
// when
toggleColumnReorderListener();
- dragDefaultColumnHeader(0, 3, 10);
+ dragAndDropDefaultColumnHeader(0, 3, 10);
// then
assertNoColumnReorderEvent();
@@ -182,6 +182,36 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest {
assertColumnReorderEvent(false);
}
+ @Test
+ public void testColumnReorder_draggingFrozenColumns_impossible() {
+ // given
+ openTestURL();
+ toggleColumnReordering();
+ setFrozenColumns(2);
+ assertColumnHeaderOrder(0, 1, 2, 3);
+
+ // when
+ dragAndDropDefaultColumnHeader(0, 2, 10);
+
+ // then
+ assertColumnHeaderOrder(0, 1, 2, 3);
+ }
+
+ @Test
+ public void testColumnReorder_draggingColumnOnTopOfFrozenColumn_columnDroppedRightOfFrozenColumns() {
+ // given
+ openTestURL();
+ toggleColumnReordering();
+ setFrozenColumns(1);
+ assertColumnHeaderOrder(0, 1, 2, 3);
+
+ // when
+ dragAndDropDefaultColumnHeader(2, 0, 10);
+
+ // then
+ assertColumnHeaderOrder(0, 2, 1, 3);
+ }
+
private void toggleColumnReordering() {
selectMenuPath(COLUMN_REORDERING_PATH);
}