1 package com.vaadin.tests.containers.filesystemcontainer;
4 import java.io.IOException;
5 import java.util.ArrayList;
7 import com.vaadin.tests.components.TestBase;
8 import com.vaadin.tests.util.Log;
9 import com.vaadin.ui.Button;
10 import com.vaadin.ui.Button.ClickEvent;
11 import com.vaadin.ui.HorizontalLayout;
12 import com.vaadin.v7.data.Container;
13 import com.vaadin.v7.data.Container.Ordered;
14 import com.vaadin.v7.data.util.FilesystemContainer;
15 import com.vaadin.v7.ui.Table;
16 import com.vaadin.v7.ui.Tree.CollapseEvent;
17 import com.vaadin.v7.ui.Tree.CollapseListener;
18 import com.vaadin.v7.ui.Tree.ExpandEvent;
19 import com.vaadin.v7.ui.Tree.ExpandListener;
20 import com.vaadin.v7.ui.TreeTable;
22 public class FileSystemContainerInTreeTable extends TestBase {
24 private Log log = new Log(5);
25 private TreeTable treeTable;
28 protected void setup() {
29 setTheme("reindeer-tests");
33 File tempFile = File.createTempFile("fsc-tt", "");
35 folder = new File(tempFile.getParent(), tempFile.getName());
37 System.out.println(folder.getPath());
38 folder.deleteOnExit();
40 populate(folder, 3, 10);
42 FilesystemContainer fsc = new FilesystemContainer(folder);
44 treeTable = new TreeTable();
45 treeTable.addStyleName("table-equal-rowheight");
46 treeTable.setWidth("450px");
47 treeTable.setHeight("550px");
48 treeTable.setContainerDataSource(fsc);
49 treeTable.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON);
50 treeTable.setVisibleColumns(new String[] { "Name" });
51 treeTable.setColumnWidth("Name", 400);
52 treeTable.addListener(new ExpandListener() {
55 public void nodeExpand(ExpandEvent event) {
56 logExpandCollapse(event.getItemId(), "expanded");
60 treeTable.addListener(new CollapseListener() {
63 public void nodeCollapse(CollapseEvent event) {
64 logExpandCollapse(event.getItemId(), "collapsed");
70 addComponent(treeTable);
72 HorizontalLayout buttonLayout = new HorizontalLayout();
73 buttonLayout.setSpacing(true);
74 buttonLayout.addComponent(
75 new Button("Create dir11", new Button.ClickListener() {
77 public void buttonClick(ClickEvent event) {
78 new File(folder, "dir11").mkdir();
79 log.log("Row dir11 created");
82 buttonLayout.addComponent(
83 new Button("Delete dir11", new Button.ClickListener() {
85 public void buttonClick(ClickEvent event) {
86 new File(folder, "dir11").delete();
87 log.log("Row dir11 deleted");
90 // to clean up explicitly before ending an automated test
91 buttonLayout.addComponent(
92 new Button("Clean all files", new Button.ClickListener() {
94 public void buttonClick(ClickEvent event) {
98 addComponent(buttonLayout);
99 } catch (IOException e) {
104 private void populate(File folder, int subDirectories, int files)
106 for (int i = 1; i <= files; i++) {
107 File f = new File(folder, "file" + i + ".txt");
111 for (int i = 1; i <= subDirectories; i++) {
112 File f = new File(folder, "dir" + i);
118 protected int indexOfId(Table source, Object itemId) {
119 Container.Ordered c = (Ordered) source.getContainerDataSource();
120 if (c instanceof Container.Indexed) {
121 return ((Container.Indexed) source).indexOfId(itemId);
123 ArrayList<Object> list = new ArrayList<Object>(source.getItemIds());
124 return list.indexOf(itemId);
128 protected void logExpandCollapse(Object itemId, String operation) {
129 File file = (File) itemId;
130 // do not use the variable part (path) of file name
131 log.log("Row " + file.getName() + " " + operation + ". Row index: "
132 + indexOfId(treeTable, itemId));
137 protected String getDescription() {
138 return "TreeTable partial updates can only be used with a container that notifies the TreeTable of item set changes";
142 protected Integer getTicketNumber() {