void (@NotNull FacetType<?, ?> type) { final ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator(); List<Module> suitableModules = new ArrayList<>(Arrays.asList(myContext.getModules())); final Iterator<Module> iterator = suitableModules.iterator(); while (iterator.hasNext()) { Module module = iterator.next(); if (!type.isSuitableModuleType(ModuleType.get(module)) || (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(module, null, type.getId()))) { iterator.remove(); } } final Project project = myContext.getProject(); if (suitableModules.isEmpty()) { Messages.showErrorDialog(project, JavaUiBundle.message("dialog.message.no.suitable.modules.for.0.facet.found", type.getPresentableName()), JavaUiBundle.message("dialog.title.cannot.create.facet")); return; } final ChooseModulesDialog dialog = new ChooseModulesDialog(project, suitableModules, JavaUiBundle.message("choose.module"), JavaUiBundle.message("facet.will.be.added.to.selected.module", type.getPresentableName())); dialog.setSingleSelectionMode(); dialog.show(); final List<Module> elements = dialog.getChosenElements(); if (!dialog.isOK() || elements.size() != 1) return; final Module module = elements.get(0); ProjectStructureConfigurable structureConfigurable = myContext.getModulesConfigurator().getProjectStructureConfigurable(); final Facet<?> facet = structureConfigurable.getModulesConfig().getFacetEditorFacade().createAndAddFacet(type, module, null); structureConfigurable.select(facet, true); }