-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create FileTreeItem to handle dynamic file views * misc code cleanup
- Loading branch information
Showing
3 changed files
with
77 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main.java; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.scene.control.TreeItem; | ||
|
||
/** | ||
* This class extends TreeItem and generates child files dynamically for the file browser. | ||
* | ||
* @author Brian Patino patinobrian@gmail.com | ||
* @see <a href="https://docs.oracle.com/javafx/2/api/javafx/scene/control/TreeItem.html">Tree Item</a> | ||
*/ | ||
public class FileTreeItem extends TreeItem<IronFile> { | ||
private boolean isLeaf; | ||
private boolean isFirstTimeChildren = true; | ||
private boolean isFirstTimeLeaf = true; | ||
|
||
public FileTreeItem(IronFile rootFile) { | ||
super(rootFile); | ||
} | ||
|
||
@Override | ||
public ObservableList<TreeItem<IronFile>> getChildren() { | ||
if (isFirstTimeChildren) { | ||
isFirstTimeChildren = false; | ||
super.getChildren().setAll(buildChildren(this)); | ||
} | ||
return super.getChildren(); | ||
} | ||
|
||
@Override | ||
public boolean isLeaf() { | ||
if (isFirstTimeLeaf) { | ||
isFirstTimeLeaf = false; | ||
IronFile f = getValue(); | ||
isLeaf = f.isFile(); | ||
} | ||
return isLeaf; | ||
} | ||
private ObservableList<FileTreeItem> buildChildren(TreeItem<IronFile> ironTreeItem) { | ||
IronFile f = ironTreeItem.getValue(); | ||
if (f != null && f.isDirectory()) { | ||
IronFile[] files = f.listFiles(); | ||
if (files != null) { | ||
ObservableList<FileTreeItem> children = FXCollections.observableArrayList(); | ||
for (IronFile childFile : files) { | ||
children.add(new FileTreeItem(childFile)); | ||
} | ||
return children; | ||
} | ||
} | ||
return FXCollections.emptyObservableList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters