TomasMikula / LiveDirsFX

Directory tree model for JavaFX that watches the filesystem for changes.
BSD 2-Clause "Simplified" License
48 stars 10 forks source link

Consolidate shared directories into one row in TreeView #2

Open JordanMartinez opened 8 years ago

JordanMartinez commented 8 years ago

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
TomasMikula commented 8 years ago

It would be nice to have.

By overriding the cell factory, you can at least use the short names:

some/
    package/
        name/
            firstName/
                text.java
                code.java
            secondName/
                subPackage/
                    someClass.java
                writer.java
class MyTreeCell extends TreeCell<Path> {
    @Override
    public void updateItem(Path p, boolean empty) {
        super.updateItem(p, empty);
        if(!empty) {
            setText(p.getFileName().toString());
        } else {
            setText(null);
        }
    }
}
JordanMartinez commented 8 years ago

Hmm... I think that will work for the short term. Thanks!

TomasMikula commented 8 years ago

I think I can think of a nice way to implement this, but it would require implementation of flatMap on ObservableList first. It would also live completely outside of LiveDirs.

JordanMartinez commented 8 years ago

It would also live completely outside of LiveDirs.

Meaning it would be an entirely separate project?

TomasMikula commented 8 years ago

I'm not sure it would be worth a separate project.

static <T> TreeItem<T> transform(TreeItem<T> item, Function<TreeItem<T>, Val<TreeItem<T>>> f) {
    return new TreeItem<T>() {
        public ObservableList<TreeItem<T>> getChildren() {
            return item.getChildren().flatMap(child -> f.apply(child).asList()); // THIS flatMap DOES NOT EXIST
        }
        // ...
    }
}

static Val<TreeItem<T>> eliminateSingleChildDirs(TreeItem<T> item) {
    LiveList.sizeOf(item.getChildren()).flatMap(n -> {
        switch(n) {
            case 0: return Val.constant(item);
            case 1: return eliminateSingleChildDirs(item.getChildren().get(0));
            default: return Val.constant(transform(item, Foo::eliminateSingleChildDirs));
        }
    });
}

TreeItem<Path> root = liveDirs.model().getRoot();
TreeItem<Path> root1 = transform(root, Foo::eliminateSingleChildDirs);

// Use root1 to create a TreeView
JordanMartinez commented 8 years ago

I thought so....

You mean "outside" as in flatMap would be implemented in ReactFX?

TomasMikula commented 8 years ago

It doesn't really matter where it is implemented, but yes, ReactFX would be a natural place for that flatMap. In fact, it is the only big feature left to be implemented before I want to release ReactFX 2.0.

JordanMartinez commented 8 years ago

Is that why it's been in a continual "2.0M4u1" release?

TomasMikula commented 8 years ago

Yes, that's a big part of the reason. I didn't get to implementing it when I was implementing LiveList. It is trickier than it seems at the first sight. And then my priorities changed (I'm currently not working on any UI stuff as part of my day job), so I have less time for altruistic work.

JordanMartinez commented 8 years ago

And then my priorities changed (I'm currently not working on any UI stuff as part of my day job), so I have less time for altruistic work.

I was wondering why you've been less responsive when it comes to RichTextFX-related things (as compared to October through December)