From ef4c8b257ce6a3f39f0db6d8e4d7dc5b76c579ef Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Mon, 20 Jul 2009 10:27:12 +0000 Subject: [PATCH] #3146 could not clear table selection and related test case svn changeset:8404/svn branch:6.0 --- src/com/vaadin/tests/tickets/Ticket3146.java | 96 ++++++++++++++++++++ src/com/vaadin/ui/Table.java | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/com/vaadin/tests/tickets/Ticket3146.java diff --git a/src/com/vaadin/tests/tickets/Ticket3146.java b/src/com/vaadin/tests/tickets/Ticket3146.java new file mode 100644 index 0000000000..53600b9299 --- /dev/null +++ b/src/com/vaadin/tests/tickets/Ticket3146.java @@ -0,0 +1,96 @@ +package com.vaadin.tests.tickets; + +import java.util.Collection; +import java.util.HashSet; + +import com.vaadin.Application; +import com.vaadin.ui.Button; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.Window; +import com.vaadin.ui.Button.ClickEvent; + +public class Ticket3146 extends Application { + + Table table; + TextField result; + + @Override + public void init() { + Window mainWindow = new Window("Test"); + + table = new Table(); + table.addContainerProperty("Items", String.class, null); + table.addItem(new String[] { "a" }, "a"); + table.addItem(new String[] { "b" }, "b"); + table.addItem(new String[] { "c" }, "c"); + for (int i = 1; i < 100; ++i) { + table.addItem(new String[] { "Item " + i }, "Item " + i); + } + table.setMultiSelect(true); + table.setSelectable(true); + table.setImmediate(true); + table.setHeight("200px"); + table.setWidth("200px"); + mainWindow.addComponent(table); + + Button clearButton = new Button("Clear selection", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + clearSelection(); + } + }); + mainWindow.addComponent(clearButton); + Button clearButton2 = new Button("Clear selection 2", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + clearSelection2(); + } + }); + mainWindow.addComponent(clearButton2); + Button clearButton3 = new Button("Clear selection 3", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + clearSelection3(); + } + }); + mainWindow.addComponent(clearButton3); + Button printButton = new Button("Print selection", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + printSelection(); + } + }); + mainWindow.addComponent(printButton); + + result = new TextField(); + result.setHeight("200px"); + result.setWidth("200px"); + mainWindow.addComponent(result); + + setMainWindow(mainWindow); + } + + void clearSelection() { + table.setValue(null); + } + + void clearSelection2() { + table.setValue(new HashSet()); + } + + void clearSelection3() { + table.unselect("a"); + table.unselect("b"); + table.unselect("c"); + } + + void printSelection() { + String selection = ""; + for (Object item : (Collection) table.getValue()) { + selection = selection + item + ' '; + } + result.setValue(selection); + } + +} diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index c3d0e66809..215bfedee3 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -2184,7 +2184,7 @@ public class Table extends AbstractSelect implements Action.Container, target.endTag("rows"); // The select variable is only enabled if selectable - if (selectable && selectedKeys.size() > 0) { + if (selectable) { target.addVariable(this, "selected", selectedKeys .toArray(new String[selectedKeys.size()])); } -- 2.39.5