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;
}
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;
}
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);
}
}
});
});
}
Aggregations