aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/tests/TreeFilesystem.java
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2009-10-27 07:57:12 +0000
committerArtur Signell <artur.signell@itmill.com>2009-10-27 07:57:12 +0000
commit6a3c715dae922edd723c9423b4308d5d7948b74e (patch)
tree46a007274681a9803afccf135ace5554f3e01e3a /src/com/vaadin/tests/TreeFilesystem.java
parent931d75fef69deb9b738fad97001cf5621de9f43e (diff)
downloadvaadin-framework-6a3c715dae922edd723c9423b4308d5d7948b74e.tar.gz
vaadin-framework-6a3c715dae922edd723c9423b4308d5d7948b74e.zip
Split demo and tests files to own source folders, for #3298
svn changeset:9390/svn branch:6.2
Diffstat (limited to 'src/com/vaadin/tests/TreeFilesystem.java')
-rw-r--r--src/com/vaadin/tests/TreeFilesystem.java106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/com/vaadin/tests/TreeFilesystem.java b/src/com/vaadin/tests/TreeFilesystem.java
deleted file mode 100644
index 202338cd50..0000000000
--- a/src/com/vaadin/tests/TreeFilesystem.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.tests;
-
-import java.io.File;
-
-import com.vaadin.data.Item;
-import com.vaadin.demo.util.SampleDirectory;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.Tree;
-import com.vaadin.ui.Window;
-import com.vaadin.ui.Tree.ExpandEvent;
-
-/**
- * Browsable file explorer using Vaadin Tree component. Demonstrates: how to add
- * items hierarchically into <code>com.vaadin.ui.Component.Tree</code>, how to
- * receive ExpandEvent and implement
- * <code>com.vaadin.ui.Tree.ExpandListener</code>.
- *
- * @since 4.0.0
- *
- */
-public class TreeFilesystem extends com.vaadin.Application implements
- Tree.ExpandListener {
-
- // Filesystem explorer panel and it's components
- private final Panel explorerPanel = new Panel("Filesystem explorer");
-
- private final Tree tree = new Tree();
-
- @Override
- public void init() {
- final Window main = new Window("Tree filesystem demo");
- setMainWindow(main);
-
- // Main window contains heading and panel
- main.addComponent(new Label("<h2>Tree demo</h2>", Label.CONTENT_XHTML));
-
- // configure file structure panel
- main.addComponent(explorerPanel);
- explorerPanel.addComponent(tree);
- explorerPanel.setHeight(400);
-
- // "this" handles tree's expand event
- tree.addListener(this);
-
- // Get sample directory
- final File sampleDir = SampleDirectory.getDirectory(this);
- // populate tree's root node with example directory
- if (sampleDir != null) {
- populateNode(sampleDir.getAbsolutePath(), null);
- }
- }
-
- /**
- * Handle tree expand event, populate expanded node's childs with new files
- * and directories.
- */
- public void nodeExpand(ExpandEvent event) {
- final Item i = tree.getItem(event.getItemId());
- if (!tree.hasChildren(i)) {
- // populate tree's node which was expanded
- populateNode(event.getItemId().toString(), event.getItemId());
- }
- }
-
- /**
- * Populates files to tree as items. In this example items are of String
- * type that consist of file path. New items are added to tree and item's
- * parent and children properties are updated.
- *
- * @param file
- * path which contents are added to tree
- * @param parent
- * for added nodes, if null then new nodes are added to root node
- */
- private void populateNode(String file, Object parent) {
- final File subdir = new File(file);
- final File[] files = subdir.listFiles();
- for (int x = 0; x < files.length; x++) {
- try {
- // add new item (String) to tree
- final String path = files[x].getCanonicalPath().toString();
- tree.addItem(path);
- // set parent if this item has one
- if (parent != null) {
- tree.setParent(path, parent);
- }
- // check if item is a directory and read access exists
- if (files[x].isDirectory() && files[x].canRead()) {
- // yes, childrens therefore exists
- tree.setChildrenAllowed(path, true);
- } else {
- // no, childrens therefore do not exists
- tree.setChildrenAllowed(path, false);
- }
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
-}