Search in sources :

Example 1 with LibraryTableModifiableModelProvider

use of com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider in project intellij-community by JetBrains.

the class ClasspathPanelImpl method doEdit.

private void doEdit() {
    final OrderEntry entry = getSelectedEntry();
    if (!(entry instanceof LibraryOrderEntry))
        return;
    final Library library = ((LibraryOrderEntry) entry).getLibrary();
    if (library == null) {
        return;
    }
    final LibraryTable table = library.getTable();
    final String tableLevel = table != null ? table.getTableLevel() : LibraryTableImplUtil.MODULE_LEVEL;
    final LibraryTablePresentation presentation = LibraryEditingUtil.getLibraryTablePresentation(getProject(), tableLevel);
    final LibraryTableModifiableModelProvider provider = getModifiableModelProvider(tableLevel);
    EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(this, provider, library, myState.getProject(), presentation, getStructureConfigurableContext());
    dialog.setContextModule(getRootModel().getModule());
    dialog.show();
    myEntryTable.repaint();
    ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
}
Also used : LibraryTablePresentation(com.intellij.openapi.roots.libraries.LibraryTablePresentation) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) EditExistingLibraryDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog) Library(com.intellij.openapi.roots.libraries.Library) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider)

Example 2 with LibraryTableModifiableModelProvider

use of com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider in project intellij-plugins by JetBrains.

the class DependenciesConfigurable method editLibrary.

private void editLibrary(ModuleLibraryItem item) {
    if (!item.canEdit())
        return;
    final LibraryOrderEntry entry = item.orderEntry;
    assert entry != null;
    Library library = entry.getLibrary();
    if (library == null) {
        return;
    }
    LibraryTablePresentation presentation = new LibraryTablePresentation() {

        @Override
        public String getDisplayName(boolean plural) {
            return FlexBundle.message(plural ? "library.editor.title.plural" : "library.editor.title.singular");
        }

        @Override
        public String getDescription() {
            return ProjectBundle.message("libraries.node.text.module");
        }

        @Override
        public String getLibraryTableEditorTitle() {
            // not used as far as I see
            return "Configure Library";
        }
    };
    LibraryTableModifiableModelProvider provider = new LibraryTableModifiableModelProvider() {

        public LibraryTable.ModifiableModel getModifiableModel() {
            return myConfigEditor.getLibraryModel(myDependencies);
        }
    };
    StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
    EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(myMainPanel, provider, library, myProject, presentation, context);
    dialog.setContextModule(myConfigEditor.getModule(myDependencies));
    dialog.show();
    myTable.refresh();
}
Also used : EditExistingLibraryDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider)

Example 3 with LibraryTableModifiableModelProvider

use of com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider in project intellij-community by JetBrains.

the class ChangeLibraryLevelActionBase method doCopy.

@Nullable
protected Library doCopy(LibraryEx library) {
    final VirtualFile baseDir = getBaseDir();
    final String libPath = baseDir != null ? baseDir.getPath() + "/lib" : "";
    final VirtualFile[] classesRoots = library.getFiles(OrderRootType.CLASSES);
    boolean allowEmptyName = isConvertingToModuleLibrary() && classesRoots.length == 1;
    final String libraryName = allowEmptyName ? "" : StringUtil.notNullize(library.getName(), LibraryTypeServiceImpl.suggestLibraryName(classesRoots));
    final LibraryTableModifiableModelProvider provider = getModifiableTableModelProvider();
    final ChangeLibraryLevelDialog dialog = new ChangeLibraryLevelDialog(getParentComponent(), myProject, myCopy, libraryName, libPath, allowEmptyName, provider);
    if (!dialog.showAndGet()) {
        return null;
    }
    final Set<File> fileToCopy = new LinkedHashSet<>();
    final Map<String, String> copiedFiles = new HashMap<>();
    final String targetDirectoryPath = dialog.getDirectoryForFilesPath();
    if (targetDirectoryPath != null) {
        for (OrderRootType type : OrderRootType.getAllTypes()) {
            for (VirtualFile root : library.getFiles(type)) {
                if (root.isInLocalFileSystem() || root.getFileSystem() instanceof ArchiveFileSystem) {
                    fileToCopy.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(root)));
                }
            }
        }
        if (!copyOrMoveFiles(fileToCopy, targetDirectoryPath, copiedFiles)) {
            return null;
        }
    }
    final Library copied = provider.getModifiableModel().createLibrary(StringUtil.nullize(dialog.getLibraryName()), library.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) copied.getModifiableModel();
    LibraryEditingUtil.copyLibrary(library, copiedFiles, model);
    WriteAction.run(() -> model.commit());
    return copied;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ChangeLibraryLevelDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.ChangeLibraryLevelDialog) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) ArchiveFileSystem(com.intellij.openapi.vfs.newvfs.ArchiveFileSystem) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider) OrderRootType(com.intellij.openapi.roots.OrderRootType) Library(com.intellij.openapi.roots.libraries.Library) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LibraryTableModifiableModelProvider

use of com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider in project intellij-community by JetBrains.

the class IdeaModifiableModelsProvider method getLibraryTableModifiableModel.

@Override
public LibraryTable.ModifiableModel getLibraryTableModifiableModel() {
    final Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
        if (!project.isInitialized()) {
            continue;
        }
        StructureConfigurableContext context = getProjectStructureContext(project);
        LibraryTableModifiableModelProvider provider = context != null ? context.createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL) : null;
        final LibraryTable.ModifiableModel modifiableModel = provider != null ? provider.getModifiableModel() : null;
        if (modifiableModel != null) {
            return modifiableModel;
        }
    }
    return LibraryTablesRegistrar.getInstance().getLibraryTable().getModifiableModel();
}
Also used : Project(com.intellij.openapi.project.Project) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) StructureConfigurableContext(com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider)

Aggregations

LibraryTableModifiableModelProvider (com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider)4 Library (com.intellij.openapi.roots.libraries.Library)2 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)2 EditExistingLibraryDialog (com.intellij.openapi.roots.ui.configuration.libraryEditor.EditExistingLibraryDialog)2 Project (com.intellij.openapi.project.Project)1 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 LibraryTablePresentation (com.intellij.openapi.roots.libraries.LibraryTablePresentation)1 ChangeLibraryLevelDialog (com.intellij.openapi.roots.ui.configuration.libraryEditor.ChangeLibraryLevelDialog)1 StructureConfigurableContext (com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArchiveFileSystem (com.intellij.openapi.vfs.newvfs.ArchiveFileSystem)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Nullable (org.jetbrains.annotations.Nullable)1