Search in sources :

Example 1 with ModuleGroup

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

the class ModuleStructureConfigurable method addModuleNode.

private void addModuleNode(final Module module) {
    final TreePath selectionPath = myTree.getSelectionPath();
    MyNode parent = null;
    if (selectionPath != null) {
        MyNode selected = (MyNode) selectionPath.getLastPathComponent();
        final Object o = selected.getConfigurable().getEditableObject();
        if (o instanceof ModuleGroup) {
            myContext.myModulesConfigurator.getModuleModel().setModuleGroupPath(module, ((ModuleGroup) o).getGroupPath());
            parent = selected;
        } else if (o instanceof Module) {
            //create near selected
            final ModifiableModuleModel modifiableModuleModel = myContext.myModulesConfigurator.getModuleModel();
            final String[] groupPath = modifiableModuleModel.getModuleGroupPath((Module) o);
            if (groupPath != null) {
                modifiableModuleModel.setModuleGroupPath(module, groupPath);
                parent = findNodeByObject(myRoot, new ModuleGroup(Arrays.asList(groupPath)));
            }
        }
    }
    if (parent == null)
        parent = myRoot;
    MyNode node = createModuleNode(module, getModuleGrouper());
    TreeUtil.insertNode(node, parent, getTreeModel(), getNodeComparator());
    selectNodeInTree(node);
    final ProjectStructureDaemonAnalyzer daemonAnalyzer = myContext.getDaemonAnalyzer();
    daemonAnalyzer.queueUpdate(new ModuleProjectStructureElement(myContext, module));
    //missing modules added
    daemonAnalyzer.queueUpdateForAllElementsWithErrors();
}
Also used : ProjectStructureDaemonAnalyzer(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer) ModuleProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup)

Example 2 with ModuleGroup

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

the class DirectoryChooserModuleTreeView method addItem.

@Override
public void addItem(DirectoryChooser.ItemWrapper itemWrapper) {
    myItems.add(itemWrapper);
    final PsiDirectory directory = itemWrapper.getDirectory();
    final Module module = myFileIndex.getModuleForFile(directory.getVirtualFile());
    DefaultMutableTreeNode node = myModuleNodes.get(module);
    if (node == null) {
        node = new DefaultMutableTreeNode(module, true);
        final List<String> groupPath = module != null ? myModuleGrouper.getGroupPath(module) : null;
        if (groupPath == null || groupPath.isEmpty()) {
            insertNode(node, myRootNode);
        } else {
            final DefaultMutableTreeNode parentNode = ModuleGroupUtil.buildModuleGroupPath(new ModuleGroup(groupPath), myRootNode, myModuleGroupNodes, parentChildRelation -> insertNode(parentChildRelation.getChild(), parentChildRelation.getParent()), moduleGroup -> new DefaultMutableTreeNode(moduleGroup, true));
            insertNode(node, parentNode);
        }
        myModuleNodes.put(module, node);
    }
    final DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(itemWrapper, false);
    myItemNodes.put(itemWrapper, itemNode);
    insertNode(itemNode, node);
    ((DefaultTreeModel) myTree.getModel()).nodeStructureChanged(node);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup)

Example 3 with ModuleGroup

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

the class AddToFavoritesAction method createNodes.

@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
    if (project == null)
        return Collections.emptyList();
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
        final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
        if (treeNode != null) {
            result.add(treeNode);
            return result;
        }
    }
    final PsiManager psiManager = PsiManager.getInstance(project);
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
    //on psi elements
    if (object instanceof PsiElement[]) {
        for (PsiElement psiElement : (PsiElement[]) object) {
            addPsiElementNode(psiElement, project, result, favoritesConfig);
        }
        return result;
    }
    //on psi element
    if (object instanceof PsiElement) {
        Module containingModule = null;
        if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
            if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
                AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
                while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
                    abstractTreeNode = abstractTreeNode.getParent();
                }
                if (abstractTreeNode != null) {
                    containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
                }
            }
        }
        addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
        return result;
    }
    if (object instanceof VirtualFile[]) {
        for (VirtualFile vFile : (VirtualFile[]) object) {
            PsiElement element = psiManager.findFile(vFile);
            if (element == null)
                element = psiManager.findDirectory(vFile);
            addPsiElementNode(element, project, result, favoritesConfig);
        }
        return result;
    }
    //on form in editor
    if (object instanceof VirtualFile) {
        final VirtualFile vFile = (VirtualFile) object;
        final PsiFile psiFile = psiManager.findFile(vFile);
        addPsiElementNode(psiFile, project, result, favoritesConfig);
        return result;
    }
    //on module groups
    if (object instanceof ModuleGroup[]) {
        for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
            result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
        }
        return result;
    }
    //on module nodes
    if (object instanceof Module)
        object = new Module[] { (Module) object };
    if (object instanceof Module[]) {
        for (Module module1 : (Module[]) object) {
            result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
        }
        return result;
    }
    //on library group node
    if (object instanceof LibraryGroupElement[]) {
        for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
            result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
        }
        return result;
    }
    //on named library node
    if (object instanceof NamedLibraryElement[]) {
        for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
            result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
        }
        return result;
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ModuleGroup

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

the class MoveModulesToSubGroupAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
    final List<String> newGroup;
    if (myModuleGroup != null) {
        String message = IdeBundle.message("prompt.specify.name.of.module.subgroup", myModuleGroup.presentableText(), whatToMove(modules));
        String subgroup = Messages.showInputDialog(message, IdeBundle.message("title.module.sub.group"), Messages.getQuestionIcon());
        if (subgroup == null || "".equals(subgroup.trim()))
            return;
        newGroup = ContainerUtil.append(myModuleGroup.getGroupPathList(), subgroup);
    } else {
        String message = IdeBundle.message("prompt.specify.module.group.name", whatToMove(modules));
        String group = Messages.showInputDialog(message, IdeBundle.message("title.module.group"), Messages.getQuestionIcon());
        if (group == null || "".equals(group.trim()))
            return;
        newGroup = Collections.singletonList(group);
    }
    doMove(modules, new ModuleGroup(newGroup), dataContext);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) Module(com.intellij.openapi.module.Module) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup)

Example 5 with ModuleGroup

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

the class AbstractProjectNode method modulesAndGroups.

protected Collection<AbstractTreeNode> modulesAndGroups(Module[] modules) {
    Map<String, List<Module>> groups = new THashMap<>();
    List<Module> nonGroupedModules = new ArrayList<>(Arrays.asList(modules));
    for (final Module module : modules) {
        final String[] path = ModuleManager.getInstance(getProject()).getModuleGroupPath(module);
        if (path != null) {
            final String topLevelGroupName = path[0];
            groups.computeIfAbsent(topLevelGroupName, k -> new ArrayList<>()).add(module);
            nonGroupedModules.remove(module);
        }
    }
    List<AbstractTreeNode> result = new ArrayList<>();
    try {
        for (String groupPath : groups.keySet()) {
            result.add(createModuleGroupNode(new ModuleGroup(Collections.singletonList(groupPath))));
        }
        for (Module module : nonGroupedModules) {
            result.add(createModuleGroup(module));
        }
    } catch (Exception e) {
        LOG.error(e);
        return new ArrayList<>();
    }
    return result;
}
Also used : PlatformIcons(com.intellij.util.PlatformIcons) java.util(java.util) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) THashMap(gnu.trove.THashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) PresentationData(com.intellij.ide.projectView.PresentationData) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) VfsUtil(com.intellij.openapi.vfs.VfsUtil) ViewSettings(com.intellij.ide.projectView.ViewSettings) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) NotNull(org.jetbrains.annotations.NotNull) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) InvocationTargetException(java.lang.reflect.InvocationTargetException) THashMap(gnu.trove.THashMap) Module(com.intellij.openapi.module.Module)

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