Search in sources :

Example 1 with LibraryGroupElement

use of com.intellij.ide.projectView.impl.nodes.LibraryGroupElement in project intellij-community by JetBrains.

the class FavoritesManager method contains.

// currently only one level here..
public boolean contains(@NotNull String name, @NotNull final VirtualFile vFile) {
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    final Set<Boolean> find = new HashSet<>();
    final ContentIterator contentIterator = new ContentIterator() {

        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) {
                find.add(Boolean.TRUE);
            }
            return true;
        }
    };
    Collection<TreeItem<Pair<AbstractUrl, String>>> urls = getFavoritesListRootUrls(name);
    for (TreeItem<Pair<AbstractUrl, String>> pair : urls) {
        AbstractUrl abstractUrl = pair.getData().getFirst();
        if (abstractUrl == null) {
            continue;
        }
        final Object[] path = abstractUrl.createPath(myProject);
        if (path == null || path.length < 1 || path[0] == null) {
            continue;
        }
        Object element = path[path.length - 1];
        if (element instanceof SmartPsiElementPointer) {
            final VirtualFile virtualFile = PsiUtilBase.getVirtualFile(((SmartPsiElementPointer) element).getElement());
            if (virtualFile == null)
                continue;
            if (vFile.getPath().equals(virtualFile.getPath())) {
                return true;
            }
            if (!virtualFile.isDirectory()) {
                continue;
            }
            projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator);
        }
        if (element instanceof PsiElement) {
            final VirtualFile virtualFile = PsiUtilBase.getVirtualFile((PsiElement) element);
            if (virtualFile == null)
                continue;
            if (vFile.getPath().equals(virtualFile.getPath())) {
                return true;
            }
            if (!virtualFile.isDirectory()) {
                continue;
            }
            projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator);
        }
        if (element instanceof Module) {
            ModuleRootManager.getInstance((Module) element).getFileIndex().iterateContent(contentIterator);
        }
        if (element instanceof LibraryGroupElement) {
            final boolean inLibrary = ModuleRootManager.getInstance(((LibraryGroupElement) element).getModule()).getFileIndex().isInContent(vFile) && projectFileIndex.isInLibraryClasses(vFile);
            if (inLibrary) {
                return true;
            }
        }
        if (element instanceof NamedLibraryElement) {
            NamedLibraryElement namedLibraryElement = (NamedLibraryElement) element;
            final VirtualFile[] files = namedLibraryElement.getOrderEntry().getRootFiles(OrderRootType.CLASSES);
            if (files != null && ArrayUtil.find(files, vFile) > -1) {
                return true;
            }
        }
        if (element instanceof ModuleGroup) {
            ModuleGroup group = (ModuleGroup) element;
            final Collection<Module> modules = group.modulesInGroup(myProject, true);
            for (Module module : modules) {
                ModuleRootManager.getInstance(module).getFileIndex().iterateContent(contentIterator);
            }
        }
        for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
            if (provider.elementContainsFile(element, vFile)) {
                return true;
            }
        }
        if (!find.isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreeItem(com.intellij.util.TreeItem) LibraryGroupElement(com.intellij.ide.projectView.impl.nodes.LibraryGroupElement) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) Module(com.intellij.openapi.module.Module)

Example 2 with LibraryGroupElement

use of com.intellij.ide.projectView.impl.nodes.LibraryGroupElement in project intellij-community by JetBrains.

the class FavoritesTreeNodeDescriptor method getLocation.

public static String getLocation(final AbstractTreeNode element, @NotNull final Project project) {
    Object nodeElement = element.getValue();
    if (nodeElement instanceof SmartPsiElementPointer) {
        nodeElement = ((SmartPsiElementPointer) nodeElement).getElement();
    }
    if (nodeElement instanceof PsiElement) {
        if (nodeElement instanceof PsiDirectory) {
            return VfsUtilCore.getRelativeLocation(((PsiDirectory) nodeElement).getVirtualFile(), project.getBaseDir());
        }
        if (nodeElement instanceof PsiFile) {
            final PsiFile containingFile = (PsiFile) nodeElement;
            return VfsUtilCore.getRelativeLocation(containingFile.getVirtualFile(), project.getBaseDir());
        }
    }
    if (nodeElement instanceof LibraryGroupElement) {
        return ((LibraryGroupElement) nodeElement).getModule().getName();
    }
    if (nodeElement instanceof NamedLibraryElement) {
        final NamedLibraryElement namedLibraryElement = ((NamedLibraryElement) nodeElement);
        final Module module = namedLibraryElement.getModule();
        return (module != null ? module.getName() : "") + ":" + namedLibraryElement.getOrderEntry().getPresentableName();
    }
    if (nodeElement instanceof File) {
        return VfsUtilCore.getRelativeLocation(VfsUtil.findFileByIoFile((File) nodeElement, false), project.getBaseDir());
    }
    final FavoriteNodeProvider[] nodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project);
    for (FavoriteNodeProvider provider : nodeProviders) {
        String location = provider.getElementLocation(nodeElement);
        if (location != null)
            return location;
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) LibraryGroupElement(com.intellij.ide.projectView.impl.nodes.LibraryGroupElement)

Example 3 with LibraryGroupElement

use of com.intellij.ide.projectView.impl.nodes.LibraryGroupElement in project intellij-community by JetBrains.

the class CommanderPanel method getDataImpl.

public final Object getDataImpl(final String dataId) {
    if (myBuilder == null)
        return null;
    final Object selectedValue = getSelectedValue();
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement selectedElement = getSelectedElement();
        return selectedElement != null && selectedElement.isValid() ? selectedElement : null;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return filterInvalidElements(getSelectedElements());
    }
    if (LangDataKeys.PASTE_TARGET_PSI_ELEMENT.is(dataId)) {
        final AbstractTreeNode parentNode = myBuilder.getParentNode();
        final Object element = parentNode != null ? parentNode.getValue() : null;
        return element instanceof PsiElement && ((PsiElement) element).isValid() ? element : null;
    }
    if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        return getNavigatables();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCopyProvider() : null;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getCutProvider() : null;
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator != null ? myCopyPasteDelegator.getPasteProvider() : null;
    }
    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return myDeleteElementProvider;
    }
    if (LangDataKeys.MODULE.is(dataId)) {
        return selectedValue instanceof Module ? selectedValue : null;
    }
    if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof ModuleGroup ? new ModuleGroup[] { (ModuleGroup) selectedValue } : null;
    }
    if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof LibraryGroupElement ? new LibraryGroupElement[] { (LibraryGroupElement) selectedValue } : null;
    }
    if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
        return selectedValue instanceof NamedLibraryElement ? new NamedLibraryElement[] { (NamedLibraryElement) selectedValue } : null;
    }
    if (myProjectTreeStructure != null) {
        return myProjectTreeStructure.getDataFromProviders(getSelectedNodes(), dataId);
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) PsiElement(com.intellij.psi.PsiElement) LibraryGroupElement(com.intellij.ide.projectView.impl.nodes.LibraryGroupElement)

Aggregations

LibraryGroupElement (com.intellij.ide.projectView.impl.nodes.LibraryGroupElement)3 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)3 Module (com.intellij.openapi.module.Module)3 PsiElement (com.intellij.psi.PsiElement)2 ModuleGroup (com.intellij.ide.projectView.impl.ModuleGroup)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1 SmartPsiElementPointer (com.intellij.psi.SmartPsiElementPointer)1 TreeItem (com.intellij.util.TreeItem)1 File (java.io.File)1