Search in sources :

Example 1 with NamedLibraryElement

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

the class NamedLibraryUrl method createUrlByElement.

@Override
public AbstractUrl createUrlByElement(Object element) {
    if (element instanceof NamedLibraryElement) {
        NamedLibraryElement libraryElement = (NamedLibraryElement) element;
        Module context = libraryElement.getModule();
        return new NamedLibraryUrl(libraryElement.getOrderEntry().getPresentableName(), context != null ? context.getName() : null);
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) Module(com.intellij.openapi.module.Module)

Example 2 with NamedLibraryElement

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement 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 3 with NamedLibraryElement

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement 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 4 with NamedLibraryElement

use of com.intellij.ide.projectView.impl.nodes.NamedLibraryElement 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)

Example 5 with NamedLibraryElement

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

the class PyTreeStructureProvider method getPythonSdk.

@Nullable
private static Sdk getPythonSdk(@NotNull AbstractTreeNode node) {
    if (node instanceof NamedLibraryElementNode) {
        final NamedLibraryElement value = ((NamedLibraryElementNode) node).getValue();
        if (value != null) {
            final LibraryOrSdkOrderEntry entry = value.getOrderEntry();
            if (entry instanceof JdkOrderEntry) {
                final Sdk sdk = ((JdkOrderEntry) entry).getJdk();
                final SdkTypeId type = sdk.getSdkType();
                if (type instanceof PythonSdkType) {
                    return sdk;
                }
            }
        }
    }
    return null;
}
Also used : NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrSdkOrderEntry(com.intellij.openapi.roots.LibraryOrSdkOrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)7 Module (com.intellij.openapi.module.Module)4 LibraryGroupElement (com.intellij.ide.projectView.impl.nodes.LibraryGroupElement)3 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)2 LibraryOrSdkOrderEntry (com.intellij.openapi.roots.LibraryOrSdkOrderEntry)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 ModuleGroup (com.intellij.ide.projectView.impl.ModuleGroup)1 ExternalLibrariesNode (com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 FlexCompositeSdk (com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk)1 Project (com.intellij.openapi.project.Project)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiFile (com.intellij.psi.PsiFile)1