aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/Grid.java25
-rw-r--r--shared/src/com/vaadin/shared/ui/grid/GridState.java4
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java8
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java116
4 files changed, 153 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 2bc42676c3..764960606a 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -3469,6 +3469,31 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
return columnKeys.get(columnId);
}
+ /**
+ * Returns whether column reordering is allowed. Default value is
+ * <code>false</code>.
+ *
+ * @since
+ * @return true if reordering is allowed
+ */
+ public boolean isColumnReorderingAllowed() {
+ return getState(false).columnReorderingAllowed;
+ }
+
+ /**
+ * Sets whether or not column reordering is allowed. Default value is
+ * <code>false</code>.
+ *
+ * @since
+ * @param columnReorderingAllowed
+ * specifies whether column reordering is allowed
+ */
+ public void setColumnReorderingAllowed(boolean columnReorderingAllowed) {
+ if (isColumnReorderingAllowed() != columnReorderingAllowed) {
+ getState().columnReorderingAllowed = columnReorderingAllowed;
+ }
+ }
+
@Override
protected GridState getState() {
return (GridState) super.getState();
diff --git a/shared/src/com/vaadin/shared/ui/grid/GridState.java b/shared/src/com/vaadin/shared/ui/grid/GridState.java
index 7018df1413..ab42a52424 100644
--- a/shared/src/com/vaadin/shared/ui/grid/GridState.java
+++ b/shared/src/com/vaadin/shared/ui/grid/GridState.java
@@ -156,4 +156,8 @@ public class GridState extends AbstractComponentState {
/** The caption for the cancel button in the editor */
@DelegateToWidget
public String editorCancelCaption = GridConstants.DEFAULT_CANCEL_CAPTION;
+
+ /** Whether the columns can be reordered */
+ @DelegateToWidget
+ public boolean columnReorderingAllowed;
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
index e5a46894b8..3a6aca11f2 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -508,6 +508,14 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}
});
+ createBooleanAction("Column Reordering Allowed", "State", false,
+ new Command<Grid, Boolean>() {
+
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ c.setColumnReorderingAllowed(value);
+ }
+ });
}
protected void createHeaderActions() {
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
new file mode 100644
index 0000000000..7b62ff85f9
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+/**
+ * Tests that Grid columns can be reordered by user with drag and drop #16643.
+ *
+ * @author Vaadin Ltd
+ */
+public class GridColumnReorderTest extends GridBasicFeaturesTest {
+
+ private static final String[] COLUMN_REORDERING_PATH = { "Component",
+ "State", "Column Reordering Allowed" };
+
+ @Before
+ public void setUp() {
+ setDebug(true);
+ }
+
+ @Test
+ public void testColumnReordering_firstColumnDroppedOnThird_dropOnLeftSide() {
+ // given
+ openTestURL();
+ assertColumnHeaderOrder(0, 1, 2);
+ toggleColumnReordering();
+
+ // when
+ dragDefaultColumnHeader(0, 2, 10);
+
+ // then
+ assertColumnHeaderOrder(1, 0, 2);
+ }
+
+ @Test
+ public void testColumnReordering_firstColumnDroppedOnThird_dropOnRightSide() {
+ // given
+ openTestURL();
+ assertColumnHeaderOrder(0, 1, 2);
+ toggleColumnReordering();
+
+ // when
+ dragDefaultColumnHeader(0, 2, 110);
+
+ // then
+ assertColumnHeaderOrder(1, 2, 0);
+ }
+
+ @Test
+ public void testColumnReordering_notEnabled_noReordering() {
+ // given
+ openTestURL();
+ assertColumnHeaderOrder(0, 1, 2);
+
+ // when
+ dragDefaultColumnHeader(0, 2, 110);
+
+ // then
+ assertColumnHeaderOrder(0, 1, 2);
+ }
+
+ private void toggleColumnReordering() {
+ selectMenuPath(COLUMN_REORDERING_PATH);
+ }
+
+ private void assertColumnHeaderOrder(int... indices) {
+ List<TestBenchElement> headers = getGridHeaderRowCells();
+ for (int i = 0; i < indices.length; i++) {
+ assertColumnHeader("Column " + indices[i], headers.get(i));
+ }
+ }
+
+ private void assertColumnHeader(String expectedHeaderCaption,
+ TestBenchElement testBenchElement) {
+ assertEquals(expectedHeaderCaption.toLowerCase(), testBenchElement
+ .getText().toLowerCase());
+ }
+
+ private WebElement getDefaultColumnHeader(int index) {
+ List<TestBenchElement> headerRowCells = getGridHeaderRowCells();
+ return headerRowCells.get(index);
+ }
+
+ private void dragDefaultColumnHeader(int draggedColumnHeaderIndex,
+ int onTopOfColumnHeaderIndex, int xOffsetFromColumnTopLeftCorner) {
+ new Actions(getDriver())
+ .clickAndHold(getDefaultColumnHeader(draggedColumnHeaderIndex))
+ .moveToElement(
+ getDefaultColumnHeader(onTopOfColumnHeaderIndex),
+ xOffsetFromColumnTopLeftCorner, 0).release().perform();
+ }
+}