diff options
author | John Alhroos <john.ahlroos@itmill.com> | 2010-05-06 13:32:45 +0000 |
---|---|---|
committer | John Alhroos <john.ahlroos@itmill.com> | 2010-05-06 13:32:45 +0000 |
commit | 57e9ad50450a4ed3c9661d123f38cc6c4c4fb7ed (patch) | |
tree | 94780b39e2bf46afaf3ad209b5f36c2d1e39dd0c /src/com/vaadin/ui | |
parent | e206775cb4c2b963ec91c4e05f218935276a884c (diff) | |
download | vaadin-framework-57e9ad50450a4ed3c9661d123f38cc6c4c4fb7ed.tar.gz vaadin-framework-57e9ad50450a4ed3c9661d123f38cc6c4c4fb7ed.zip |
- Added Ctrl+Shift multiple selection to Tree
- Moved MultiSelectMode enum to AbstractSelect
- Added test application for Tree ctrl+Shift selection
- Added keyboard navigation sample to the Sampler feature set
svn changeset:13070/svn branch:6.4
Diffstat (limited to 'src/com/vaadin/ui')
-rw-r--r-- | src/com/vaadin/ui/AbstractSelect.java | 15 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 16 | ||||
-rw-r--r-- | src/com/vaadin/ui/Tree.java | 71 |
3 files changed, 85 insertions, 17 deletions
diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java index 9667de32d6..a8451e7ef6 100644 --- a/src/com/vaadin/ui/AbstractSelect.java +++ b/src/com/vaadin/ui/AbstractSelect.java @@ -127,6 +127,21 @@ public abstract class AbstractSelect extends AbstractField implements } /** + * Multi select modes that controls how multi select behaves. + */ + public enum MultiSelectMode { + /** + * The default behavior of the multi select mode + */ + DEFAULT, + + /** + * The previous more simple behavior of the multselect + */ + SIMPLE + } + + /** * Is the select in multiselect mode? */ private boolean multiSelect = false; diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 9322447bf9..4fde62d4bd 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -94,22 +94,6 @@ public class Table extends AbstractSelect implements Action.Container, MULTIROW } - /** - * Multi select modes that controls how multi select behaves. - */ - public enum MultiSelectMode { - /** - * Simple left clicks only selects one item, CTRL+left click selects - * multiple items and SHIFT-left click selects a range of items. - */ - DEFAULT, - /** - * Uses the old method of selection. CTRL- and SHIFT-clicks are disabled and - * clicking on the items selects/deselects them. - */ - SIMPLE - } - private static final int CELL_KEY = 0; private static final int CELL_HEADER = 1; diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 2b38d5a6eb..11b049d803 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -119,7 +119,9 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } private TreeDragMode dragMode = TreeDragMode.NONE; - + + private MultiSelectMode multiSelectMode = MultiSelectMode.DEFAULT; + /* Tree constructors */ /** @@ -338,6 +340,29 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, requestRepaint(); } } + + /** + * Sets the behavior of the multiselect mode + * + * @param mode + * The mode to set + */ + public void setMultiselectMode(MultiSelectMode mode) { + if (multiSelectMode != mode && mode != null) { + multiSelectMode = mode; + requestRepaint(); + } + } + + /** + * Returns the mode the multiselect is in. The mode controls how + * multiselection can be done. + * + * @return The mode + */ + public MultiSelectMode getMultiselectMode() { + return multiSelectMode; + } /* Component API */ @@ -396,6 +421,15 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } } + // AbstractSelect cannot handle multiselection so we handle + // it ourself + if (variables.containsKey("selected") && isMultiSelect() + && multiSelectMode == MultiSelectMode.DEFAULT) { + handleSelectedItems(variables); + variables = new HashMap<String, Object>(variables); + variables.remove("selected"); + } + // Selections are handled by the select component super.changeVariables(source, variables); @@ -419,6 +453,37 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } /** + * Handles the selection + * + * @param variables + * The variables sent to the server from the client + */ + private void handleSelectedItems(Map<String, Object> variables) { + final String[] ka = (String[]) variables.get("selected"); + + // Converts the key-array to id-set + final LinkedList s = new LinkedList(); + for (int i = 0; i < ka.length; i++) { + final Object id = itemIdMapper.get(ka[i]); + if (!isNullSelectionAllowed() + && (id == null || id == getNullSelectionItemId())) { + // skip empty selection if nullselection is not allowed + requestRepaint(); + } else if (id != null && containsId(id)) { + s.add(id); + } + } + + if (!isNullSelectionAllowed() && s.size() < 1) { + // empty selection not allowed, keep old value + requestRepaint(); + return; + } + + setValue(s, true); + } + + /** * Paints any needed component-specific things to the given UIDL stream. * * @see com.vaadin.ui.AbstractComponent#paintContent(PaintTarget) @@ -442,6 +507,10 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, if (isSelectable()) { target.addAttribute("selectmode", (isMultiSelect() ? "multi" : "single")); + if (isMultiSelect()) { + target.addAttribute("multiselectmode", multiSelectMode + .ordinal()); + } } else { target.addAttribute("selectmode", "none"); } |