summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2017-01-13 12:37:54 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-01-13 12:37:54 +0200
commit40cb64fbab832279ab13bd853bf1096da92abc39 (patch)
treecf1660013f272fc3252cb4593277f827386a3955 /uitest
parent8fca887996e063470379dcf3b47d6bcff3c9839c (diff)
downloadvaadin-framework-40cb64fbab832279ab13bd853bf1096da92abc39.tar.gz
vaadin-framework-40cb64fbab832279ab13bd853bf1096da92abc39.zip
Add "deselect allowed" feature to the Grid. (#8227)
* Add "deselect allowed" feature to the Grid. Fixes #8149
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/DisallowedDeselection.java51
-rw-r--r--uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java6
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/DisallowedDeselectionTest.java62
3 files changed, 116 insertions, 3 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/DisallowedDeselection.java b/uitest/src/main/java/com/vaadin/tests/components/grid/DisallowedDeselection.java
new file mode 100644
index 0000000000..fc2357c346
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/DisallowedDeselection.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2000-2016 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;
+
+import com.vaadin.data.ValueProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.SelectionMode;
+import com.vaadin.ui.components.grid.GridSelectionModel;
+import com.vaadin.ui.components.grid.SingleSelectionModelImpl;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class DisallowedDeselection extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<String> grid = new Grid<>();
+ grid.addColumn(ValueProvider.identity());
+ grid.setItems("a", "b");
+
+ GridSelectionModel<String> model = grid
+ .setSelectionMode(SelectionMode.SINGLE);
+ SingleSelectionModelImpl<?> singleSelectionModel = (SingleSelectionModelImpl<?>) model;
+ singleSelectionModel.setDeselectAllowed(false);
+ addComponent(grid);
+
+ Button allowDeselection = new Button("Allow deselection",
+ event -> singleSelectionModel.setDeselectAllowed(true));
+
+ addComponent(allowDeselection);
+ }
+
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java
index 78851dd7ef..24f9aff2ad 100644
--- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java
+++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java
@@ -15,7 +15,6 @@
*/
package com.vaadin.tests.widgetset.client.grid;
-import com.vaadin.client.ServerConnector;
import com.vaadin.client.connectors.grid.MultiSelectionModelConnector;
import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.widget.grid.selection.ClickSelectHandler;
@@ -36,9 +35,10 @@ public class MySelectionModelConnector extends MultiSelectionModelConnector {
private ClickSelectHandler<JsonObject> handler;
@Override
- protected void extend(ServerConnector target) {
- handler = new ClickSelectHandler<>(getGrid());
+ protected void initSelectionModel() {
+ super.initSelectionModel();
getGrid().setSelectionModel(new MyMultiSelectionModel());
+ handler = new ClickSelectHandler<>(getGrid());
}
@Override
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/DisallowedDeselectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/DisallowedDeselectionTest.java
new file mode 100644
index 0000000000..85d202d50d
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/DisallowedDeselectionTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2016 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridElement.GridRowElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class DisallowedDeselectionTest extends MultiBrowserTest {
+
+ @Test
+ public void checkDeselection() {
+ openTestURL();
+
+ GridRowElement row = $(GridElement.class).first().getRow(0);
+ Assert.assertFalse(row.isSelected());
+
+ select(row);
+ Assert.assertTrue(row.isSelected());
+
+ // deselection is disallowed
+ select(row);
+ Assert.assertTrue(row.isSelected());
+
+ // select another row
+ GridRowElement oldRow = row;
+ row = $(GridElement.class).first().getRow(1);
+ select(row);
+ Assert.assertTrue(row.isSelected());
+ Assert.assertFalse(oldRow.isSelected());
+
+ $(ButtonElement.class).first().click();
+
+ select(row);
+ Assert.assertFalse(row.isSelected());
+ }
+
+ private void select(GridRowElement row) {
+ row.getCell(0).click();
+ }
+}