- /**
- * Called when this item is expanded or collapsed. this.expanded will be
- * true if this item was just expanded from a mouse click or keypress.
- */
- @Override
- public final void onExpand() {
- // System.err.printf("onExpand() %s\n", file);
-
- if (file == null) {
- return;
- }
- getChildren().clear();
-
- // Make sure we can read it before trying to.
- if (file.canRead()) {
- setSelectable(true);
- } else {
- setSelectable(false);
- }
- assert (file.isDirectory());
- setExpandable(true);
-
- if (!isExpanded() || !isExpandable()) {
- getTreeView().reflowData();
- return;
- }
-
- for (File f: file.listFiles()) {
- // System.err.printf(" -> file %s %s\n", file, file.getName());
-
- if (f.getName().startsWith(".")) {
- // Hide dot-files
- continue;
- }
- if (!f.isDirectory()) {
- continue;
- }
-
- try {
- TDirectoryTreeItem item = new TDirectoryTreeItem(getTreeView(),
- f.getCanonicalPath(), false, false);
-
- item.level = this.level + 1;
- getChildren().add(item);
- } catch (IOException e) {
- continue;
- }
- }
- Collections.sort(getChildren());
-
- getTreeView().reflowData();
- }
-
- /**
- * Add a child item. This method should never be used, it will throw an
- * IllegalArgumentException every time.
- *
- * @param text text for this item
- * @param expanded if true, have it expanded immediately
- * @return the new item
- * @throws IllegalArgumentException if this function is called
- */
- @Override
- public final TTreeItem addChild(final String text,
- final boolean expanded) throws IllegalArgumentException {
-
- throw new IllegalArgumentException("Do not call addChild(), use onExpand() instead");
- }