Skip to content

Commit

Permalink
Add refresh button
Browse files Browse the repository at this point in the history
Simpify when I add a folder outside of the program and want it to show
up. I could also add a filewatch onto the folder itself and do this
automatically, but a the moment I don't want to deal with the various
events I'd likely need to keep track of, as we'd probably want to be
smart and update the tree wherever the event was for things like renames
(though the naive approach would be to just refresh the entire tree,
which is non-performant but simple)
  • Loading branch information
EdgeCaseBerg committed Aug 12, 2023
1 parent 5f504e3 commit d7a8284
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
public abstract class AbstractFileTreePanel extends JPanel implements ActionListener, FileVisitor<Path> {

JButton browseButton = new JButton("Browse");
JButton refreshButton = new JButton("Refresh");
transient Path loadedPath = null;
DefaultMutableTreeNode rootNode;
JTree jTree;
String browseText;
Expand All @@ -48,13 +50,21 @@ protected AbstractFileTreePanel(String browseText, boolean onlyIncludeDirectorie
jTree.setEditable(false);
jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.setShowsRootHandles(true);




setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(browseButton);
JPanel buttonPanel = new JPanel();
BoxLayout sideBySideButtons = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);

buttonPanel.add(browseButton);
buttonPanel.add(refreshButton);
add(buttonPanel);
add(scrollPane);

browseButton.addActionListener(this);
refreshButton.addActionListener(this);
}

DefaultMutableTreeNode currentParent = rootNode;
Expand All @@ -77,9 +87,14 @@ public void loadPath(Path rootPath) {
@Override
public void actionPerformed(ActionEvent e) {
AppLogger.info("FileTreePanel with text \"" + browseText + "\" button clicked " + this.rootNode);
if (jFileChooser.showOpenDialog(this.getParent()) == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser.getSelectedFile();
this.loadPath(file.toPath());
if (e.getActionCommand().equals("Refresh")) {
this.loadPath(this.loadedPath);
} else if (e.getActionCommand().equals(this.browseText)) {
if (jFileChooser.showOpenDialog(this.getParent()) == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser.getSelectedFile();
this.loadPath(file.toPath());
this.loadedPath = file.toPath();
}
}
}

Expand Down

0 comments on commit d7a8284

Please sign in to comment.