Hierarchical Container and TreeTable

Hi all,
i seem to don’t get the Hierarchical Container:
I’m trying to implement a simple one just for testing the basics and…it doesn’t work.

Here’s my code:
The container, implementing Container, Collapsible, Container.Indexed

public class TestHContainer implements Container, Collapsible, Container.Indexed {

	private List<SimpleItem> items;
	
	public TestHContainer() {
		this.items = new LinkedList<SimpleItem>();
		
		for(int i = 0; i < 55; i++){
			items.add(new SimpleItem(i));
		}
	}
	
	@Override
	public Collection<?> getChildren(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		if((index % 10) == 0){
			LinkedList<SimpleItem> list = new LinkedList<SimpleItem>();
			for(int i = 1; i < 10; i++){
				list.add(items.get(index + i));
			}
			System.out.println("getChildren("+itemId+").size="+list.size());
			return list;
		}else{
			System.out.println("getChildren("+itemId+")= not root");
			return new LinkedList<SimpleItem>();
		}
	}

	@Override
	public Object getParent(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		index = index - (index % 10);
		System.out.println("getParent("+itemId+")="+items.get(index));
		return items.get(index);
	}

	@Override
	public Collection<?> rootItemIds() {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean setParent(Object itemId, Object newParentId)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean areChildrenAllowed(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		return (index % 10) == 0;
	}

	@Override
	public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean isRoot(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		
		return (index % 10) == 0;
	}

	@Override
	public boolean hasChildren(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		System.out.println("hasChildren("+itemId+")="+((index % 10) == 0));
		return (index % 10) == 0;
	}

	@Override
	public Object nextItemId(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		return items.get( index +1);
	}

	@Override
	public Object prevItemId(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		return items.get( index -1);
	}

	@Override
	public Object firstItemId() {
		return items.get(0);
	}

	@Override
	public Object lastItemId() {
		return items.get(items.size()-1);
	}

	@Override
	public boolean isFirstId(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		return index == 0;
	}

	@Override
	public boolean isLastId(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		return index == items.size()-1;
	}

	@Override
	public Object addItemAfter(Object previousItemId)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public Item addItemAfter(Object previousItemId, Object newItemId)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public int indexOfId(Object itemId) {
		assert itemId instanceof SimpleItem;
		
		Integer index = ((SimpleItem)itemId).getIndex();
		assert index != null;
		return index;
	}

	@Override
	public Object getIdByIndex(int index) {
		return items.get(index);
	}

	@Override
	public Object addItemAt(int index) throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public Item addItemAt(int index, Object newItemId)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setCollapsed(Object itemId, boolean collapsed) {
		assert itemId instanceof SimpleItem;
		((SimpleItem)itemId).setCollapsed(collapsed);
	}

	@Override
	public boolean isCollapsed(Object itemId) {		
		assert itemId instanceof SimpleItem;
		System.out.println("isCollapsed("+itemId+")=="+((SimpleItem)itemId).isCollapsed());
		return ((SimpleItem)itemId).isCollapsed();
	}

	@Override
	public Item getItem(Object itemId) {
		assert itemId instanceof SimpleItem;
		return ((SimpleItem)itemId);
	}

	@Override
	public Collection<?> getContainerPropertyIds() {
		return items.get(0).getItemPropertyIds();
	}

	@Override
	public Collection<?> getItemIds() {
		throw new UnsupportedOperationException();
	}

	@Override
	public Property getContainerProperty(Object itemId, Object propertyId) {
		assert itemId instanceof SimpleItem;
		return ((SimpleItem)itemId).getItemProperty(propertyId);
	}

	@Override
	public Class<?> getType(Object propertyId) {
		return items.get(0).getItemProperty(propertyId).getType();
	}

	@Override
	public int size() {
		return items.size();
	}

	@Override
	public boolean containsId(Object itemId) {
		return items.contains(itemId);
	}

	@Override
	public Item addItem(Object itemId) throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public Object addItem() throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean removeItem(Object itemId)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean addContainerProperty(Object propertyId, Class<?> type,
			Object defaultValue) throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean removeContainerProperty(Object propertyId)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean removeAllItems() throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

}

The item

public class SimpleItem implements Item{

	private static LinkedList<String> propertyIds;
	private Integer index;
	private boolean collapsed = false;
	
	public SimpleItem(Integer index) {
		this.index = index;
	}
	
	@Override
	public Property getItemProperty(Object id) {
		if("id".equals(id)){
			return new ObjectProperty<Integer>(this.index);
		}else if("nome".equals(id)){
			return new ObjectProperty<String>("nome "+ this.index);
		}else{
			throw new InvalidParameterException();
		}
	}

	@Override
	public Collection<?> getItemPropertyIds() {
		if(propertyIds == null){
			propertyIds = new LinkedList<String>();
			propertyIds.add("id");
			propertyIds.add("nome");
		}
		return propertyIds;
	}

	@Override
	public boolean addItemProperty(Object id, Property property)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean removeItemProperty(Object id)
			throws UnsupportedOperationException {
		throw new UnsupportedOperationException();
	}

	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	public boolean isCollapsed() {
		return collapsed;
	}

	public void setCollapsed(boolean collapsed) {
		this.collapsed = collapsed;
	}
	
	@Override
	public String toString() {
		return "SimpleItem@"+index;
	}
}

The testing component

TreeTable tree = new TreeTable();
		
		tree.setContainerDataSource(new TestHContainer());
		
		addComponent(tree);

the items Hierarchy is simple:
0

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
    10
    -11
    -12
    -13
    -14
    -15

and so on
but i get this:

the Hierarchy seem correct but if i try to expand or collapse a root nothing happens

What am I doing wrong?