Search in sources :

Example 6 with ModuleType

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

the class ProjectTypeStep method fillTemplatesMap.

private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {
    List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
    if (context.isCreatingNewProject()) {
        builders.add(new EmptyModuleBuilder());
    }
    Map<String, TemplatesGroup> groupMap = new HashMap<>();
    for (ModuleBuilder builder : builders) {
        BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
        if (builder.isTemplate()) {
            TemplatesGroup group = groupMap.get(builder.getGroupName());
            if (group == null) {
                group = new TemplatesGroup(builder);
            }
            myTemplatesMap.putValue(group, template);
        } else {
            TemplatesGroup group = new TemplatesGroup(builder);
            groupMap.put(group.getName(), group);
            myTemplatesMap.put(group, new ArrayList<>());
        }
    }
    MultiMap<TemplatesGroup, ProjectTemplate> map = getTemplatesMap(context);
    myTemplatesMap.putAllValues(map);
    for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) {
        TemplatesGroup group = new TemplatesGroup(category);
        myTemplatesMap.remove(group);
        myTemplatesMap.put(group, new ArrayList<>());
    }
    if (context.isCreatingNewProject()) {
        MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates();
        for (TemplatesGroup group : myTemplatesMap.keySet()) {
            myTemplatesMap.putValues(group, localTemplates.get(group.getId()));
        }
    }
    List<TemplatesGroup> groups = new ArrayList<>(myTemplatesMap.keySet());
    // sorting by module type popularity
    final MultiMap<ModuleType, TemplatesGroup> moduleTypes = new MultiMap<>();
    for (TemplatesGroup group : groups) {
        ModuleType type = getModuleType(group);
        moduleTypes.putValue(type, group);
    }
    Collections.sort(groups, (o1, o2) -> {
        int i = o2.getWeight() - o1.getWeight();
        if (i != 0)
            return i;
        int i1 = moduleTypes.get(getModuleType(o2)).size() - moduleTypes.get(getModuleType(o1)).size();
        if (i1 != 0)
            return i1;
        return o1.compareTo(o2);
    });
    Set<String> groupNames = ContainerUtil.map2Set(groups, TemplatesGroup::getParentGroup);
    // move subgroups
    MultiMap<String, TemplatesGroup> subGroups = new MultiMap<>();
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
        TemplatesGroup group = iterator.next();
        String parentGroup = group.getParentGroup();
        if (parentGroup != null && groupNames.contains(parentGroup) && !group.getName().equals(parentGroup) && groupMap.containsKey(parentGroup)) {
            subGroups.putValue(parentGroup, group);
            iterator.remove();
        }
    }
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
        TemplatesGroup group = iterator.next();
        for (TemplatesGroup subGroup : subGroups.get(group.getName())) {
            iterator.add(subGroup);
        }
    }
    // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593)
    if (PlatformUtils.isIdeaCommunity()) {
        for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
            TemplatesGroup group = iterator.next();
            if (WebModuleTypeBase.WEB_MODULE.equals(group.getId()) && myTemplatesMap.get(group).isEmpty()) {
                iterator.remove();
                break;
            }
        }
    }
    return groups;
}
Also used : THashMap(gnu.trove.THashMap) HashMap(java.util.HashMap) ModuleType(com.intellij.openapi.module.ModuleType) ProjectTemplate(com.intellij.platform.ProjectTemplate)

Example 7 with ModuleType

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

the class AddFacetToModuleAction method isVisible.

public static boolean isVisible(FacetEditorFacade editor, final FacetType<?, ?> type) {
    final ModuleType moduleType = editor.getSelectedModuleType();
    if (moduleType == null || !type.isSuitableModuleType(moduleType)) {
        return false;
    }
    final FacetTypeId<?> underlyingTypeId = type.getUnderlyingFacetType();
    final FacetInfo selectedFacet = editor.getSelectedFacetInfo();
    if (selectedFacet == null) {
        return underlyingTypeId == null && canAddFacet(null, type, editor);
    }
    final FacetTypeId selectedFacetType = selectedFacet.getFacetType().getId();
    if (selectedFacetType == underlyingTypeId) {
        return canAddFacet(selectedFacet, type, editor);
    }
    final FacetInfo parent = editor.getParent(selectedFacet);
    if (!canAddFacet(parent, type, editor)) {
        return false;
    }
    return parent == null && underlyingTypeId == null || parent != null && parent.getFacetType().getId() == underlyingTypeId;
}
Also used : ModuleType(com.intellij.openapi.module.ModuleType)

Example 8 with ModuleType

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

the class MavenModuleImporter method configFacets.

public void configFacets(final List<MavenProjectsProcessorTask> postTasks) {
    MavenUtil.smartInvokeAndWait(myModule.getProject(), ModalityState.defaultModalityState(), () -> {
        if (myModule.isDisposed())
            return;
        final ModuleType moduleType = ModuleType.get(myModule);
        ApplicationManager.getApplication().runWriteAction(() -> {
            for (final MavenImporter importer : getSuitableImporters()) {
                final MavenProjectChanges changes;
                if (myMavenProjectChanges == null) {
                    if (importer.processChangedModulesOnly())
                        continue;
                    changes = MavenProjectChanges.NONE;
                } else {
                    changes = myMavenProjectChanges;
                }
                if (importer.getModuleType() == moduleType) {
                    importer.process(myModifiableModelsProvider, myModule, myRootModelAdapter, myMavenTree, myMavenProject, changes, myMavenProjectToModuleName, postTasks);
                }
            }
        });
    });
}
Also used : ModuleType(com.intellij.openapi.module.ModuleType)

Aggregations

ModuleType (com.intellij.openapi.module.ModuleType)8 Facet (com.intellij.facet.Facet)1 InvalidFacetType (com.intellij.facet.impl.invalid.InvalidFacetType)1 DetectedContentRoot (com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot)1 DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)1 DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)1 ProjectStructureDetector (com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)1 JavaModuleType (com.intellij.openapi.module.JavaModuleType)1 Module (com.intellij.openapi.module.Module)1 ProjectTemplate (com.intellij.platform.ProjectTemplate)1 PythonModuleTypeBase (com.jetbrains.python.PythonModuleTypeBase)1 PythonFacetSettings (com.jetbrains.python.facet.PythonFacetSettings)1 THashMap (gnu.trove.THashMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FacetState (org.jetbrains.jps.model.serialization.facet.FacetState)1