Directory tree model for JavaFX that watches the filesystem for changes.

Related tags

GUI LiveDirsFX
Overview

LiveDirsFX

LiveDirsFX is a combination of a directory watcher, a directory-tree model (for TreeView) and a simple asynchronous file I/O facility. The extra benefits of this combination are:

  1. Automatic synchronization of the directory model with the filesystem.
  2. Ability to distinguish directory and file modifications made by the application (through the I/O facility) from external modifications.

Example

enum ChangeSource {
    INTERNAL, // indicates a change made by this application
    EXTERNAL, // indicates an external change
}

// create LiveDirs to watch a directory
LiveDirs<ChangeSource> liveDirs = new LiveDirs<>(EXTERNAL);
Path dir = Paths.get("/path/to/watched/directory/");
liveDirs.addTopLevelDirectory(dir);

// use LiveDirs as a TreeView model
TreeView<Path> treeView = new TreeView<>(liveDirs.model().getRoot());
treeView.setShowRoot(false);

// handle external changes
liveDirs.model().modifications().subscribe(m -> {
    if(m.getInitiator() == EXTERNAL) {
        // handle external modification, e.g. reload the modified file
        reload(m.getPath());
    } else {
        // modification done by this application, no extra action needed
    }
});

// Use LiveDirs's I/O facility to write to the filesystem,
// in order to be able to distinguish between internal and external changes.
Path file = dir.resolve("some/file.txt");
liveDirs.io().saveUTF8File(file, "Hello text file!", INTERNAL);

// clean up
liveDirs.dispose();

Use LiveDirsFX in your project

Method 1: as a managed dependency (recommended)

Snapshot releases are deployed to Sonatype snapshot repository with these Maven coordinates

Group ID Artifact ID Version
org.fxmisc.livedirs livedirsfx 1.0.0-SNAPSHOT

Gradle example

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/' 
    }
}

dependencies {
    compile group: 'org.fxmisc.livedirs', name: 'livedirsfx', version: '1.0.0-SNAPSHOT'
}

Sbt example

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "org.fxmisc.livedirs" % "livedirsfx" % "1.0.0-SNAPSHOT"

Method 2: as an unmanaged dependency

Download the latest JAR or fat JAR (including dependencies) and place it on your classpath.

Links

Javadoc

Comments
  • Allow CheckBoxTreeCell CellFactory

    Allow CheckBoxTreeCell CellFactory

    I was hoping to use this library in JGitFX. However, LiveDirs does not allow the option of using the CheckBoxTreeCell factory, which is essential for designing a commit or revert dialog where the user can check which files they want to stage and commit or revert.

    opened by JordanMartinez 33
  • Generalize TreeItem used in root and children of a TreeView

    Generalize TreeItem used in root and children of a TreeView

    I named the two functions, projector and injector. However, I wonder if it might be better to name them valToPath and pathToVal. Seems to be more consistent....

    opened by JordanMartinez 22
  • Is there a way to choose custom names for each tree item?

    Is there a way to choose custom names for each tree item?

    The default option is that the whole path name is displayed within the tree view. I just want to display the filename (path.fileName). I did not yet a way to do this, is there one?

    opened by arturbosch 2
  • Minor code cleanup

    Minor code cleanup

    • Specified toArray generic
    • Convert lambdas to method references where possible

    Let's be honest. I should have done this first before since I end up redoing it in every new branch I try out.

    opened by JordanMartinez 0
  • Check box tree item option

    Check box tree item option

    Same as #3 except without the 'remove unneeded root generic in Directory Model' commit. Per my realization in rereading my comment #1, the root actually does need to be specified.

    opened by JordanMartinez 0
  • Correcting a redundant invokation of pollEvents method, that was perm…

    Correcting a redundant invokation of pollEvents method, that was perm…

    …anently emptying the event queue.

    The project invokes "pollEvents" twice, consecutively : one time (l162) as the "events" variable is initialized and one more time immediately after, in the for loop (l166). Watchkey documentation tells: "Events are retrieved by invoking the key's pollEvents method. This method retrieves and removes all events accumulated for the object." As a consequence, the for loop tries continuously to scan an emptied liste of events because no file event could happen inbetween. The solution is to use the created variable ("events") instead of re-invoking the pollEvents method on line 166.

    It was for me the only way to make directories display. Hope this helps (far from beeing an experienced coder).

    opened by CaiusCornelius 0
  • Lazy loading

    Lazy loading

    Hi, Tomas! Thanks for bringing ReactFX to the world.

    Any chance to implement lazy loading in LiveDirsFX, so that the children list would be loaded as a user expands TreeItem? Could you point me in the right direction?

    opened by valnaumov 0
  • Unable to initialize the view

    Unable to initialize the view

    Hi, I was trying to implement LiveDirsFX in my code. But it is giving me error on LinuxMint (18.1).

    Exception in Application start method
       java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
        Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
        Caused by: java.lang.ExceptionInInitializerError
    at org.fxmisc.livedirs.DirectoryModel.<clinit>(DirectoryModel.java:101)
    at org.fxmisc.livedirs.LiveDirsModel.<init>(LiveDirsModel.java:27)
    at org.fxmisc.livedirs.LiveDirs.<init>(LiveDirs.java:90)
    at org.fxmisc.livedirs.LiveDirs.getInstance(LiveDirs.java:65)
    at org.fxmisc.livedirs.LiveDirs.getInstance(LiveDirs.java:52)
    at in.co.s13.marking.assistant.MarkingAssistant.start(MarkingAssistant.java:61)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
    ... 1 more
        Caused by: java.lang.NullPointerException
    at org.fxmisc.livedirs.DefaultGraphicFactory.<clinit>(DirectoryModel.java:143)
    ... 15 more
        Exception running application in.co.s13.marking.assistant.MarkingAssistant
        Java Result: 1
    

    Any ideas ??

    opened by deepsidhu1313 0
  • Consolidate shared directories into one row in TreeView

    Consolidate shared directories into one row in TreeView

    In Intellij Idea, the TreeView displays their files like so:

    some/package/name/
        firstName/
            text.java
            code.java
        secondName/
            subPackage/
                someClass.java
            writer.java
    

    Currently, LiveDirsFX does not support this option to consolidate directories into one row. So, the above files would be displayed as:

    some/
        some/package
            some/package/name/
            some/package/name/firstName/
                some/package/name/firstName/text.java
                some/package/name/firstName/code.java
            some/package/name/secondName/
                some/package/name/secondName/subPackage/
                    some/package/name/secondName/subPackage/someClass.java
                some/package/name/secondName/writer.java
    
    opened by JordanMartinez 10
Owner
Tomas Mikula
Tomas Mikula
This is an open source visualization for the C4 model for visualising software architecture.

c4viz: C4 Visualization This is an open source visualization for the C4 model for visualising software architecture. It expects input in the form of a

Peter Valdemar Mørch 40 Dec 6, 2022
Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.

FXTrayIcon Library intended for use in JavaFX applications that makes adding a System Tray icon easier. The FXTrayIcon class handles all the messy AWT

Dustin Redmond 248 Dec 30, 2022
Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE 8 and provides the functionalities to use and handle easily Tiles in your JavaFX application.

Lib-Tile Intention Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE and provides the functionalities to use and handle easily Tile

Peter Rogge 13 Apr 13, 2022
DataFX - is a JavaFX frameworks that provides additional features to create MVC based applications in JavaFX by providing routing and a context for CDI.

What you’ve stumbled upon here is a project that intends to make retrieving, massaging, populating, viewing, and editing data in JavaFX UI controls ea

Guigarage 110 Dec 29, 2022
Collection of Binding helpers for JavaFX(8)

Advanced-Bindings for JavaFX (8) advanced-bindings is a collection of useful helpers and custom binding implementations to simplify the development of

Manuel Mauky 63 Nov 19, 2022
Docking framework for JavaFX platform

Docking framework for JavaFX platform AnchorFX is a gratis and open source library for JavaFX to create graphical interfaces with docking features Anc

Alessio Vinerbi 197 Oct 15, 2022
A library of +70 ready-to-use animations for JavaFX

AnimateFX A library of ready-to-use animations for JavaFX Features: Custom animations Custom interpolators Play/Stop animation Play an animation after

Loïc Sculier 366 Jan 5, 2023
BootstrapFX: Bootstrap for JavaFX

BootstrapFX BootstrapFX is a partial port of Twitter Bootstrap for JavaFX. It mainly provides a CSS stylesheet that closely resembles the original whi

Kordamp 810 Dec 28, 2022
A Java framework for creating sophisticated calendar views (JavaFX 8, 9, 10, and 11)

CalendarFX A Java framework for creating sophisticated calendar views based on JavaFX. A detailed developer manual can be found online: CalendarFX 8 D

DLSC Software & Consulting GmbH 660 Jan 6, 2023
Allow runtime modification of JavaFX CSS

cssfx ⚠ WARNING ⚠ In version 11.3.0 we have relocated & refactored the project. maven groupId has been changed to fr.brouillard.oss java module name h

Matthieu Brouillard 134 Jan 2, 2023
A JavaFX UI framework to create fully customized undecorated windows

CustomStage A JavaFX undecorated stage which can fully be customized Donations If this project is helpful to you and love my work and feel like showin

Oshan Mendis 186 Jan 6, 2023
MDI components for JavaFX

DesktopPaneFX DesktopPaneFX is a JavaFX version of Swing’s JDesktopPane which can be used as a container for individual "child" similar to JInternalFr

Kordamp 58 Sep 23, 2022
Efficient VirtualFlow for JavaFX

Flowless Efficient VirtualFlow for JavaFX. VirtualFlow is a layout container that lays out cells in a vertical or horizontal flow. The main feature of

null 163 Nov 24, 2022
A framework for easily creating forms for a JavaFX UI.

FormsFX Forms for business application made easy. Creating forms in Java has never been this easy! Maven To use this framework as part of your Maven b

DLSC Software & Consulting GmbH 534 Dec 30, 2022
:icecream: iOS frosty/translucent effect to JavaFX

FroXty is JavaFX library which replicates the famous iOS translucent effect with ease. Set-up FroXty can be imported into your project either by downl

Giorgio Garofalo 33 Dec 11, 2022
💠 Undecorated JavaFX Scene with implemented move, resize, minimise, maximise, close and Windows Aero Snap controls.

Support me joining PI Network app with invitation code AlexKent FX-BorderlessScene ( Library ) ?? Undecorated JavaFX Scene with implemented move, resi

Alexander Kentros 125 Jan 4, 2023
Dynamic JavaFX form generation

FXForm 2 Stop coding forms: FXForm 2 can do it for you! About FXForm2 is a library providing automatic JavaFX form generation. How does it work? Write

dooApp 209 Jan 9, 2023
A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

FXGraphics2D Version 2.1, 3 October 2020. Overview FXGraphics2D is a free implementation of Java's Graphics2D API that targets the JavaFX Canvas. It m

David Gilbert 184 Dec 31, 2022
Auto updating launcher for JavaFX Applications

FXLauncher Auto updating launcher for JavaFX Applications. Combined with JavaFX native packaging, you get a native installer with automatic app update

Edvin Syse 694 Dec 27, 2022