Search in sources :

Example 6 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class GroovyFacetUtil method tryToSetUpGroovyFacetOnTheFly.

public static boolean tryToSetUpGroovyFacetOnTheFly(final Module module) {
    final Project project = module.getProject();
    GroovyConfigUtils utils = GroovyConfigUtils.getInstance();
    final Library[] libraries = utils.getAllSDKLibraries(project);
    if (libraries.length > 0) {
        final Library library = libraries[0];
        int result = Messages.showOkCancelDialog(GroovyBundle.message("groovy.like.library.found.text", module.getName(), library.getName(), utils.getSDKLibVersion(library)), GroovyBundle.message("groovy.like.library.found"), JetgroovyIcons.Groovy.Groovy_32x32);
        if (result == Messages.OK) {
            WriteAction.run(() -> {
                ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
                LibraryOrderEntry entry = model.addLibraryEntry(libraries[0]);
                LibrariesUtil.placeEntryToCorrectPlace(model, entry);
                model.commit();
            });
            return true;
        }
    }
    return false;
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Project(com.intellij.openapi.project.Project) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry)

Example 7 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class FacetBasedDetectedFrameworkDescription method doSetup.

protected void doSetup(ModifiableModelsProvider modifiableModelsProvider, final Module module) {
    final ModifiableFacetModel model = modifiableModelsProvider.getFacetModifiableModel(module);
    final String name = UniqueNameGenerator.generateUniqueName(myFacetType.getDefaultFacetName(), s -> FacetManager.getInstance(module).findFacet(myFacetType.getId(), s) == null);
    final F facet = FacetManager.getInstance(module).createFacet(myFacetType, name, myConfiguration, findUnderlyingFacet(module));
    model.addFacet(facet);
    modifiableModelsProvider.commitFacetModifiableModel(module, model);
    final ModifiableRootModel rootModel = modifiableModelsProvider.getModuleModifiableModel(module);
    myDetector.setupFacet(facet, rootModel);
    modifiableModelsProvider.commitModuleModifiableModel(rootModel);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel)

Example 8 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class ModuleDependencyDataService method importData.

@Override
protected Map<OrderEntry, OrderAware> importData(@NotNull final Collection<DataNode<ModuleDependencyData>> toImport, @NotNull final Module module, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    final Map<Pair<String, DependencyScope>, ModuleOrderEntry> /* dependency module scope */
    toRemove = ContainerUtilRt.newHashMap();
    final Map<OrderEntry, OrderAware> orderEntryDataMap = ContainerUtil.newLinkedHashMap();
    for (OrderEntry entry : modelsProvider.getOrderEntries(module)) {
        if (entry instanceof ModuleOrderEntry) {
            ModuleOrderEntry e = (ModuleOrderEntry) entry;
            toRemove.put(Pair.create(e.getModuleName(), e.getScope()), e);
        }
    }
    final Set<ModuleDependencyData> processed = ContainerUtil.newHashSet();
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    for (DataNode<ModuleDependencyData> dependencyNode : toImport) {
        final ModuleDependencyData dependencyData = dependencyNode.getData();
        if (processed.contains(dependencyData))
            continue;
        processed.add(dependencyData);
        toRemove.remove(Pair.create(dependencyData.getInternalName(), dependencyData.getScope()));
        final ModuleData moduleData = dependencyData.getTarget();
        Module ideDependencyModule = modelsProvider.findIdeModule(moduleData);
        ModuleOrderEntry orderEntry;
        if (module.equals(ideDependencyModule)) {
            // skip recursive module dependency check
            continue;
        } else {
            if (ideDependencyModule == null) {
                LOG.warn(String.format("Can't import module dependency for '%s' module. Reason: target module (%s) is not found at the ide", module.getName(), dependencyData));
            }
            orderEntry = modelsProvider.findIdeModuleDependency(dependencyData, module);
            if (orderEntry == null) {
                orderEntry = ReadAction.compute(() -> ideDependencyModule == null ? modifiableRootModel.addInvalidModuleEntry(moduleData.getInternalName()) : modifiableRootModel.addModuleOrderEntry(ideDependencyModule));
            }
        }
        orderEntry.setScope(dependencyData.getScope());
        orderEntry.setExported(dependencyData.isExported());
        final boolean productionOnTestDependency = dependencyData.isProductionOnTestDependency();
        if (orderEntry instanceof ModuleOrderEntryImpl) {
            ((ModuleOrderEntryImpl) orderEntry).setProductionOnTestDependency(productionOnTestDependency);
        } else if (productionOnTestDependency) {
            LOG.warn("Unable to set productionOnTestDependency for entry: " + orderEntry);
        }
        orderEntryDataMap.put(orderEntry, dependencyData);
    }
    if (!toRemove.isEmpty()) {
        removeData(toRemove.values(), module, modelsProvider);
    }
    return orderEntryDataMap;
}
Also used : ModuleOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleOrderEntryImpl) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderAware(com.intellij.openapi.externalSystem.model.project.OrderAware) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ModuleDependencyData(com.intellij.openapi.externalSystem.model.project.ModuleDependencyData) Pair(com.intellij.openapi.util.Pair)

Example 9 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class CommonContentEntriesEditor method createComponentImpl.

@Override
public JPanel createComponentImpl() {
    final Module module = getModule();
    final Project project = module.getProject();
    myContentEntryEditorListener = new MyContentEntryEditorListener();
    final JPanel mainPanel = new JPanel(new BorderLayout());
    addAdditionalSettingsToPanel(mainPanel);
    final DefaultActionGroup group = new DefaultActionGroup();
    final AddContentEntryAction action = new AddContentEntryAction();
    action.registerCustomShortcutSet(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK, mainPanel);
    group.add(action);
    myEditorsPanel = new ScrollablePanel(new VerticalStackLayout());
    myEditorsPanel.setBackground(BACKGROUND_COLOR);
    JScrollPane myScrollPane = ScrollPaneFactory.createScrollPane(myEditorsPanel, true);
    final ToolbarPanel toolbarPanel = new ToolbarPanel(myScrollPane, group);
    int border = myWithBorders ? 1 : 0;
    toolbarPanel.setBorder(new CustomLineBorder(1, 0, border, border));
    final JBSplitter splitter = new OnePixelSplitter(false);
    splitter.setProportion(0.6f);
    splitter.setHonorComponentsMinimumSize(true);
    myRootTreeEditor = createContentEntryTreeEditor(project);
    final JComponent component = myRootTreeEditor.createComponent();
    component.setBorder(new CustomLineBorder(1, border, border, 0));
    splitter.setFirstComponent(component);
    splitter.setSecondComponent(toolbarPanel);
    JPanel contentPanel = new JPanel(new GridBagLayout());
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, myRootTreeEditor.getEditingActionsGroup(), true);
    contentPanel.add(new JLabel("Mark as:"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, 0, JBUI.insets(0, 10), 0, 0));
    contentPanel.add(actionToolbar.getComponent(), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
    contentPanel.add(splitter, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    final JPanel innerPanel = createBottomControl(module);
    if (innerPanel != null) {
        mainPanel.add(innerPanel, BorderLayout.SOUTH);
    }
    final ModifiableRootModel model = getModel();
    if (model != null) {
        final ContentEntry[] contentEntries = model.getContentEntries();
        if (contentEntries.length > 0) {
            for (final ContentEntry contentEntry : contentEntries) {
                addContentEntryPanel(contentEntry.getUrl());
            }
            selectContentEntry(contentEntries[0].getUrl());
        }
    }
    return mainPanel;
}
Also used : OnePixelSplitter(com.intellij.ui.OnePixelSplitter) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Project(com.intellij.openapi.project.Project) VerticalStackLayout(com.intellij.openapi.roots.ui.componentsList.layout.VerticalStackLayout) ScrollablePanel(com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) ContentEntry(com.intellij.openapi.roots.ContentEntry) JBSplitter(com.intellij.ui.JBSplitter) Module(com.intellij.openapi.module.Module) ToolbarPanel(com.intellij.ui.roots.ToolbarPanel)

Example 10 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.

the class ModuleDeleteProvider method deleteElement.

@Override
public void deleteElement(@NotNull DataContext dataContext) {
    final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
    assert modules != null;
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    assert project != null;
    String names = StringUtil.join(Arrays.asList(modules), module -> "\'" + module.getName() + "\'", ", ");
    int ret = Messages.showOkCancelDialog(getConfirmationText(modules, names), getActionTitle(), Messages.getQuestionIcon());
    if (ret != Messages.OK)
        return;
    CommandProcessor.getInstance().executeCommand(project, () -> {
        final Runnable action = () -> {
            final ModuleManager moduleManager = ModuleManager.getInstance(project);
            final Module[] currentModules = moduleManager.getModules();
            final ModifiableModuleModel modifiableModuleModel = moduleManager.getModifiableModel();
            final Map<Module, ModifiableRootModel> otherModuleRootModels = new HashMap<>();
            for (final Module module : modules) {
                final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
                for (final Module otherModule : currentModules) {
                    if (otherModule == module || ArrayUtilRt.find(modules, otherModule) != -1)
                        continue;
                    if (!otherModuleRootModels.containsKey(otherModule)) {
                        otherModuleRootModels.put(otherModule, ModuleRootManager.getInstance(otherModule).getModifiableModel());
                    }
                }
                removeModule(module, modifiableModel, otherModuleRootModels.values(), modifiableModuleModel);
            }
            final ModifiableRootModel[] modifiableRootModels = otherModuleRootModels.values().toArray(new ModifiableRootModel[otherModuleRootModels.size()]);
            ModifiableModelCommitter.multiCommit(modifiableRootModels, modifiableModuleModel);
        };
        ApplicationManager.getApplication().runWriteAction(action);
    }, ProjectBundle.message("module.remove.command"), null);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) ModuleManager(com.intellij.openapi.module.ModuleManager) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)101 Module (com.intellij.openapi.module.Module)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 ContentEntry (com.intellij.openapi.roots.ContentEntry)27 File (java.io.File)18 Library (com.intellij.openapi.roots.libraries.Library)15 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)14 ModuleManager (com.intellij.openapi.module.ModuleManager)8 Sdk (com.intellij.openapi.projectRoots.Sdk)8 IOException (java.io.IOException)8 NotNull (org.jetbrains.annotations.NotNull)8 OrderEntry (com.intellij.openapi.roots.OrderEntry)7 Project (com.intellij.openapi.project.Project)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Nullable (org.jetbrains.annotations.Nullable)6 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)5 ConfigurationException (com.intellij.openapi.options.ConfigurationException)5 THashMap (gnu.trove.THashMap)5 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)4 AccessToken (com.intellij.openapi.application.AccessToken)4