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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations