Search in sources :

Example 6 with ModuleGroup

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

the class ModuleGroupNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    ModuleGrouper grouper = ModuleGrouper.instanceFor(getProject());
    final Collection<ModuleGroup> childGroups = getValue().childGroups(grouper);
    final List<AbstractTreeNode> result = new ArrayList<>();
    for (final ModuleGroup childGroup : childGroups) {
        result.add(createModuleGroupNode(childGroup));
    }
    Collection<Module> modules = getValue().modulesInGroup(grouper, false);
    try {
        for (Module module : modules) {
            result.add(createModuleNode(module));
        }
    } catch (Exception e) {
        LOG.error(e);
    }
    return result;
}
Also used : ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) Module(com.intellij.openapi.module.Module) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ModuleGroup

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

the class PsiPackageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return null;
    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
    if (elements == null) {
        final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
        if (element != null) {
            elements = new PsiElement[] { element };
        }
    }
    final Collection<AbstractTreeNode> result = new ArrayList<>();
    if (elements != null) {
        for (PsiElement element : elements) {
            if (element instanceof PsiPackage) {
                final PsiPackage psiPackage = (PsiPackage) element;
                final PsiDirectory[] directories = psiPackage.getDirectories();
                if (directories.length > 0) {
                    final VirtualFile firstDir = directories[0].getVirtualFile();
                    final boolean isLibraryRoot = ProjectRootsUtil.isLibraryRoot(firstDir, project);
                    final PackageElement packageElement = new PackageElement(LangDataKeys.MODULE.getData(context), psiPackage, isLibraryRoot);
                    result.add(new PackageElementNode(project, packageElement, viewSettings));
                }
            }
        }
        return result.isEmpty() ? null : result;
    }
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(context);
    if (modules != null) {
        for (Module module : modules) {
            if (PackageViewPane.ID.equals(currentViewId)) {
                result.add(new PackageViewModuleNode(project, module, viewSettings));
            } else {
                result.add(new ProjectViewModuleNode(project, module, viewSettings));
            }
        }
    } else {
        final ModuleGroup[] data = ModuleGroup.ARRAY_DATA_KEY.getData(context);
        if (data != null) {
            for (ModuleGroup moduleGroup : data) {
                if (PackageViewPane.ID.equals(currentViewId)) {
                    result.add(new PackageViewModuleGroupNode(project, moduleGroup, viewSettings));
                } else {
                    result.add(new ProjectViewModuleGroupNode(project, moduleGroup, viewSettings));
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 8 with ModuleGroup

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

ModuleGroup (com.intellij.ide.projectView.impl.ModuleGroup)8 Module (com.intellij.openapi.module.Module)7 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 FavoriteNodeProvider (com.intellij.ide.favoritesTreeView.FavoriteNodeProvider)1 PresentationData (com.intellij.ide.projectView.PresentationData)1 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)1 LibraryGroupElement (com.intellij.ide.projectView.impl.nodes.LibraryGroupElement)1 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ModuleGrouper (com.intellij.openapi.module.ModuleGrouper)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1