mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Extend TreeUI and ProjectView/ProjectViewPane APIs
This commit is contained in:
+4
-2
@@ -115,9 +115,11 @@ public abstract class AbstractProjectViewPSIPane extends AbstractProjectViewPane
|
||||
});
|
||||
}
|
||||
myTreeStructure = createStructure();
|
||||
setTreeBuilder(createBuilder(treeModel));
|
||||
|
||||
installComparator();
|
||||
BaseProjectTreeBuilder treeBuilder = createBuilder(treeModel);
|
||||
installComparator(treeBuilder);
|
||||
setTreeBuilder(treeBuilder);
|
||||
|
||||
initTree();
|
||||
|
||||
Disposer.register(getTreeBuilder(), new UiNotifyConnector(myTree, new Activatable() {
|
||||
|
||||
+13
-1
@@ -468,8 +468,12 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
}
|
||||
|
||||
public void installComparator() {
|
||||
installComparator(getTreeBuilder());
|
||||
}
|
||||
|
||||
public void installComparator(AbstractTreeBuilder treeBuilder) {
|
||||
final ProjectView projectView = ProjectView.getInstance(myProject);
|
||||
getTreeBuilder().setNodeDescriptorComparator(new GroupByTypeComparator(projectView, getId()));
|
||||
treeBuilder.setNodeDescriptorComparator(new GroupByTypeComparator(projectView, getId()));
|
||||
}
|
||||
|
||||
public JTree getTree() {
|
||||
@@ -633,6 +637,14 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
myTreeBuilder = treeBuilder;
|
||||
}
|
||||
|
||||
public boolean supportsFoldersAlwaysOnTop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean supportsSortByType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private class MyDragSource implements DnDSource {
|
||||
@Override
|
||||
public boolean canStartDragging(DnDAction action, Point dragOrigin) {
|
||||
|
||||
@@ -1878,7 +1878,8 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
public void update(final AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
presentation.setVisible(getCurrentProjectViewPane() != null);
|
||||
AbstractProjectViewPane pane = getCurrentProjectViewPane();
|
||||
presentation.setVisible(pane != null && pane.supportsSortByType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1901,7 +1902,8 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
public void update(final AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
presentation.setEnabledAndVisible(getCurrentProjectViewPane() != null);
|
||||
AbstractProjectViewPane pane = getCurrentProjectViewPane();
|
||||
presentation.setEnabledAndVisible(pane != null && pane.supportsFoldersAlwaysOnTop());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -794,14 +794,27 @@ public final class TreeUtil {
|
||||
expand(tree, new TreePath(tree.getModel().getRoot()), levels);
|
||||
}
|
||||
|
||||
private static void expand(@NotNull JTree tree, @NotNull TreePath path, int levels) {
|
||||
if (levels == 0) return;
|
||||
/**
|
||||
* Expands n levels of the tree counting from the root and return true if there is no nodes to expand
|
||||
* @param tree to expand nodes of
|
||||
* @param levels depths of the expantion
|
||||
*/
|
||||
public static boolean expandWithResult(@NotNull JTree tree, int levels) {
|
||||
return expand(tree, new TreePath(tree.getModel().getRoot()), levels);
|
||||
}
|
||||
|
||||
private static boolean expand(@NotNull JTree tree, @NotNull TreePath path, int levels) {
|
||||
if (levels == 0) return false;
|
||||
tree.expandPath(path);
|
||||
TreeNode node = (TreeNode)path.getLastPathComponent();
|
||||
Enumeration children = node.children();
|
||||
|
||||
boolean isReady = true;
|
||||
while (children.hasMoreElements()) {
|
||||
expand(tree, path.pathByAddingChild(children.nextElement()) , levels - 1);
|
||||
if (!expand(tree, path.pathByAddingChild(children.nextElement()) , levels - 1))
|
||||
isReady = false;
|
||||
}
|
||||
return isReady;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user