From 0645a86e5b6951de0e5b170657a2eaf74a7e9b77 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Tue, 19 May 2020 13:13:25 +0300 Subject: Table / TreeTable multiselect disabling of touch detection (#12014) Added a toggle in Table (and thus TreeTable) where you can explicitly disable multiselect touch screen detection. This allows you to work around issues on hybrid devices that have both a touch screen and a keyboard where you don't want automatic simple multiselection applied. Fixes #11601, slightly modified cherry-pick of #11641 --- .../src/main/java/com/vaadin/v7/ui/Table.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'compatibility-server/src/main/java/com/vaadin/v7') diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java index 433254aa67..0519e20f75 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java @@ -588,6 +588,8 @@ public class Table extends AbstractSelect implements Action.Container, private MultiSelectMode multiSelectMode = MultiSelectMode.DEFAULT; + private boolean multiSelectTouchDetectionEnabled = true; + private boolean rowCacheInvalidated; private RowGenerator rowGenerator = null; @@ -3775,6 +3777,10 @@ public class Table extends AbstractSelect implements Action.Container, if (isSelectable()) { target.addAttribute("selectmode", (isMultiSelect() ? "multi" : "single")); + if (isMultiSelect()) { + target.addAttribute("touchdetection", + isMultiSelectTouchDetectionEnabled()); + } } else { target.addAttribute("selectmode", "none"); } @@ -5188,7 +5194,10 @@ public class Table extends AbstractSelect implements Action.Container, *

* Note, that on some clients the mode may not be respected. E.g. on touch * based devices CTRL/SHIFT base selection method is invalid, so touch based - * browsers always use the {@link MultiSelectMode#SIMPLE}. + * browsers always use the {@link MultiSelectMode#SIMPLE} unless touch multi + * select is explicitly disabled. + * + * @see #setMultiSelectTouchDetectionEnabled(boolean) * * @param mode * The select mode of the table @@ -5207,6 +5216,31 @@ public class Table extends AbstractSelect implements Action.Container, return multiSelectMode; } + /** + * Default behavior on touch-reporting devices is to switch from CTRL/SHIFT + * based multi-selection to simple mode, but you can use this method to + * explicitly disable the touch device detection. Thus you can keep using + * keyboard-based multi selection on hybrid devices that have both a touch + * screen and a keyboard. + * + * @param multiSelectTouchDetectionEnabled + * Whether to enable or disable touch screen detection + */ + public void setMultiSelectTouchDetectionEnabled( + boolean multiSelectTouchDetectionEnabled) { + this.multiSelectTouchDetectionEnabled = multiSelectTouchDetectionEnabled; + markAsDirty(); + } + + /** + * Returns if touch screen detection is used to toggle multi select mode. + * + * @return If touch screen detection for multi select is enabled + */ + public boolean isMultiSelectTouchDetectionEnabled() { + return multiSelectTouchDetectionEnabled; + } + /** * Lazy loading accept criterion for Table. Accepted target rows are loaded * from server once per drag and drop operation. Developer must override one -- cgit v1.2.3