Select all itens on a Table

How can I implement a button to select or unselect all itens on a Mult Select Table?

Valder

Hi,

You can addListener to the button. And in the buttonClick method, you can retrieve all the itemIds from the table; then put them into a set; finally set it to table.setValue(set).

To unselect the values, just do the following: table.setValue(null);

Button button = new Button(“Test”);

public void buildPanel(){
this.addComponent(button);
button.addListener(this);
}

public void buttonClick (Button.ClickEvent event) {
HashSet set = new HashSet();
Iterator iterator = table.getItemIds().iterator();
while (iterator.hasNext()) {
Message msg = (Message) iterator.next();
set.add(msg);
}
table.setValue(set);
}


button.addListener(new ClickListener()
{
	@Override
	public void buttonClick(ClickEvent event)
	{
		Collection<?> vals = (Collection<?>) table.getValue();
		if(vals.isEmpty())
		{
			table.setValue(table.getItemIds());
		}
		else table.setValue(null);
	}
});