summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2015-08-31 22:51:19 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-09-14 08:12:54 +0000
commit9e99e3e793ab14c3623f810b53471dde3d9f9816 (patch)
tree6cd00611dc83f101b9d46280c8d10ee8ab4dd634
parent47fe6d931ddd550d35ab87d8a38eed4f3e8c7fff (diff)
downloadvaadin-framework-9e99e3e793ab14c3623f810b53471dde3d9f9816.tar.gz
vaadin-framework-9e99e3e793ab14c3623f810b53471dde3d9f9816.zip
Disable sidebar button when grid is disabled. (#18696)
Change-Id: If334cebd85fcfe9b368b1b360181abaadd5cb4ef
-rw-r--r--WebContent/VAADIN/themes/base/grid/grid.scss4
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java21
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java85
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java21
4 files changed, 130 insertions, 1 deletions
diff --git a/WebContent/VAADIN/themes/base/grid/grid.scss b/WebContent/VAADIN/themes/base/grid/grid.scss
index 6b3b017070..a5fb27f7d7 100644
--- a/WebContent/VAADIN/themes/base/grid/grid.scss
+++ b/WebContent/VAADIN/themes/base/grid/grid.scss
@@ -110,6 +110,10 @@ $v-grid-details-border-bottom-stripe: 1px solid darken($v-grid-row-background-co
text-align: right;
line-height: 1;
+ &[disabled] {
+ cursor: default;
+ }
+
&::-moz-focus-inner {
border: 0;
}
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 4d1788639c..449cb60cc7 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -3487,7 +3487,7 @@ public class Grid<T> extends ResizeComposite implements
*
* @since 7.5.0
*/
- private static class Sidebar extends Composite {
+ private static class Sidebar extends Composite implements HasEnabled {
private final ClickHandler openCloseButtonHandler = new ClickHandler() {
@@ -3538,6 +3538,9 @@ public class Grid<T> extends ResizeComposite implements
initWidget(rootContainer);
openCloseButton = new Button();
+
+ setEnabled(grid.isEnabled());
+
openCloseButton.addClickHandler(openCloseButtonHandler);
rootContainer.add(openCloseButton);
@@ -3719,6 +3722,20 @@ public class Grid<T> extends ResizeComposite implements
}
});
}
+
+ @Override
+ public boolean isEnabled() {
+ return openCloseButton.isEnabled();
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ if(!enabled && isOpen()) {
+ close();
+ }
+
+ openCloseButton.setEnabled(enabled);
+ }
}
/**
@@ -5625,6 +5642,8 @@ public class Grid<T> extends ResizeComposite implements
editor.setGridEnabled(enabled);
}
+ sidebar.setEnabled(enabled);
+
getEscalator().setScrollLocked(Direction.VERTICAL,
!enabled || editorOpen);
getEscalator().setScrollLocked(Direction.HORIZONTAL, !enabled);
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java
new file mode 100644
index 0000000000..0f207b68f2
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java
@@ -0,0 +1,85 @@
+package com.vaadin.tests.components.grid;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
+
+public class GridDisabledSideBarTest extends GridBasicClientFeaturesTest {
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+
+ openTestURL();
+ }
+
+ private void makeColumnHidable() {
+ selectMenuPath("Component", "Columns", "Column 0", "Hidable");
+ }
+
+ private void toggleSideBarMenuAndDisable() {
+ selectMenuPath("Component", "Sidebar", "Open sidebar and disable grid");
+ waitUntil(new ExpectedCondition<Boolean>() {
+
+ @Override
+ public Boolean apply(WebDriver input) {
+ return !findElement(By.className("v-grid-sidebar-button")).isEnabled();
+ }
+ });
+ }
+ private void clickSideBarButton() {
+ findElement(By.cssSelector(".v-grid-sidebar-button")).click();
+ }
+
+ private void toggleEnabled() {
+ selectMenuPath("Component", "State", "Enabled");
+ }
+
+ private void assertSideBarContainsClass(String cssClass) {
+ assertThat(findElement(By.cssSelector(".v-grid-sidebar")).getAttribute("class"), containsString(cssClass));
+ }
+
+ @Test
+ public void sidebarButtonIsDisabledOnCreation() {
+ selectMenuPath("Component", "State", "Enabled");
+ makeColumnHidable();
+
+ clickSideBarButton();
+
+ assertSideBarContainsClass("closed");
+ }
+
+ @Test
+ public void sidebarButtonCanBeEnabled() {
+ makeColumnHidable();
+
+ clickSideBarButton();
+
+ assertSideBarContainsClass("open");
+ }
+
+ @Test
+ public void sidebarButtonCanBeDisabled() {
+ makeColumnHidable();
+ toggleEnabled();
+
+ clickSideBarButton();
+
+ assertSideBarContainsClass("closed");
+ }
+
+ @Test
+ public void sidebarIsClosedOnDisable() {
+ makeColumnHidable();
+
+ toggleSideBarMenuAndDisable();
+
+ assertSideBarContainsClass("closed");
+ }
+} \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
index aa1d7d60a4..b6386afe44 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;
+import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
@@ -1593,6 +1594,26 @@ public class GridBasicClientFeaturesWidget extends
grid.setSidebarOpen(!grid.isSidebarOpen());
}
}, menupath);
+
+ addMenuCommand("Open sidebar and disable grid", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setSidebarOpen(true);
+
+ Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
+ @Override
+ public boolean execute() {
+ if(grid.isSidebarOpen()) {
+ grid.setEnabled(false);
+
+ return false;
+ }
+
+ return true;
+ }
+ }, 250);
+ }
+ }, menupath);
}
private MenuItem createSidebarMenuItem(final int index) {