Search in sources :

Example 1 with ModifiableModelsProvider

use of com.intellij.openapi.roots.ModifiableModelsProvider in project ballerina by ballerina-lang.

the class BallerinaModuleLibrariesInitializer method removeLibraryIfNeeded.

private void removeLibraryIfNeeded() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
    ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
    LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
    if (ballerinaLibraryEntry != null) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            Library library = ballerinaLibraryEntry.getLibrary();
            if (library != null) {
                LibraryTable table = library.getTable();
                if (table != null) {
                    table.removeLibrary(library);
                    model.removeOrderEntry(ballerinaLibraryEntry);
                    modelsProvider.commitModuleModifiableModel(model);
                }
            } else {
                modelsProvider.disposeModuleModifiableModel(model);
            }
        });
    } else {
        ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModifiableModelsProvider(com.intellij.openapi.roots.ModifiableModelsProvider) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 ModifiableModelsProvider (com.intellij.openapi.roots.ModifiableModelsProvider)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1