Search in sources :

Example 91 with AbstractTreeNode

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

the class UsageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
        return null;
    }
    final Usage[] usages = UsageView.USAGES_KEY.getData(context);
    if (usages != null) {
        final List<AbstractTreeNode> result = new SmartList<>();
        final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
        final List<Usage> nonMapped = new ArrayList<>();
        for (Usage usage : usages) {
            if (usage instanceof UsageInFile) {
                map.putValue(((UsageInFile) usage).getFile(), usage);
            } else if (usage instanceof UsageInFiles) {
                final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
                for (VirtualFile file : files) {
                    map.putValue(file, usage);
                }
            } else {
                nonMapped.add(usage);
            }
        }
        final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
        keys.addAll(map.keySet());
        for (VirtualFile key : keys) {
            final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
            result.add(grouping);
            final Collection<Usage> subUsages = map.get(key);
            for (Usage usage : subUsages) {
                if (usage instanceof UsageInfo2UsageAdapter) {
                    final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                    grouping.addChild(node);
                } else if (NullUsage.INSTANCE.equals(usage)) {
                    continue;
                } else {
                    grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
                }
            }
        }
        for (Usage usage : nonMapped) {
            if (usage instanceof UsageInfo2UsageAdapter) {
                final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                result.add(node);
            } else if (NullUsage.INSTANCE.equals(usage)) {
                continue;
            } else {
                result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
            }
        }
        return result;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NullUsage(com.intellij.usages.impl.NullUsage) Usage(com.intellij.usages.Usage) UsageInFiles(com.intellij.usages.rules.UsageInFiles) UsageInFile(com.intellij.usages.rules.UsageInFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) MultiMap(com.intellij.util.containers.MultiMap) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) SmartList(com.intellij.util.SmartList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UsageInFile(com.intellij.usages.rules.UsageInFile) File(java.io.File)

Example 92 with AbstractTreeNode

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

the class AddToFavoritesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Collection<AbstractTreeNode> nodesToAdd = getNodesToAdd(dataContext, true);
    if (!nodesToAdd.isEmpty()) {
        Project project = e.getProject();
        FavoritesManager.getInstance(project).addRoots(myFavoritesListName, nodesToAdd);
    }
}
Also used : Project(com.intellij.openapi.project.Project) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 93 with AbstractTreeNode

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

the class AddToNewFavoritesListAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    Collection<AbstractTreeNode> nodesToAdd = AddToFavoritesAction.getNodesToAdd(e.getDataContext(), true);
    if (!nodesToAdd.isEmpty()) {
        final String newName = AddNewFavoritesListAction.doAddNewFavoritesList(project);
        if (newName != null) {
            FavoritesManager.getInstance(project).addRoots(newName, nodesToAdd);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 94 with AbstractTreeNode

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

the class DeleteFromFavoritesAction method updateButton.

@Override
public void updateButton(AnActionEvent e) {
    e.getPresentation().setText(getTemplatePresentation().getText());
    final DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
    if (project == null || builder == null) {
        e.getPresentation().setEnabled(false);
        return;
    }
    Set<Object> selection = builder.getSelectedElements();
    String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
    if (listName == null) {
        //Selection is empty or contains several items under favorites/bookmarks/breakpoints at the same time
        e.getPresentation().setText(CommonActionsPanel.Buttons.REMOVE.getText());
        e.getPresentation().setEnabled(false);
        return;
    }
    FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    FavoritesListProvider provider = favoritesManager.getListProvider(listName);
    if (provider != null) {
        boolean willHandle = provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection);
        e.getPresentation().setEnabled(willHandle);
        if (willHandle) {
            e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.REMOVE));
        } else {
            e.getPresentation().setText(CommonActionsPanel.Buttons.REMOVE.getText());
        }
        return;
    }
    FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
    if (roots == null || roots.length == 0 || selection.isEmpty()) {
        e.getPresentation().setEnabled(false);
        return;
    }
    for (Object o : selection) {
        if (o instanceof AbstractTreeNode) {
            AbstractTreeNode node = (AbstractTreeNode) o;
            int deep = getDeep(node);
            if (deep != 2 && deep != 3) {
                //favorite list or it's nested "root"
                e.getPresentation().setEnabled(false);
                return;
            }
        } else {
            e.getPresentation().setEnabled(false);
            return;
        }
    }
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext)

Example 95 with AbstractTreeNode

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

the class SendToFavoritesAction method doSend.

public void doSend(final FavoritesManager favoritesManager, final FavoritesTreeNodeDescriptor[] roots, final String listName) {
    for (FavoritesTreeNodeDescriptor root : roots) {
        final AbstractTreeNode rootElement = root.getElement();
        String name = listName;
        if (name == null) {
            name = root.getFavoritesRoot().getName();
        }
        favoritesManager.removeRoot(name, Collections.singletonList(rootElement));
        favoritesManager.addRoots(toName, Collections.singletonList(rootElement));
    }
}
Also used : FavoritesTreeNodeDescriptor(com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)150 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)51 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 Project (com.intellij.openapi.project.Project)33 PsiFile (com.intellij.psi.PsiFile)30 Module (com.intellij.openapi.module.Module)27 PsiDirectory (com.intellij.psi.PsiDirectory)25 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)9 PsiManager (com.intellij.psi.PsiManager)9 List (java.util.List)9 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