Search in sources :

Example 1 with ModifiableFacetModel

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

the class PythonFrameworkSupportConfigurable method addSupport.

public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable Library library) {
    final FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    PythonFacet facet = facetManager.createFacet(PythonFacetType.getInstance(), "Python", null);
    facet.getConfiguration().setSdk(mySdkComboBox.getSelectedSdk());
    facetModel.addFacet(facet);
    facetModel.commit();
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager)

Example 2 with ModifiableFacetModel

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

the class MvcModuleStructureUtil method updateModuleStructure.

public static void updateModuleStructure(final Module module, MvcProjectStructure structure, @NotNull VirtualFile root) {
    final Pair<Collection<Consumer<ModifiableRootModel>>, Collection<Consumer<ModifiableFacetModel>>> actions = getUpdateProjectStructureActions(Collections.singletonList(root), structure);
    // update module
    if (!actions.first.isEmpty()) {
        ModuleRootModificationUtil.updateModel(module, model -> {
            for (final Consumer<ModifiableRootModel> action : actions.first) {
                action.consume(model);
            }
        });
    }
    // update facets
    if (!actions.second.isEmpty()) {
        final Application application = ApplicationManager.getApplication();
        final ModifiableFacetModel model = application.runReadAction(new Computable<ModifiableFacetModel>() {

            @Override
            public ModifiableFacetModel compute() {
                return FacetManager.getInstance(module).createModifiableModel();
            }
        });
        for (Consumer<ModifiableFacetModel> action : actions.second) {
            action.consume(model);
        }
        application.invokeAndWait(() -> application.runWriteAction(() -> model.commit()));
    }
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) Application(com.intellij.openapi.application.Application)

Example 3 with ModifiableFacetModel

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

the class BuildoutFacetConfigurator method setupFacet.

static void setupFacet(Module module, @NotNull BuildoutFacetConfiguration config) {
    //TODO: refactor, see other python facets
    FacetManager facetManager = FacetManager.getInstance(module);
    final ModifiableFacetModel model = facetManager.createModifiableModel();
    BuildoutFacetType facetType = BuildoutFacetType.getInstance();
    BuildoutFacet facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), config, null);
    model.addFacet(facet);
    new WriteAction() {

        protected void run(@NotNull final Result result) throws Throwable {
            model.commit();
        }
    }.execute();
    facet.updatePaths();
    BuildoutFacet.attachLibrary(module);
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) Result(com.intellij.openapi.application.Result)

Example 4 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project kotlin by JetBrains.

the class KotlinAndroidTestCase method addAndroidFacet.

public AndroidFacet addAndroidFacet(Module module, String sdkPath, String platformDir, boolean addSdk) {
    FacetManager facetManager = FacetManager.getInstance(module);
    AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
    if (addSdk) {
        addAndroidSdk(module, sdkPath, platformDir);
    }
    final ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    facetModel.addFacet(facet);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            facetModel.commit();
        }
    });
    return facet;
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 5 with ModifiableFacetModel

use of com.intellij.facet.ModifiableFacetModel in project android by JetBrains.

the class NdkModuleModelDataService method onModelsNotFound.

@Override
protected void onModelsNotFound(@NotNull IdeModifiableModelsProvider modelsProvider) {
    // See https://code.google.com/p/android/issues/detail?id=229806
    for (Module module : modelsProvider.getModules()) {
        ModifiableFacetModel facetModel = modelsProvider.getModifiableFacetModel(module);
        removeAllFacets(facetModel, NdkFacet.getFacetTypeId());
    }
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) Module(com.intellij.openapi.module.Module)

Aggregations

ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)29 FacetManager (com.intellij.facet.FacetManager)15 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)9 NotNull (org.jetbrains.annotations.NotNull)5 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)4 Module (com.intellij.openapi.module.Module)4 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)3 Result (com.intellij.openapi.application.Result)3 WriteAction (com.intellij.openapi.application.WriteAction)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)2 NdkFacetType (com.android.tools.idea.gradle.project.facet.ndk.NdkFacetType)2 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 File (java.io.File)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 GradleFacetType (com.android.tools.idea.gradle.project.facet.gradle.GradleFacetType)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 GradleSyncSummary (com.android.tools.idea.gradle.project.sync.GradleSyncSummary)1