Search in sources :

Example 1 with ModuleGrouper

use of com.intellij.openapi.module.ModuleGrouper in project intellij-community by JetBrains.

the class MoveModuleToGroup method getChildren.

@Override
@NotNull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e == null)
        return EMPTY_ARRAY;
    Project project = getEventProject(e);
    if (project == null)
        return EMPTY_ARRAY;
    ModifiableModuleModel modifiableModuleModel = LangDataKeys.MODIFIABLE_MODULE_MODEL.getData(e.getDataContext());
    List<AnAction> result = new ArrayList<>();
    result.add(new MoveModulesToGroupAction(myModuleGroup, IdeBundle.message("action.move.module.to.this.group")));
    result.add(new MoveModulesToSubGroupAction(myModuleGroup));
    result.add(Separator.getInstance());
    ModuleGrouper grouper = ModuleGrouper.instanceFor(project, modifiableModuleModel);
    result.addAll(myModuleGroup.childGroups(grouper).stream().sorted((moduleGroup1, moduleGroup2) -> {
        assert moduleGroup1.getGroupPath().length == moduleGroup2.getGroupPath().length;
        return moduleGroup1.toString().compareToIgnoreCase(moduleGroup2.toString());
    }).map(MoveModuleToGroup::new).collect(Collectors.toList()));
    return result.toArray(new AnAction[result.size()]);
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IdeBundle(com.intellij.ide.IdeBundle) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) Project(com.intellij.openapi.project.Project) MoveModulesToSubGroupAction(com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) MoveModulesToGroupAction(com.intellij.ide.projectView.actions.MoveModulesToGroupAction) Project(com.intellij.openapi.project.Project) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ArrayList(java.util.ArrayList) MoveModulesToGroupAction(com.intellij.ide.projectView.actions.MoveModulesToGroupAction) MoveModulesToSubGroupAction(com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ModuleGrouper

use of com.intellij.openapi.module.ModuleGrouper 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 3 with ModuleGrouper

use of com.intellij.openapi.module.ModuleGrouper in project intellij-community by JetBrains.

the class ModulesAndLibrariesSourceItemsProvider method createModuleItems.

@NotNull
private static Collection<? extends PackagingSourceItem> createModuleItems(@NotNull ArtifactEditorContext editorContext, @NotNull List<String> groupPath) {
    final List<PackagingSourceItem> items = new ArrayList<>();
    ModuleGrouper grouper = ModuleGrouper.instanceFor(editorContext.getProject(), editorContext.getModifiableModuleModel());
    Set<String> groups = new HashSet<>();
    for (Module module : grouper.getAllModules()) {
        List<String> path = grouper.getGroupPath(module);
        if (Comparing.equal(path, groupPath)) {
            items.add(new ModuleSourceItemGroup(module));
        } else if (ContainerUtil.startsWith(path, groupPath)) {
            groups.add(path.get(groupPath.size()));
        }
    }
    for (String group : groups) {
        items.add(0, new ModuleGroupItem(ContainerUtil.append(groupPath, group)));
    }
    return items;
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ModuleGrouper

use of com.intellij.openapi.module.ModuleGrouper in project intellij-community by JetBrains.

the class PluginDescriptorChooser method createCandidates.

private static List<PluginDescriptorCandidate> createCandidates(final Module currentModule, List<DomFileElement<IdeaPlugin>> elements) {
    ModuleGrouper grouper = ModuleGrouper.instanceFor(currentModule.getProject());
    final List<String> groupPath = grouper.getGroupPath(currentModule);
    elements.sort((o1, o2) -> {
        // current module = first group
        final Module module1 = o1.getModule();
        final Module module2 = o2.getModule();
        if (currentModule.equals(module1))
            return -1;
        if (currentModule.equals(module2))
            return 1;
        if (module1 != null && module2 != null) {
            int groupComparison = Comparing.compare(groupMatchLevel(groupPath, grouper.getGroupPath(module2)), groupMatchLevel(groupPath, grouper.getGroupPath(module1)));
            if (groupComparison != 0) {
                return groupComparison;
            }
        }
        return ModulesAlphaComparator.INSTANCE.compare(module1, module2);
    });
    elements.sort((o1, o2) -> {
        if (!Comparing.equal(o1.getModule(), o2.getModule()))
            return 0;
        String pluginId1 = o1.getRootElement().getPluginId();
        String pluginId2 = o2.getRootElement().getPluginId();
        if (pluginId1 == null && pluginId2 == null) {
            return o1.getFile().getName().compareTo(o2.getFile().getName());
        }
        if (pluginId1 == null)
            return 1;
        if (pluginId2 == null)
            return -1;
        return Comparing.compare(pluginId1, pluginId2);
    });
    return ContainerUtil.map(elements, new Function<DomFileElement<IdeaPlugin>, PluginDescriptorCandidate>() {

        private Module myLastModule = currentModule;

        @Override
        public PluginDescriptorCandidate fun(DomFileElement<IdeaPlugin> element) {
            final Module module = element.getModule();
            boolean startsNewGroup = !myLastModule.equals(module);
            myLastModule = module;
            return new PluginDescriptorCandidate(element, startsNewGroup);
        }
    });
}
Also used : ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) DomFileElement(com.intellij.util.xml.DomFileElement) Module(com.intellij.openapi.module.Module)

Example 5 with ModuleGrouper

use of com.intellij.openapi.module.ModuleGrouper in project intellij-community by JetBrains.

the class MoveModuleToGroupTopLevel method getChildren.

@Override
@NotNull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e == null)
        return EMPTY_ARRAY;
    Project project = getEventProject(e);
    if (project == null)
        return EMPTY_ARRAY;
    ModifiableModuleModel moduleModel = LangDataKeys.MODIFIABLE_MODULE_MODEL.getData(e.getDataContext());
    ModuleGrouper grouper = ModuleGrouper.instanceFor(project, moduleModel);
    List<String> topLevelGroupNames = new ArrayList<>(getTopLevelGroupNames(grouper));
    Collections.sort(topLevelGroupNames);
    List<AnAction> result = new ArrayList<>();
    result.add(new MoveModulesOutsideGroupAction());
    result.add(new MoveModulesToSubGroupAction(null));
    result.add(Separator.getInstance());
    for (String name : topLevelGroupNames) {
        result.add(new MoveModuleToGroup(new ModuleGroup(Collections.singletonList(name))));
    }
    return result.toArray(new AnAction[result.size()]);
}
Also used : Project(com.intellij.openapi.project.Project) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) MoveModulesOutsideGroupAction(com.intellij.ide.projectView.actions.MoveModulesOutsideGroupAction) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) MoveModulesToSubGroupAction(com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ModuleGrouper (com.intellij.openapi.module.ModuleGrouper)5 Module (com.intellij.openapi.module.Module)4 NotNull (org.jetbrains.annotations.NotNull)4 MoveModulesToSubGroupAction (com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction)2 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)2 Project (com.intellij.openapi.project.Project)2 IdeBundle (com.intellij.ide.IdeBundle)1 MoveModulesOutsideGroupAction (com.intellij.ide.projectView.actions.MoveModulesOutsideGroupAction)1 MoveModulesToGroupAction (com.intellij.ide.projectView.actions.MoveModulesToGroupAction)1 ModuleGroup (com.intellij.ide.projectView.impl.ModuleGroup)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)1 DomFileElement (com.intellij.util.xml.DomFileElement)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Nullable (org.jetbrains.annotations.Nullable)1 IdeaPlugin (org.jetbrains.idea.devkit.dom.IdeaPlugin)1