public class TreeFiltering extends TestBase {
@Override
public void setup() {
final Tree ccTree = new Tree();
addComponent(ccTree);
final HierarchicalContainer cont = new HierarchicalContainer();
cont.addContainerProperty("caption", String.class, "");
Item item;
for (int i = 0; i < 5; i++) {
item = cont.addItem(i);
item.getItemProperty("caption").setValue("Number " + i);
cont.setParent(i, i - 1);
}
for (int i = 0; i < 5; i++) {
Object id = cont.addItem();
item = cont.getItem(id);
item.getItemProperty("caption").setValue("0-" + i);
cont.setParent(id, 0);
}
ccTree.setContainerDataSource(cont);
ccTree.setItemCaptionPropertyId("caption");
for (final Object o : ccTree.getItemIds()) {
ccTree.expandItem(o);
}
final CheckBox filterType = new CheckBox(
"Include parent when filtering", true);
filterType.setImmediate(true);
filterType.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
cont.setIncludeParentsWhenFiltering(((CheckBox) event
.getProperty()).getValue());
ccTree.markAsDirty();
}
});
addComponent(filterType);
final Button b = new Button("Add filter 'foo'", new ClickListener() {