Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate shared directories into one row in TreeView #2

Open
JordanMartinez opened this issue Feb 12, 2016 · 10 comments
Open

Consolidate shared directories into one row in TreeView #2

JordanMartinez opened this issue Feb 12, 2016 · 10 comments

Comments

@JordanMartinez
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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

@TomasMikula
Copy link
Owner

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
Copy link
Contributor Author

It would also live completely outside of LiveDirs.

Meaning it would be an entirely separate project?

@TomasMikula
Copy link
Owner

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
Copy link
Contributor Author

I thought so....

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

@TomasMikula
Copy link
Owner

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
Copy link
Contributor Author

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

@TomasMikula
Copy link
Owner

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
Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants