Selecting an item in a TreeTable

I try to select an item in a TreeTable (through api - not with my mouse)… I am using Vaadin 6.8.6

The task is to (automatically) select the parent item of the item I click. The UI is not refreshed, although finding the parent of an item and selecting it works.

I used the ItemClickListener in this example… How can find out if the item I clicked is selected or unselected?

Here is the complete code:

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.AbstractSelect.MultiSelectMode;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.TreeTable;
import com.vaadin.ui.VerticalLayout;

public class TreeGui extends CustomComponent {
	private static final long serialVersionUID = -602900588162916989L;
	private VerticalLayout mainLayout;
	private TreeTable treeTable;

	private class Person {
		private String name;
		public Person(String name) { = name;
		public String getName() {
			return name;
		public String toString() {
			return name;

	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	public TreeGui() {
		treeTable.addContainerProperty("Name", String.class, null);
		treeTable.setColumnHeader("Name", "Family");
		treeTable.addContainerProperty("Name", String.class, null);
		Person grandfather = new Person("Grandfather");
		Person father = new Person("Father");
		Person son = new Person("Son");
		Person grandmother = new Person("Grandmother");
		Person mother = new Person("Mother");
		Person daughter = new Person("Daughter");
		treeTable.addItem(new Object [] {grandfather.getName()}, grandfather);
		treeTable.addItem(new Object [] {father.getName()}, father);
		treeTable.addItem(new Object [] {son.getName()}, son);
		treeTable.addItem(new Object [] {grandmother.getName()}, grandmother);
		treeTable.addItem(new Object [] {mother.getName()}, mother);
		treeTable.addItem(new Object [] {daughter.getName()}, daughter);
		treeTable.setParent(son, father);
		treeTable.setParent(father, grandfather);
		treeTable.setParent(daughter, mother);
		treeTable.setParent(mother, grandmother);
		treeTable.setChildrenAllowed(son, false);
		treeTable.setChildrenAllowed(daughter, false);
		treeTable.setCollapsed(grandfather, false);
		treeTable.setCollapsed(father, false);
		treeTable.setCollapsed(grandmother, false);
		treeTable.setCollapsed(mother, false);
		treeTable.addListener(new ItemClickListener() {
			private static final long serialVersionUID = -3820290353547897436L;
			public void itemClick(ItemClickEvent event) {
				if (event.getButton() == ItemClickEvent.BUTTON_LEFT) {
					Person person = (Person)event.getItemId();
					Person parent = (Person)treeTable.getParent(person);
					if (parent != null) {
						System.out.println(parent + " is parent of " + person);;

	private VerticalLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new VerticalLayout();
		// top-level component properties
		// treeTable
		treeTable = new TreeTable();
		return mainLayout;

the getValue() method will return the selected itemId, if any (a Person object in this case). Just check if that matches the provided itemId.

getValue() and getParent() deliver the correct values for the TreeTable and for the parent element.

As a workaround I found out that the setValue() method works when called outside of a treeTable listener. So I created another button (Submit changes) with a listener and called the treetable.setValue(object) method.

After that the TreeTable gui was updated and the corrent value was shown (clicked element plus all parent elements).

The select method method did not work…

If I remember correctly, an ItemClickListener is called before a possible ValueChangeListener and other value change processing.
I wonder if that might lead to some conflict where you set the value before it is reset by the value change mechanism in your use case.