Search in sources :

Example 1 with SettingsProvider

use of com.intellij.ide.projectView.SettingsProvider in project intellij-community by JetBrains.

the class AbstractTreeStructureBase method getChildElements.

@Override
public Object[] getChildElements(Object element) {
    LOG.assertTrue(element instanceof AbstractTreeNode, element != null ? element.getClass().getName() : null);
    AbstractTreeNode<?> treeNode = (AbstractTreeNode) element;
    Collection<? extends AbstractTreeNode> elements = treeNode.getChildren();
    List<TreeStructureProvider> providers = getProvidersDumbAware();
    if (!providers.isEmpty()) {
        ViewSettings settings = treeNode instanceof SettingsProvider ? ((SettingsProvider) treeNode).getSettings() : ViewSettings.DEFAULT;
        for (TreeStructureProvider provider : providers) {
            try {
                elements = provider.modify(treeNode, (Collection<AbstractTreeNode>) elements, settings);
            } catch (ProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    for (AbstractTreeNode node : elements) {
        node.setParent(treeNode);
    }
    return ArrayUtil.toObjectArray(elements);
}
Also used : SettingsProvider(com.intellij.ide.projectView.SettingsProvider) ViewSettings(com.intellij.ide.projectView.ViewSettings) Collection(java.util.Collection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with SettingsProvider

use of com.intellij.ide.projectView.SettingsProvider in project intellij-community by JetBrains.

the class FavoritesTreeStructure method getChildElements.

@Override
public Object[] getChildElements(Object element) {
    if (!(element instanceof AbstractTreeNode)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final AbstractTreeNode favTreeElement = (AbstractTreeNode) element;
    try {
        if (!(element instanceof FavoritesListNode)) {
            Object[] elements = super.getChildElements(favTreeElement);
            if (elements.length > 0)
                return elements;
            ViewSettings settings = favTreeElement instanceof SettingsProvider ? ((SettingsProvider) favTreeElement).getSettings() : ViewSettings.DEFAULT;
            return ArrayUtil.toObjectArray(myNonProjectProvider.modify(favTreeElement, new ArrayList<>(), settings));
        }
        final List<AbstractTreeNode> result = new ArrayList<>();
        final FavoritesListNode listNode = (FavoritesListNode) element;
        if (listNode.getProvider() != null) {
            return ArrayUtil.toObjectArray(listNode.getChildren());
        }
        final Collection<AbstractTreeNode> roots = FavoritesListNode.getFavoritesRoots(myProject, listNode.getName(), listNode);
        for (AbstractTreeNode<?> abstractTreeNode : roots) {
            final Object value = abstractTreeNode.getValue();
            if (value == null)
                continue;
            if (value instanceof PsiElement && !((PsiElement) value).isValid())
                continue;
            if (value instanceof SmartPsiElementPointer && ((SmartPsiElementPointer) value).getElement() == null)
                continue;
            boolean invalid = false;
            for (FavoriteNodeProvider nodeProvider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
                if (nodeProvider.isInvalidElement(value)) {
                    invalid = true;
                    break;
                }
            }
            if (invalid)
                continue;
            result.add(abstractTreeNode);
        }
        //}
        return ArrayUtil.toObjectArray(result);
    } catch (Exception e) {
        LOGGER.error(e);
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ViewSettings(com.intellij.ide.projectView.ViewSettings) SettingsProvider(com.intellij.ide.projectView.SettingsProvider) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiElement(com.intellij.psi.PsiElement)

Aggregations

SettingsProvider (com.intellij.ide.projectView.SettingsProvider)2 ViewSettings (com.intellij.ide.projectView.ViewSettings)2 TreeStructureProvider (com.intellij.ide.projectView.TreeStructureProvider)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 PsiElement (com.intellij.psi.PsiElement)1 SmartPsiElementPointer (com.intellij.psi.SmartPsiElementPointer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1