Skip to content

Commit

Permalink
Attempt at creating a file visitor that works with tree items
Browse files Browse the repository at this point in the history
  • Loading branch information
kag12017 committed Feb 12, 2016
1 parent 00e0cee commit 5ee5dec
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 36 deletions.
14 changes: 9 additions & 5 deletions src/main/java/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ public class Controller{
@FXML private MenuItem fileTag;
@FXML private MenuItem fileExit;
@FXML private MenuItem editPreferences;
@FXML private TreeView<IronFile> dirTree;
@FXML private TreeView<String> dirTree;
@FXML private ResourceBundle resources;

@FXML private void initialize() {
createTree();
//createTree();
// FolderViewManager.java calls are done here

FolderViewManager.view = dirTree;
File homeDir = new File(System.getProperty("user.home"));
FolderViewManager.setRootDirectory(homeDir);
}

// Create the directory Tree
private void createTree() {
/* private void createTree() {
// Get the hard disk drives and 2 levels down
IronFile[] roots = IronFile.listRoots();
for (IronFile hdd : roots) {
Expand All @@ -54,8 +58,8 @@ private void createTree() {
public TreeCell<File> call(TreeView<File> param) {
return new TreeFieldImpl();
}
});*/
}
});
}*/
/**
* Set the child of a given parent TreeItem
*
Expand Down
48 changes: 17 additions & 31 deletions src/main/java/FolderViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.ExecutionException;

/**
This class handles manipulation of the Folder View. This includes
Expand All @@ -21,45 +20,32 @@
@author kristopherguzman
@author Brian Patino
*/
public class FolderViewManager extends SimpleFileVisitor<Path>{
// public static TreeView<String> treeView;
// private static TreeItem<String> root;
// private static int NEST_COUNT = 0; //tracks number of nested calls when searching through files, TEMPORARY
public class FolderViewManager {

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// System.out.printf("Visiting file %s\n", file);
return FileVisitResult.CONTINUE;
}
/**
* {@inheritDoc}
* This method must be overridden so that walking the tree can continue.
* */
@Override
public FileVisitResult visitFileFailed(Path file, IOException e) throws IOException {
System.err.printf("Visiting failed for %s\n", file);
return FileVisitResult.SKIP_SUBTREE;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
// System.out.printf("About to visit directory %s\n", dir);
return FileVisitResult.CONTINUE;
}
public static TreeView<String> view;
private static TreeItem<String> root;
private static int NEST_COUNT = 0; //tracks number of nested calls when searching through files, TEMPORARY

private FolderViewManager() { }

public static void setRootDirectory(File file) {

/*public static void setRootDirectory(File file) {
root = new TreeItem<String>(file.getName());
view.setRoot(root);

createCellsFromRoot(file, root);
treeView.setRoot(root);
}


private static void createCellsFromRoot(File rootFile, TreeItem<String> rootNode) {

NEST_COUNT++;
if(NEST_COUNT > 6000) { //fixed value, TEMPORARY, must come up with better way to optimize load time of files
if(NEST_COUNT > 6000) { //fixed value, TEMPORARY optimization
return;
}

for(File f : rootFile.listFiles()) {
if(!f.getName().startsWith(".")) { //don't show files that start with dot (ex: .filename .pythonfile)
if(!f.getName().startsWith(".")) { //don't show system files that start with dot (ex: .filename .pythonfile)
TreeItem<String> fileNode = new TreeItem<String>(f.getName());
rootNode.getChildren().add(fileNode);
if (f.isDirectory()) {
Expand All @@ -68,4 +54,4 @@ private static void createCellsFromRoot(File rootFile, TreeItem<String> rootNode
}
}
}
*/}
}
49 changes: 49 additions & 0 deletions src/main/java/IronFileVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main.java;

import javafx.scene.control.TreeItem;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.io.File;

/**
* Created by kristopherguzman on 2/11/16.
*/
public class IronFileVisitor extends SimpleFileVisitor<Path> {

private TreeItem<String> currentDirectory;

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

return FileVisitResult.CONTINUE;
}
/**
* {@inheritDoc}
* This method must be overridden so that walking the tree can continue.
* */
@Override
public FileVisitResult visitFileFailed(Path file, IOException e) throws IOException {
System.err.printf("Visiting failed for %s\n", file);
return FileVisitResult.SKIP_SUBTREE;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
System.out.printf("About to visit directory %s\n", dir);

currentDirectory = new TreeItem<String>(dir.getFileName().toString());
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
System.out.printf("About to visit directory %s\n", dir);


return FileVisitResult.CONTINUE;
}

}

0 comments on commit 5ee5dec

Please sign in to comment.