Search in sources :

Example 26 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class FileStructurePopup method navigateSelectedElement.

public boolean navigateSelectedElement() {
    final AbstractTreeNode selectedNode = getSelectedNode();
    if (ApplicationManager.getApplication().isInternal()) {
        String enteredPrefix = getSpeedSearch().getEnteredPrefix();
        String itemText = getSpeedSearchText(selectedNode);
        if (StringUtil.isNotEmpty(enteredPrefix) && StringUtil.isNotEmpty(itemText)) {
            LOG.info("Chosen in file structure popup by prefix '" + enteredPrefix + "': '" + itemText + "'");
        }
    }
    final Ref<Boolean> succeeded = new Ref<>();
    final CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(myProject, () -> {
        if (selectedNode != null) {
            if (selectedNode.canNavigateToSource()) {
                myPopup.cancel();
                selectedNode.navigate(true);
                succeeded.set(true);
            } else {
                succeeded.set(false);
            }
        } else {
            succeeded.set(false);
        }
        IdeDocumentHistory.getInstance(myProject).includeCurrentCommandAsNavigation();
    }, "Navigate", null);
    return succeeded.get();
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) CommandProcessor(com.intellij.openapi.command.CommandProcessor)

Example 27 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class ProjectViewNode method someChildContainsFile.

public boolean someChildContainsFile(final VirtualFile file, boolean optimizeByCheckingFileRootsFirst) {
    VirtualFile parent = file.getParent();
    boolean mayContain = false;
    if (optimizeByCheckingFileRootsFirst && parent != null) {
        Collection<VirtualFile> roots = getRoots();
        for (VirtualFile eachRoot : roots) {
            if (parent.equals(eachRoot.getParent())) {
                mayContain = true;
                break;
            }
            if (VfsUtilCore.isAncestor(eachRoot, file, true)) {
                mayContain = true;
                break;
            }
        }
    } else {
        mayContain = true;
    }
    if (!mayContain) {
        return false;
    }
    Collection<? extends AbstractTreeNode> kids = getChildren();
    for (final AbstractTreeNode kid : kids) {
        ProjectViewNode node = (ProjectViewNode) kid;
        if (node.contains(file))
            return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 28 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class MigrationPanel method selectionChanged.

private void selectionChanged() {
    myConflictsPanel.setToInitialPosition();
    myUsagesPanel.setToInitialPosition();
    final DefaultMutableTreeNode[] migrationNodes = myRootsTree.getSelectedNodes(DefaultMutableTreeNode.class, null);
    if (migrationNodes.length == 0)
        return;
    final Object userObject = migrationNodes[0].getUserObject();
    if (userObject instanceof MigrationNode) {
        final MigrationNode migrationNode = (MigrationNode) userObject;
        final UsageInfo[] failedUsages = myLabeler.getFailedUsages(migrationNode.getInfo());
        if (failedUsages.length > 0) {
            myConflictsPanel.showUsages(PsiElement.EMPTY_ARRAY, failedUsages);
        }
        final AbstractTreeNode rootNode = migrationNode.getParent();
        if (rootNode instanceof MigrationNode) {
            myUsagesPanel.showRootUsages(((MigrationNode) rootNode).getInfo(), migrationNode.getInfo(), myLabeler);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) UsageInfo(com.intellij.usageView.UsageInfo) TypeMigrationUsageInfo(com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo)

Example 29 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class AddToFavoritesAction method getNodesToAdd.

@NotNull
public static Collection<AbstractTreeNode> getNodesToAdd(final DataContext dataContext, final boolean inProjectView) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return Collections.emptyList();
    Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    Collection<AbstractTreeNode> nodesToAdd = null;
    for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
        nodesToAdd = provider.getFavoriteNodes(dataContext, ViewSettings.DEFAULT);
        if (nodesToAdd != null) {
            break;
        }
    }
    if (nodesToAdd == null) {
        Object elements = collectSelectedElements(dataContext);
        if (elements != null) {
            nodesToAdd = createNodes(project, moduleContext, elements, inProjectView, ViewSettings.DEFAULT);
        }
    }
    return nodesToAdd == null ? Collections.<AbstractTreeNode>emptyList() : nodesToAdd;
}
Also used : Project(com.intellij.openapi.project.Project) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class AddToFavoritesAction method createNodes.

@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
    if (project == null)
        return Collections.emptyList();
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
        final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
        if (treeNode != null) {
            result.add(treeNode);
            return result;
        }
    }
    final PsiManager psiManager = PsiManager.getInstance(project);
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
    //on psi elements
    if (object instanceof PsiElement[]) {
        for (PsiElement psiElement : (PsiElement[]) object) {
            addPsiElementNode(psiElement, project, result, favoritesConfig);
        }
        return result;
    }
    //on psi element
    if (object instanceof PsiElement) {
        Module containingModule = null;
        if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
            if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
                AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
                while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
                    abstractTreeNode = abstractTreeNode.getParent();
                }
                if (abstractTreeNode != null) {
                    containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
                }
            }
        }
        addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
        return result;
    }
    if (object instanceof VirtualFile[]) {
        for (VirtualFile vFile : (VirtualFile[]) object) {
            PsiElement element = psiManager.findFile(vFile);
            if (element == null)
                element = psiManager.findDirectory(vFile);
            addPsiElementNode(element, project, result, favoritesConfig);
        }
        return result;
    }
    //on form in editor
    if (object instanceof VirtualFile) {
        final VirtualFile vFile = (VirtualFile) object;
        final PsiFile psiFile = psiManager.findFile(vFile);
        addPsiElementNode(psiFile, project, result, favoritesConfig);
        return result;
    }
    //on module groups
    if (object instanceof ModuleGroup[]) {
        for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
            result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
        }
        return result;
    }
    //on module nodes
    if (object instanceof Module)
        object = new Module[] { (Module) object };
    if (object instanceof Module[]) {
        for (Module module1 : (Module[]) object) {
            result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
        }
        return result;
    }
    //on library group node
    if (object instanceof LibraryGroupElement[]) {
        for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
            result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
        }
        return result;
    }
    //on named library node
    if (object instanceof NamedLibraryElement[]) {
        for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
            result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
        }
        return result;
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)154 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)43 Project (com.intellij.openapi.project.Project)36 PsiFile (com.intellij.psi.PsiFile)31 Module (com.intellij.openapi.module.Module)29 PsiDirectory (com.intellij.psi.PsiDirectory)27 PsiElement (com.intellij.psi.PsiElement)17 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 PsiManager (com.intellij.psi.PsiManager)11 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)10 List (java.util.List)10 PresentationData (com.intellij.ide.projectView.PresentationData)6 ViewSettings (com.intellij.ide.projectView.ViewSettings)6 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)6 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)5 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5