void () { final LibrariesContainer.LibraryLevel level = myNameAndLevelPanel.getLibraryLevel(); WriteAction.run(() -> { final Module module = myModulesComboBox.getSelectedModule(); final String libraryName = myNameAndLevelPanel.getLibraryName(); if (level == LibrariesContainer.LibraryLevel.MODULE) { final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel(); LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(libraryName, level, myRoots); modifiableModel.commit(); } else { final Library library = LibrariesContainerFactory.createContainer(myProject).createLibrary(libraryName, level, myRoots); if (module != null) { ModuleRootModificationUtil.addDependency(module, library); } } }); }