Skip to content

Commit

Permalink
Add Tag by Meta-data and Other Button Events
Browse files Browse the repository at this point in the history
* add view of current tags
* add new simpler gui
* add fxids to some fields
  • Loading branch information
brp14005 committed Mar 4, 2016
1 parent ddb4628 commit 7243188
Show file tree
Hide file tree
Showing 5 changed files with 397 additions and 47 deletions.
43 changes: 35 additions & 8 deletions src/main/java/directory/IronFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
import utils.IronFileFilter;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.util.List;

/**
Expand All @@ -12,17 +20,27 @@ public class IronFile extends File {
private boolean isRoot = true;
public IronFileFilter filter;
private String tag;
final private String ATTR_TYPE = "tags";
private UserDefinedFileAttributeView fileAttributeView;

/**
* Construct an IronFile that extends File
* @param pathname the path where the file is located
* */
public IronFile(String pathname) {
super(pathname);
isRoot = (getParent() == null);
filter = new IronFileFilter();
// filter = new IronFileFilter();
}
/**
* Construct an IronFile that extends File. This is an overloaded method
* @param file file that can be passed instead of path (string)
* */
public IronFile(File file) {
super(file.getPath());
isRoot = (getParent() == null);
filter = new IronFileFilter();

// filter = new IronFileFilter();
fileAttributeView = Files.getFileAttributeView(this.toPath(), UserDefinedFileAttributeView.class);
}

@Override
Expand Down Expand Up @@ -63,17 +81,26 @@ public void setRoot(boolean root) {

@Override
public String toString() {
if (isRoot) {
return this.getAbsolutePath();
} else {
return this.getName();
}
return (isRoot) ? this.getAbsolutePath() : this.getName();
}

public String getTag() {
try {
ByteBuffer buf = ByteBuffer.allocate(fileAttributeView.size(ATTR_TYPE));
fileAttributeView.read(ATTR_TYPE, buf);
buf.flip();
tag = Charset.defaultCharset().decode(buf).toString();
} catch(IOException e) {
e.printStackTrace();
}
return tag;
}
public void setTag(String tag) {
this.tag = tag;
try {
fileAttributeView.write(ATTR_TYPE, Charset.defaultCharset().encode(tag)); // Set file tag attributes
} catch (IOException e) {
e.printStackTrace();
}
}
}
74 changes: 41 additions & 33 deletions src/main/java/launcher/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,28 @@ public class Controller{
@FXML private MenuItem fileExit;
@FXML private MenuItem editPreferences;
@FXML private MenuItem fileDropboxSignin;
@FXML private TreeView<IronFile> dirTree;
@FXML private MenuItem toolsTagFiles;
@FXML private MenuItem toolsDeleteTags;
@FXML private MenuItem toolsTagFiles;
@FXML private ResourceBundle resources;
@FXML private Button btnAddTag;
@FXML private TreeView<IronFile> dirTree;
@FXML private TextField txtAddTag;
@FXML private TextField txtSearchTag;
@FXML private Button btnSearchTag;
@FXML private ListView<IronFile> viewTags;
private FolderViewManager manager;
@FXML private MenuBar menubar;
@FXML private Label dragHereLabel;
@FXML private ListView<IronFile> viewTags;
@FXML private ListView<String> viewExistTags;


@FXML private void initialize() {
manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best
IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives
// IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives
menubar.setUseSystemMenuBar(true); //allows use of native menu bars, luckily an easy 1 liner
// manager.setRootDirectory(hardDrives); //Ideally only show tree view of files the user drags in
// initializeSceneEvents(); // initialize Drag and Drop feature
}
/**
* Action event triggered when user clicks. This method will add tag directly to IronFile
* Method name must match StartPage.fxml assigned `on Action`
* */
@FXML private void eventAddTag() {
ObservableList<TreeItem<IronFile>> treeIronFileList = dirTree.getSelectionModel().getSelectedItems();
ObservableList<IronFile> selectedIronFiles = FXCollections.observableArrayList();
/** The following line converts ObservableList<TreeItem<IronFile> into ObservableList<IronFile> which is needed to display just the names.**/
selectedIronFiles.addAll(treeIronFileList.stream().map(TreeItem::getValue).collect(Collectors.toList()));
manager.setTags(selectedIronFiles, txtAddTag.getText());
}
/**
* On Click event that will search and display files based on entered tag
* */
@FXML private void eventSearchTag() {
ObservableList<IronFile> taggedItems = manager.getTaggedItems(txtSearchTag.getText());
viewTags.setItems(taggedItems);
}
/**
* Action on click event that will delete all tag information from selected files.
* Initialize the drag and Drop event and other scene events
* */
@FXML private void eventDeleteTags() {
ObservableList<TreeItem<IronFile>> selectedItems = dirTree.getSelectionModel().getSelectedItems(); // get list of selected files
manager.deleteAllTags(selectedItems);
}
public void initializeSceneEvents() {
Scene scene = dirTree.getScene();
scene.setOnDragOver(args -> {
Expand All @@ -104,9 +81,40 @@ public void initializeSceneEvents() {
args.setDropCompleted(success);
});
}
/**
* Action event triggered when user clicks. This method will add tag directly to IronFile
* Method name must match StartPage.fxml assigned `on Action`
* */
@FXML private void eventAddTag() {
ObservableList<TreeItem<IronFile>> treeIronFileList = dirTree.getSelectionModel().getSelectedItems();
ObservableList<IronFile> selectedIronFiles = FXCollections.observableArrayList();
/** The following line converts ObservableList<TreeItem<IronFile> into ObservableList<IronFile> which is needed to display just the names.**/
selectedIronFiles.addAll(treeIronFileList.stream().map(TreeItem::getValue).collect(Collectors.toList()));
manager.setTags(selectedIronFiles, txtAddTag.getText());
ObservableList<String> tagsList = FXCollections.observableArrayList(txtAddTag.getText());
tagsList.addAll(viewExistTags.getItems());
viewExistTags.setItems(tagsList);
}
@FXML private void eventSearchRemoveTag() {

/* public void setScene(Scene scene) {
this.scene = scene;
}*/
}
/**
* On Click event that will search and display files based on entered tag
* */
@FXML private void eventSearchTag() {
ObservableList<IronFile> taggedItems = manager.getTaggedItems(txtSearchTag.getText());
viewTags.setItems(taggedItems);
}
/**
* Action on click event that will delete all tag information from selected files.
* */
@FXML private void eventDeleteTags() {
ObservableList<TreeItem<IronFile>> selectedItems = dirTree.getSelectionModel().getSelectedItems(); // get list of selected files
manager.deleteAllTags(selectedItems);
}

@FXML private void eventRemoveTag() {
// ObservableList<TreeItem<IronFile>> treeIronFile
}
}

3 changes: 1 addition & 2 deletions src/main/java/launcher/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Main extends Application {
public void start(Stage primaryStage) throws Exception{
// setUserAgentStylesheet(STYLESHEET_CASPIAN);
FXMLLoader loader = new FXMLLoader();
Parent root = loader.load(getClass().getResource("/StartPage.fxml").openStream());
Parent root = loader.load(getClass().getResource("/SimpleGUI.fxml").openStream());
Controller controller = loader.getController();
primaryStage.setTitle("Iron-gate!");
Scene scene = new Scene(root, 990, 700);
Expand All @@ -28,7 +28,6 @@ public void start(Stage primaryStage) throws Exception{
scene.getStylesheets().clear(); // clear any styles
// scene.getStylesheets().add("/main/resources/mainStyle.css"); // absolute path
primaryStage.show(); // show the initialized stage

}
public static void main(String[] args) {
launch(args);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/utils/CmdExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
* Created by kristopherguzman on 2/19/16.
*/
public class CmdExecutor {

public CmdExecutor() { }

public String run(String cmd) throws IOException {
System.out.println("executing command: " + cmd);
String[] args = new String[] {"sh", "-c", "cd / && " + cmd};
Expand All @@ -30,7 +27,6 @@ public String run(String cmd) throws IOException {
while(error != null) {
System.out.println("error output: " + error);
error = errorReader.readLine();

}
outputReader.close();
errorReader.close();
Expand Down
Loading

0 comments on commit 7243188

Please sign in to comment.