]> source.dussan.org Git - vaadin-framework.git/commitdiff
Null selection changes (#574)
authorMarc Englund <marc.englund@itmill.com>
Fri, 2 Nov 2007 14:13:07 +0000 (14:13 +0000)
committerMarc Englund <marc.englund@itmill.com>
Fri, 2 Nov 2007 14:13:07 +0000 (14:13 +0000)
svn changeset:2694/svn branch:trunk

src/com/itmill/toolkit/ui/AbstractSelect.java
src/com/itmill/toolkit/ui/Table.java
src/com/itmill/toolkit/ui/Tree.java

index 939cdd248de1e181a0a0ffa148ed797825629cf9..aa928548d7a8705400ebc5e26433c47ebfe3f49e 100644 (file)
@@ -407,7 +407,11 @@ public abstract class AbstractSelect extends AbstractField implements
                                LinkedList s = new LinkedList();
                                for (int i = 0; i < ka.length; i++) {
                                        Object id = this.itemIdMapper.get(ka[i]);
-                                       if (id != null && containsId(id)) {
+                                       if (!isNullSelectionAllowed()
+                                                       && (id == null || id == getNullSelectionItemId())) {
+                                               // skip empty selection if nullselection is not allowed
+                                               requestRepaint();
+                                       } else if (id != null && containsId(id)) {
                                                s.add(id);
                                        } else if (this.itemIdMapper.isNewIdKey(ka[i])
                                                        && newitem != null && newitem.length() > 0) {
@@ -415,6 +419,12 @@ public abstract class AbstractSelect extends AbstractField implements
                                        }
                                }
 
+                               if (!isNullSelectionAllowed() && s.size() < 1) {
+                                       // empty selection not allowed, keep old value
+                                       requestRepaint();
+                                       return;
+                               }
+
                                // Limits the deselection to the set of visible items
                                // (non-visible items can not be deselected)
                                Collection visible = getVisibleItemIds();
@@ -431,8 +441,14 @@ public abstract class AbstractSelect extends AbstractField implements
                                }
                        } else {
                                // Single select mode
+                               if (!isNullSelectionAllowed()
+                                               && (ka.length == 0 || ka[0] == null || ka[0] == getNullSelectionItemId())) {
+                                       requestRepaint();
+                                       return;
+                               }
                                if (ka.length == 0) {
-                                       // Allows deselection only if the deselected item is visible
+                                       // Allows deselection only if the deselected item is
+                                       // visible
                                        Object current = getValue();
                                        Collection visible = getVisibleItemIds();
                                        if (visible != null && visible.contains(current)) {
@@ -440,7 +456,10 @@ public abstract class AbstractSelect extends AbstractField implements
                                        }
                                } else {
                                        Object id = this.itemIdMapper.get(ka[0]);
-                                       if (id != null && id.equals(getNullSelectionItemId())) {
+                                       if (!isNullSelectionAllowed() && id == null) {
+                                               requestRepaint();
+                                       } else if (id != null
+                                                       && id.equals(getNullSelectionItemId())) {
                                                setValue(null, true);
                                        } else if (this.itemIdMapper.isNewIdKey(ka[0])) {
                                                setValue(newitem);
index 6d5a699116f88f26fccef18a2f739a5378c9ae83..5a9762db9e1a10c52fc04032e3bbe6d31e153b50 100644 (file)
@@ -1322,6 +1322,13 @@ public class Table extends AbstractSelect implements Action.Container,
         */
        public void changeVariables(Object source, Map variables) {
 
+               if (!isSelectable() && variables.containsKey("selected")) {
+                       // Not-selectable is a special case, AbstractSelect does not support
+                       // TODO could be optimized.
+                       variables = new HashMap(variables);
+                       variables.remove("selected");
+               }
+
                super.changeVariables(source, variables);
 
                // Page start index
@@ -1522,9 +1529,16 @@ public class Table extends AbstractSelect implements Action.Container,
                }
                target.startTag("rows");
                for (int i = 0; i < cells[0].length; i++) {
-                       target.startTag("tr");
                        Object itemId = cells[CELL_ITEMID][i];
 
+                       if (!isNullSelectionAllowed() && getNullSelectionItemId() != null
+                                       && itemId == getNullSelectionItemId()) {
+                               // Remove null selection item if null selection is not allowed
+                               continue;
+                       }
+
+                       target.startTag("tr");
+
                        // tr attributes
                        if (rowheads) {
                                if (cells[CELL_ICON][i] != null) {
index 0aaa22a3c7ec333f4444171298ca45395db8958c..3c5552c256a7e28cad2066eaa8941df5d25d92df 100644 (file)
@@ -31,6 +31,7 @@ package com.itmill.toolkit.ui;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -336,6 +337,13 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         */
        public void changeVariables(Object source, Map variables) {
 
+               if (!isSelectable() && variables.containsKey("selected")) {
+                       // Not-selectable is a special case, AbstractSelect does not support
+                       // TODO could be optimized.
+                       variables = new HashMap(variables);
+                       variables.remove("selected");
+               }
+
                // Collapses the nodes
                if (variables.containsKey("collapse")) {
                        String[] keys = (String[]) variables.get("collapse");