Search in sources :

Example 1 with FrameworkSupportConfigurable

use of com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable in project intellij-community by JetBrains.

the class AddSupportForFrameworksPanel method addSupport.

public void addSupport(@NotNull final Module module, @NotNull final ModifiableRootModel rootModel) {
    List<Library> addedLibraries = new ArrayList<>();
    List<FrameworkSupportNode> selectedFrameworks = getSelectedNodes();
    sortFrameworks(selectedFrameworks);
    List<FrameworkSupportConfigurable> selectedConfigurables = new ArrayList<>();
    final IdeaModifiableModelsProvider modifiableModelsProvider = new IdeaModifiableModelsProvider();
    for (FrameworkSupportNode node : selectedFrameworks) {
        FrameworkSupportInModuleConfigurable configurable = node.getConfigurable();
        if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) {
            selectedConfigurables.add(((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) configurable).getConfigurable());
        }
        final LibraryCompositionSettings settings = getLibraryCompositionSettings(node);
        Library library = settings != null ? settings.addLibraries(rootModel, addedLibraries, myLibrariesContainer) : null;
        if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) {
            ((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) configurable).getConfigurable().addSupport(module, rootModel, library);
        } else {
            configurable.addSupport(module, rootModel, modifiableModelsProvider);
        }
    }
    for (FrameworkSupportNode node : selectedFrameworks) {
        FrameworkSupportInModuleProvider provider = node.getUserObject();
        if (provider instanceof OldFrameworkSupportProviderWrapper) {
            final FrameworkSupportProvider oldProvider = ((OldFrameworkSupportProviderWrapper) provider).getProvider();
            if (oldProvider instanceof FacetBasedFrameworkSupportProvider && !addedLibraries.isEmpty()) {
                ((FacetBasedFrameworkSupportProvider) oldProvider).processAddedLibraries(module, addedLibraries);
            }
        }
    }
    for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) {
        communicator.onFrameworkSupportAdded(module, rootModel, selectedConfigurables, myModel);
    }
}
Also used : LibraryCompositionSettings(com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings) FrameworkSupportProvider(com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider) FacetBasedFrameworkSupportProvider(com.intellij.facet.ui.FacetBasedFrameworkSupportProvider) FrameworkSupportInModuleProvider(com.intellij.framework.addSupport.FrameworkSupportInModuleProvider) FrameworkSupportConfigurable(com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable) IdeaModifiableModelsProvider(com.intellij.openapi.roots.IdeaModifiableModelsProvider) Library(com.intellij.openapi.roots.libraries.Library) FrameworkSupportInModuleConfigurable(com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable) FacetBasedFrameworkSupportProvider(com.intellij.facet.ui.FacetBasedFrameworkSupportProvider) FrameworkSupportCommunicator(com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportCommunicator)

Example 2 with FrameworkSupportConfigurable

use of com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable in project intellij-community by JetBrains.

the class MavenFrameworkSupportProvider method createConfigurable.

@NotNull
@Override
public FrameworkSupportConfigurable createConfigurable(@NotNull FrameworkSupportModel model) {
    return new FrameworkSupportConfigurable() {

        @Override
        public JComponent getComponent() {
            return new JPanel();
        }

        @Override
        public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable Library library) {
            VirtualFile[] roots = model.getContentRoots();
            VirtualFile root;
            if (roots.length == 0) {
                VirtualFile moduleFile = module.getModuleFile();
                if (moduleFile != null) {
                    root = moduleFile.getParent();
                    model.addContentEntry(root);
                } else {
                    return;
                }
            } else {
                root = roots[0];
            }
            VirtualFile existingPom = null;
            for (VirtualFile child : root.getChildren()) {
                if (child.getName().startsWith("pom.")) {
                    existingPom = child;
                }
            }
            if (existingPom != null) {
                MavenProjectsManager.getInstance(module.getProject()).addManagedFilesOrUnignore(Collections.singletonList(existingPom));
            } else {
                prepareProjectStructure(model, root);
                new MavenModuleBuilderHelper(new MavenId("groupId", module.getName(), "1.0-SNAPSHOT"), null, null, false, false, null, null, "Add Maven Support").configure(model.getProject(), root, true);
            }
        }
    };
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenId(org.jetbrains.idea.maven.model.MavenId) FrameworkSupportConfigurable(com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FrameworkSupportConfigurable (com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable)2 Library (com.intellij.openapi.roots.libraries.Library)2 LibraryCompositionSettings (com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings)1 FacetBasedFrameworkSupportProvider (com.intellij.facet.ui.FacetBasedFrameworkSupportProvider)1 FrameworkSupportInModuleConfigurable (com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable)1 FrameworkSupportInModuleProvider (com.intellij.framework.addSupport.FrameworkSupportInModuleProvider)1 FrameworkSupportProvider (com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider)1 FrameworkSupportCommunicator (com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportCommunicator)1 Module (com.intellij.openapi.module.Module)1 IdeaModifiableModelsProvider (com.intellij.openapi.roots.IdeaModifiableModelsProvider)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 MavenId (org.jetbrains.idea.maven.model.MavenId)1