Skip to content

Commit

Permalink
Workaround for issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ricemery committed Aug 12, 2016
1 parent 6679d72 commit e9a469e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class DirectoryTreeItem extends TreeItem<File> {
private final Icons icons;
private final boolean isLeaf;

// Hold onto graphic at this level instead of passing to super class.
// This is to work around JDK issue - https://bugs.openjdk.java.net/browse/JDK-8156049.
private Node graphic;

private boolean directoryListLoaded = false;

public DirectoryTreeItem(final File value, final FilesViewCallback callback,
Expand All @@ -29,11 +33,12 @@ public DirectoryTreeItem(final File value, final FilesViewCallback callback,
public DirectoryTreeItem(final File value, final Node graphic,
final FilesViewCallback callback,
final Icons icons) {
super(value, graphic);
super(value, null);

this.callback = callback;
this.icons = icons;
this.isLeaf = !value.isDirectory();
this.graphic = graphic;

expandedProperty().addListener(new ExpandedListener());
}
Expand Down Expand Up @@ -71,11 +76,19 @@ private void loadChildren() {
getChildren().addAll(children);
}

public Node getGraphic2() {
return graphic;
}

public void setGraphic2(Node graphic) {
this.graphic = graphic;
}

private class ExpandedListener implements ChangeListener<Boolean> {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean expanded) {
if (getValue().isDirectory()) {
setGraphic(getIcon(expanded));
setGraphic2(getIcon(expanded));
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/chainstaysoftware/filechooser/ListFilesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@ private TreeTableColumn<File, String> createNameColumn(final TreeTableView paren
column.prefWidthProperty().bind(parent.widthProperty()
.subtract(DATE_MODIFIED_COL_PREF_WIDTH)
.subtract(SIZE_COLUMN_PREF_WIDTH));

column.setCellFactory(param -> new TreeTableCell<File, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);

if (empty) {
setText("");
setGraphic(null);
} else {
// This is a hack to work around JDK bug - https://bugs.openjdk.java.net/browse/JDK-8156049 .
final TreeTableRow row = getTreeTableRow();
if (row != null && row.getTreeItem() != null) {
final TreeItem treeItem = row.getTreeItem();
if (getTreeTableRow().getTreeItem() instanceof DirectoryTreeItem) {
setGraphic(((DirectoryTreeItem)treeItem).getGraphic2());
} else {
setGraphic(treeItem.getGraphic());
}
}

setText(item.toString());
}
}
});

return column;
}

Expand Down

0 comments on commit e9a469e

Please sign in to comment.