Search in sources :

Example 1 with ProjectFacetsConfigurator

use of com.intellij.facet.impl.ProjectFacetsConfigurator in project intellij-community by JetBrains.

the class AddFrameworkSupportInProjectStructureAction method isVisible.

private boolean isVisible() {
    final Module module = getSelectedModule();
    if (module == null || !myProvider.isEnabledForModuleType(ModuleType.get(module))) {
        return false;
    }
    final ProjectFacetsConfigurator facetsProvider = myModuleStructureConfigurable.getFacetConfigurator();
    if (!myProvider.canAddSupport(module, facetsProvider)) {
        return false;
    }
    final String underlyingFrameworkTypeId = myFrameworkType.getUnderlyingFrameworkTypeId();
    if (underlyingFrameworkTypeId == null)
        return true;
    final FrameworkSupportInModuleProvider underlyingProvider = FrameworkSupportUtil.findProvider(underlyingFrameworkTypeId, FrameworkSupportUtil.getAllProviders());
    if (underlyingProvider == null) {
        LOG.error("framework not found by id " + underlyingFrameworkTypeId);
    }
    return underlyingProvider.isSupportAlreadyAdded(module, facetsProvider);
}
Also used : Module(com.intellij.openapi.module.Module) ProjectFacetsConfigurator(com.intellij.facet.impl.ProjectFacetsConfigurator) FrameworkSupportInModuleProvider(com.intellij.framework.addSupport.FrameworkSupportInModuleProvider)

Example 2 with ProjectFacetsConfigurator

use of com.intellij.facet.impl.ProjectFacetsConfigurator in project intellij-community by JetBrains.

the class AddFacetOfTypeAction method addFacetToModule.

private void addFacetToModule(@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, "No suitable modules for " + type.getPresentableName() + " facet found.", "Cannot Create Facet");
        return;
    }
    final ChooseModulesDialog dialog = new ChooseModulesDialog(project, suitableModules, "Choose Module", type.getPresentableName() + " facet will be added to selected module");
    dialog.setSingleSelectionMode();
    dialog.show();
    final List<Module> elements = dialog.getChosenElements();
    if (!dialog.isOK() || elements.size() != 1)
        return;
    final Module module = elements.get(0);
    final Facet facet = ModuleStructureConfigurable.getInstance(project).getFacetEditorFacade().createAndAddFacet(type, module, null);
    ProjectStructureConfigurable.getInstance(project).select(facet, true);
}
Also used : Project(com.intellij.openapi.project.Project) ChooseModulesDialog(com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog) ArrayList(java.util.ArrayList) ProjectFacetsConfigurator(com.intellij.facet.impl.ProjectFacetsConfigurator) Module(com.intellij.openapi.module.Module) Facet(com.intellij.facet.Facet)

Example 3 with ProjectFacetsConfigurator

use of com.intellij.facet.impl.ProjectFacetsConfigurator in project intellij-community by JetBrains.

the class AddFacetOfTypeAction method addSubFacet.

private void addSubFacet(FacetType type, FacetTypeId<?> underlyingType) {
    final ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator();
    List<Facet> suitableParents = new ArrayList<>();
    for (Module module : myContext.getModules()) {
        if (type.isSuitableModuleType(ModuleType.get(module))) {
            suitableParents.addAll(facetsConfigurator.getFacetsByType(module, underlyingType));
        }
    }
    final Iterator<Facet> iterator = suitableParents.iterator();
    while (iterator.hasNext()) {
        Facet parent = iterator.next();
        if (type.isOnlyOneFacetAllowed() && facetsConfigurator.hasFacetOfType(parent.getModule(), parent, type.getId())) {
            iterator.remove();
        }
    }
    final Project project = myContext.getProject();
    if (suitableParents.isEmpty()) {
        final String parentType = FacetTypeRegistry.getInstance().findFacetType(underlyingType).getPresentableName();
        Messages.showErrorDialog(project, "No suitable parent " + parentType + " facets found", "Cannot Create " + type.getPresentableName() + " Facet");
        return;
    }
    ChooseParentFacetDialog dialog = new ChooseParentFacetDialog(project, suitableParents);
    dialog.show();
    final List<Facet> chosen = dialog.getChosenElements();
    if (!dialog.isOK() || chosen.size() != 1)
        return;
    final Facet parent = chosen.get(0);
    final Facet facet = ModuleStructureConfigurable.getInstance(project).getFacetEditorFacade().createAndAddFacet(type, parent.getModule(), parent);
    ProjectStructureConfigurable.getInstance(project).select(facet, true);
}
Also used : Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) ProjectFacetsConfigurator(com.intellij.facet.impl.ProjectFacetsConfigurator) Module(com.intellij.openapi.module.Module) Facet(com.intellij.facet.Facet)

Example 4 with ProjectFacetsConfigurator

use of com.intellij.facet.impl.ProjectFacetsConfigurator in project intellij-community by JetBrains.

the class FacetTypeEditor method createAllFacetsEditor.

@Nullable
private MultipleFacetSettingsEditor createAllFacetsEditor() {
    ProjectFacetsConfigurator facetsConfigurator = myContext.myModulesConfigurator.getFacetsConfigurator();
    List<Facet> facets = new ArrayList<>();
    for (Module module : myContext.getModules()) {
        facets.addAll(facetsConfigurator.getFacetsByType(module, myFacetType.getId()));
    }
    if (!facets.isEmpty()) {
        final FacetEditor[] editors = new FacetEditor[facets.size()];
        for (int i = 0; i < facets.size(); i++) {
            editors[i] = facetsConfigurator.getOrCreateEditor(facets.get(i));
        }
        return myFacetType.createMultipleConfigurationsEditor(myProject, editors);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) FacetEditor(com.intellij.facet.ui.FacetEditor) ProjectFacetsConfigurator(com.intellij.facet.impl.ProjectFacetsConfigurator) Module(com.intellij.openapi.module.Module) Facet(com.intellij.facet.Facet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProjectFacetsConfigurator (com.intellij.facet.impl.ProjectFacetsConfigurator)4 Module (com.intellij.openapi.module.Module)4 Facet (com.intellij.facet.Facet)3 ArrayList (java.util.ArrayList)3 Project (com.intellij.openapi.project.Project)2 FacetEditor (com.intellij.facet.ui.FacetEditor)1 FrameworkSupportInModuleProvider (com.intellij.framework.addSupport.FrameworkSupportInModuleProvider)1 ChooseModulesDialog (com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog)1 Nullable (org.jetbrains.annotations.Nullable)1