use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-plugins by JetBrains.
the class DartTreeStructureProvider method modify.
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parentNode, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (parentNode instanceof ExternalLibrariesNode) {
return ContainerUtil.map(children, node -> {
if (node instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(node.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(node.getName()))) {
final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(node.getName());
return new NamedLibraryElementNode(node.getProject(), ((NamedLibraryElementNode) node).getValue(), settings) {
@Override
public boolean canNavigate() {
return isSdkRoot;
}
@Override
public void navigate(boolean requestFocus) {
final Project project = getProject();
if (project != null) {
DartConfigurable.openDartSettings(project);
}
}
};
}
return node;
});
}
if (parentNode instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(parentNode.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName()))) {
final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName());
return ContainerUtil.map(children, node -> {
final VirtualFile dir = node instanceof PsiDirectoryNode ? ((PsiDirectoryNode) node).getVirtualFile() : null;
if (dir != null && dir.isInLocalFileSystem() && dir.isDirectory() && (isSdkRoot || "lib".equals(dir.getName()))) {
return new DartSdkOrLibraryRootNode(node.getProject(), ((PsiDirectoryNode) node).getValue(), settings);
}
return node;
});
}
// root/packages/ThisProject and root/packages/PathPackage folders are excluded in dart projects (see DartProjectComponent.excludeBuildAndPackagesFolders),
// this provider adds location string tho these nodes in Project View like "ThisProject (ThisProject/lib)"
final Project project = parentNode.getProject();
final VirtualFile packagesDir = parentNode instanceof PsiDirectoryNode && project != null ? ((PsiDirectoryNode) parentNode).getVirtualFile() : null;
final VirtualFile parentFolder = packagesDir != null && packagesDir.isDirectory() && PACKAGES_FOLDER_NAME.equals(packagesDir.getName()) ? packagesDir.getParent() : null;
final VirtualFile pubspecYamlFile = parentFolder != null ? parentFolder.findChild(PUBSPEC_YAML) : null;
if (pubspecYamlFile != null && !pubspecYamlFile.isDirectory()) {
final ArrayList<AbstractTreeNode> modifiedChildren = new ArrayList<>(children);
final DartUrlResolver resolver = DartUrlResolver.getInstance(project, pubspecYamlFile);
resolver.processLivePackages((packageName, packageDir) -> {
final VirtualFile folder = packagesDir.findChild(packageName);
if (folder != null) {
final AbstractTreeNode node = getFolderNode(children, folder);
if (node == null) {
modifiedChildren.add(new SymlinkToLivePackageNode(project, packageName, packageDir));
} else {
node.getPresentation().setLocationString(getPackageLocationString(packageDir));
}
}
});
return modifiedChildren;
}
return children;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (!(parent instanceof PsiDirectoryNode))
return children;
final Collection<NestingRule> rules = getNestingRules();
if (rules.isEmpty())
return children;
final MultiMap<PsiFileNode, PsiFileNode> parentToChildren = calcParentToChildren(children, rules);
if (parentToChildren.isEmpty())
return children;
// initial ArrayList size may be not exact, not a big problem
final Collection<AbstractTreeNode> newChildren = new ArrayList<>(children.size() - parentToChildren.size());
final Set<PsiFileNode> childrenToMoveDown = new THashSet<>(parentToChildren.values());
for (AbstractTreeNode node : children) {
if (!(node instanceof PsiFileNode)) {
newChildren.add(node);
continue;
}
if (childrenToMoveDown.contains(node)) {
continue;
}
final Collection<PsiFileNode> childrenOfThisFile = parentToChildren.get((PsiFileNode) node);
if (childrenOfThisFile.isEmpty()) {
newChildren.add(node);
continue;
}
newChildren.add(new NestingTreeNode((PsiFileNode) node, childrenOfThisFile));
}
return newChildren;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.
the class AbstractProjectViewPSIPane method createComponent.
@Override
public JComponent createComponent() {
if (myComponent != null)
return myComponent;
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(null);
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
myTree = createTree(treeModel);
enableDnD();
myComponent = ScrollPaneFactory.createScrollPane(myTree);
if (Registry.is("error.stripe.enabled")) {
ErrorStripePainter painter = new ErrorStripePainter(true);
Disposer.register(this, new TreeUpdater<ErrorStripePainter>(painter, myComponent, myTree) {
@Override
protected void update(ErrorStripePainter painter, int index, Object object) {
if (object instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) object;
object = node.getUserObject();
}
if (object instanceof PsiDirectoryNode && !myTree.isCollapsed(index)) {
object = null;
}
super.update(painter, index, object);
}
@Override
protected ErrorStripe getErrorStripe(Object object) {
if (object instanceof PresentableNodeDescriptor) {
PresentableNodeDescriptor node = (PresentableNodeDescriptor) object;
PresentationData presentation = node.getPresentation();
TextAttributesKey key = presentation.getTextAttributesKey();
if (key != null) {
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
if (attributes != null && EffectType.WAVE_UNDERSCORE == attributes.getEffectType()) {
return ErrorStripe.create(attributes.getEffectColor(), 1);
}
}
}
return null;
}
});
}
myTreeStructure = createStructure();
BaseProjectTreeBuilder treeBuilder = createBuilder(treeModel);
installComparator(treeBuilder);
setTreeBuilder(treeBuilder);
initTree();
Disposer.register(getTreeBuilder(), new UiNotifyConnector(myTree, new Activatable() {
private boolean showing;
@Override
public void showNotify() {
if (!showing) {
showing = true;
restoreExpandedPaths();
}
}
@Override
public void hideNotify() {
if (showing) {
showing = false;
saveExpandedPaths();
}
}
}));
return myComponent;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.
the class PlatformProjectViewStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (parent instanceof PsiDirectoryNode) {
final VirtualFile vFile = ((PsiDirectoryNode) parent).getVirtualFile();
if (vFile != null && Comparing.equal(ProjectFileIndex.SERVICE.getInstance(myProject).getContentRootForFile(vFile), vFile)) {
final Collection<AbstractTreeNode> moduleChildren = ((PsiDirectoryNode) parent).getChildren();
Collection<AbstractTreeNode> result = new ArrayList<>();
for (AbstractTreeNode moduleChild : moduleChildren) {
if (moduleChild instanceof PsiDirectoryNode) {
final PsiDirectory value = ((PsiDirectoryNode) moduleChild).getValue();
if (value.getName().equals(Project.DIRECTORY_STORE_FOLDER) && Registry.is("projectView.hide.dot.idea")) {
continue;
}
}
result.add(moduleChild);
}
return result;
}
}
return children;
}
use of com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode in project intellij-community by JetBrains.
the class AbstractProjectViewPane method getSelectedDirectories.
@NotNull
public PsiDirectory[] getSelectedDirectories() {
List<PsiDirectory> directories = ContainerUtil.newArrayList();
for (PsiDirectoryNode node : getSelectedNodes(PsiDirectoryNode.class)) {
PsiDirectory directory = node.getValue();
if (directory != null) {
directories.add(directory);
Object parentValue = node.getParent().getValue();
if (parentValue instanceof PsiDirectory && Registry.is("projectView.choose.directory.on.compacted.middle.packages")) {
while (true) {
directory = directory.getParentDirectory();
if (directory == null || directory.equals(parentValue)) {
break;
}
directories.add(directory);
}
}
}
}
if (!directories.isEmpty()) {
return directories.toArray(new PsiDirectory[directories.size()]);
}
final PsiElement[] elements = getSelectedPSIElements();
if (elements.length == 1) {
final PsiElement element = elements[0];
if (element instanceof PsiDirectory) {
return new PsiDirectory[] { (PsiDirectory) element };
} else if (element instanceof PsiDirectoryContainer) {
return ((PsiDirectoryContainer) element).getDirectories();
} else {
final PsiFile containingFile = element.getContainingFile();
if (containingFile != null) {
final PsiDirectory psiDirectory = containingFile.getContainingDirectory();
if (psiDirectory != null) {
return new PsiDirectory[] { psiDirectory };
}
final VirtualFile file = containingFile.getVirtualFile();
if (file instanceof VirtualFileWindow) {
final VirtualFile delegate = ((VirtualFileWindow) file).getDelegate();
final PsiFile delegatePsiFile = containingFile.getManager().findFile(delegate);
if (delegatePsiFile != null && delegatePsiFile.getContainingDirectory() != null) {
return new PsiDirectory[] { delegatePsiFile.getContainingDirectory() };
}
}
return PsiDirectory.EMPTY_ARRAY;
}
}
} else {
final DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null) {
return getSelectedDirectoriesInAmbiguousCase(selectedNode);
}
}
return PsiDirectory.EMPTY_ARRAY;
}
Aggregations