public <Kk extends K, Vv extends V> void putAllValues(@NotNull MultiMap<Kk, Vv> from) { for (Map.Entry<Kk, Collection<Vv>> entry : from.entrySet()) { putValues(entry.getKey(), entry.getValue()); } }
private List<TemplatesGroup> fillTemplatesMap(WizardContext context) { List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders(); if (context.isCreatingNewProject()) { builders.add(new EmptyModuleBuilder()); } Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>(); 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<ProjectTemplate>()); } } MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.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<ProjectTemplate>()); } if (context.isCreatingNewProject()) { MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates(); for (TemplatesGroup group : myTemplatesMap.keySet()) { myTemplatesMap.putValues(group, localTemplates.get(group.getId())); } } // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593) if (PlatformUtils.isIdeaCommunity()) { for (TemplatesGroup group : myTemplatesMap.keySet()) { if (WebModuleTypeBase.WEB_MODULE.equals(group.getId()) && myTemplatesMap.get(group).isEmpty()) { myTemplatesMap.remove(group); break; } } } List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet()); // sorting by module type popularity final MultiMap<ModuleType, TemplatesGroup> moduleTypes = new MultiMap<ModuleType, TemplatesGroup>(); for (TemplatesGroup group : groups) { ModuleType type = getModuleType(group); moduleTypes.putValue(type, group); } Collections.sort( groups, new Comparator<TemplatesGroup>() { @Override public int compare(TemplatesGroup o1, TemplatesGroup 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, new Function<TemplatesGroup, String>() { @Override public String fun(TemplatesGroup group) { return group.getParentGroup(); } }); // move subgroups MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>(); 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); } } return groups; }
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) { KeymapGroup result = KeymapGroupFactory.getInstance() .createGroup( ExternalSystemBundle.message("external.system.keymap.group"), ExternalSystemIcons.TaskGroup); if (project == null) return result; MultiMap<ProjectSystemId, String> projectToActionsMapping = MultiMap.create(); for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) { projectToActionsMapping.putValues(manager.getSystemId(), ContainerUtil.<String>emptyList()); } ActionManager actionManager = ActionManager.getInstance(); if (actionManager != null) { for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) { AnAction eachAction = actionManager.getAction(eachId); if (!(eachAction instanceof MyExternalSystemAction)) continue; if (condition != null && !condition.value(actionManager.getActionOrStub(eachId))) continue; MyExternalSystemAction taskAction = (MyExternalSystemAction) eachAction; projectToActionsMapping.putValue(taskAction.getSystemId(), eachId); } } Map<ProjectSystemId, KeymapGroup> keymapGroupMap = ContainerUtil.newHashMap(); for (ProjectSystemId systemId : projectToActionsMapping.keySet()) { if (!keymapGroupMap.containsKey(systemId)) { final Icon projectIcon = ExternalSystemUiUtil.getUiAware(systemId).getProjectIcon(); KeymapGroup group = KeymapGroupFactory.getInstance().createGroup(systemId.getReadableName(), projectIcon); result.addGroup(group); keymapGroupMap.put(systemId, group); } } for (Map.Entry<ProjectSystemId, Collection<String>> each : projectToActionsMapping.entrySet()) { Collection<String> tasks = each.getValue(); final ProjectSystemId systemId = each.getKey(); final KeymapGroup systemGroup = keymapGroupMap.get(systemId); for (String actionId : tasks) { systemGroup.addActionId(actionId); } if (systemGroup instanceof Group) { Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add; ((Group) systemGroup) .addHyperlink( new Hyperlink(icon, "Choose a task to assign a shortcut") { @Override public void onClick(MouseEvent e) { SelectExternalTaskDialog dialog = new SelectExternalTaskDialog(systemId, project); if (dialog.showAndGet() && dialog.getResult() != null) { TaskData taskData = dialog.getResult().second; String ownerModuleName = dialog.getResult().first; ExternalSystemTaskAction externalSystemAction = (ExternalSystemTaskAction) getOrRegisterAction(project, ownerModuleName, taskData); ApplicationManager.getApplication() .getMessageBus() .syncPublisher(KeymapListener.CHANGE_TOPIC) .processCurrentKeymapChanged(); Settings allSettings = Settings.KEY.getData( DataManager.getInstance().getDataContext(e.getComponent())); KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null; if (keymapPanel != null) { // clear actions filter keymapPanel.showOption(""); keymapPanel.selectAction(externalSystemAction.myId); } } } }); } } for (ActionsProvider extension : ActionsProvider.EP_NAME.getExtensions()) { KeymapGroup group = extension.createGroup(condition, project); if (group != null) { result.addGroup(group); } } return result; }