commit
4fdefea1bd
@ -13,13 +13,26 @@ import java.util.List;
|
||||
* @author cccqyu
|
||||
*/
|
||||
public class DirFileModel {
|
||||
/**
|
||||
* 路径
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 未选中时的图标
|
||||
*/
|
||||
private Node iconIsNotSelected;
|
||||
|
||||
/**
|
||||
* 选中时的图标
|
||||
*/
|
||||
private Node iconIsSelected;
|
||||
|
||||
/**
|
||||
* 子文件
|
||||
*/
|
||||
private List<DirFileModel> childFile;
|
||||
|
||||
public DirFileModel(String path, String name, List<DirFileModel> childFile, Node iconIsNotSelected, Node iconIsSelected) {
|
||||
|
||||
@ -112,6 +112,16 @@ public class DirectorySidebarManager {
|
||||
expandFolder(dirFileModel, rootItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given `DirFileModel` represents a directory.
|
||||
*
|
||||
* @param childFile the `DirFileModel` to check
|
||||
* @return `true` if the `childFile` represents a directory, `false` otherwise
|
||||
*/
|
||||
private static boolean isDirectoryByDirFileModel(DirFileModel childFile) {
|
||||
return new File(childFile.getPath()).isDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归展开 dirFileModel
|
||||
*
|
||||
@ -123,7 +133,10 @@ public class DirectorySidebarManager {
|
||||
if (childFileList != null) {
|
||||
for (DirFileModel childFile : childFileList) {
|
||||
TreeItem<DirFileModel> childItem = new TreeItem<>(childFile, childFile.getIconIsNotSelected());
|
||||
childItem.expandedProperty().addListener(getTreeItemListener(childItem));
|
||||
// 只有文件夹树才添加监听事件
|
||||
if (isDirectoryByDirFileModel(childFile)) {
|
||||
childItem.expandedProperty().addListener(getTreeItemListener(childItem));
|
||||
}
|
||||
item.getChildren().add(childItem);
|
||||
expandFolder(childFile, childItem);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user