Java Code Examples for com.intellij.openapi.roots.libraries.LibraryTable#ModifiableModel

The following examples show how to use com.intellij.openapi.roots.libraries.LibraryTable#ModifiableModel . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaxeProjectConfigurationUpdater.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private void setupLibraries(Project project, ModifiableModelsProvider modelsProvider, ModulesProvider modulesProvider, List<LibraryData> libraries) {
  LibraryTable.ModifiableModel librariesModel = modelsProvider.getLibraryTableModifiableModel(project);

  for(LibraryData lib:libraries) {
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(lib.getClasspath());
    if(root != null) {
      LibraryImpl library = (LibraryImpl)librariesModel.createLibrary(lib.getName());
      LibraryEx.ModifiableModelEx model = library.getModifiableModel();
      model.setKind(HaxeLibraryType.HAXE_LIBRARY);
      model.addRoot(root, OrderRootType.CLASSES);
      model.addRoot(root, OrderRootType.SOURCES);
      model.commit();

      for(Module module:modulesProvider.getModules()) {
        ModifiableRootModel moduleModel = modelsProvider.getModuleModifiableModel(module);
        moduleModel.addLibraryEntry(library);
        moduleModel.commit();
      }
    }
  }

  librariesModel.commit();
}
 
Example 2
Source File: ClasspathPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public LibraryTableModifiableModelProvider getModifiableModelProvider(@Nonnull String tableLevel) {
  if (LibraryTableImplUtil.MODULE_LEVEL.equals(tableLevel)) {
    final LibraryTable moduleLibraryTable = getRootModel().getModuleLibraryTable();
    return new LibraryTableModifiableModelProvider() {
      @Override
      public LibraryTable.ModifiableModel getModifiableModel() {
        return moduleLibraryTable.getModifiableModel();
      }
    };
  }
  else {
    return getStructureConfigurableContext().createModifiableModelProvider(tableLevel);
  }
}
 
Example 3
Source File: LibraryEditorDialogBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected boolean validateAndApply() {
  String newName = myNameField.getText().trim();
  if (newName.length() == 0) {
    newName = null;
  }
  if (shouldCheckName(newName)) {
    final LibraryTable.ModifiableModel tableModifiableModel = getTableModifiableModel();
    if (tableModifiableModel != null && !(tableModifiableModel instanceof ModuleLibraryTable)) {
      if (newName == null) {
        Messages.showErrorDialog(ProjectBundle.message("library.name.not.specified.error", newName), ProjectBundle.message("library.name.not.specified.title"));
        return false;
      }
      if (LibraryEditingUtil.libraryAlreadyExists(tableModifiableModel, newName)) {
        Messages.showErrorDialog(ProjectBundle.message("library.name.already.exists.error", newName), ProjectBundle.message("library.name.already.exists.title"));
        return false;
      }
    }
    myLibraryRootsComponent.renameLibrary(newName);
  }
  myLibraryRootsComponent.applyProperties();
  return true;
}
 
Example 4
Source File: IdeaModifiableModelsProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 5
Source File: EditExistingLibraryDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private EditExistingLibraryDialog(Component parent,
                                  LibraryTable.ModifiableModel tableModifiableModel,
                                  @Nullable Project project,
                                  ExistingLibraryEditor libraryEditor,
                                  boolean commitChanges,
                                  LibraryTablePresentation presentation, StructureConfigurableContext context) {
  super(parent, new LibraryRootsComponent(project, libraryEditor));
  setTitle("Configure " + presentation.getDisplayName(false));
  myTableModifiableModel = tableModifiableModel;
  myLibraryEditor = libraryEditor;
  myCommitChanges = commitChanges;
  if (commitChanges) {
    Disposer.register(getDisposable(), libraryEditor);
  }
  context.addLibraryEditorListener(new LibraryEditorListener() {
    @Override
    public void libraryRenamed(@Nonnull Library library, String oldName, String newName) {
      if (library.equals(myLibraryEditor.getLibrary())) {
        myNameField.setText(newName);
      }
    }
  }, getDisposable());
  init();
}
 
Example 6
Source File: EditExistingLibraryDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static EditExistingLibraryDialog createDialog(Component parent,
                                                     LibraryTableModifiableModelProvider modelProvider,
                                                     Library library,
                                                     @Nullable Project project,
                                                     LibraryTablePresentation presentation,
                                                     StructureConfigurableContext context) {
  LibraryTable.ModifiableModel modifiableModel = modelProvider.getModifiableModel();
  boolean commitChanges = false;
  ExistingLibraryEditor libraryEditor;
  if (modifiableModel instanceof LibrariesModifiableModel) {
    libraryEditor = ((LibrariesModifiableModel)modifiableModel).getLibraryEditor(library);
  }
  else {
    libraryEditor = new ExistingLibraryEditor(library, context);
    commitChanges = true;
  }
  return new EditExistingLibraryDialog(parent, modifiableModel, project, libraryEditor, commitChanges, presentation, context);
}
 
Example 7
Source File: LibraryProjectStructureElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void performFix() {
  final LibraryTable.ModifiableModel libraryTable = myContext.getModifiableLibraryTable(myLibrary.getTable());
  if (libraryTable instanceof LibrariesModifiableModel) {
    for (String invalidRoot : myInvalidUrls) {
      final ExistingLibraryEditor libraryEditor = ((LibrariesModifiableModel)libraryTable).getLibraryEditor(myLibrary);
      libraryEditor.removeRoot(invalidRoot, myType);
    }
    myContext.getDaemonAnalyzer().queueUpdate(LibraryProjectStructureElement.this);
    final ProjectStructureConfigurable structureConfigurable = ProjectStructureConfigurable.getInstance(myContext.getProject());
    navigate().doWhenDone(new Runnable() {
      @Override
      public void run() {
        final NamedConfigurable configurable = structureConfigurable.getConfigurableFor(myLibrary).getSelectedConfigurable();
        if (configurable instanceof LibraryConfigurable) {
          ((LibraryConfigurable)configurable).updateComponent();
        }
      }
    });
  }
}
 
Example 8
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ExistingLibraryEditor getLibraryEditor(@Nonnull Library library) {
  final LibraryTable table = library.getTable();
  if (table == null) return null;

  final LibraryTable.ModifiableModel model = myContext.getModifiableLibraryTable(table);
  if (model instanceof LibrariesModifiableModel) {
    return ((LibrariesModifiableModel)model).getLibraryEditor(library);
  }
  return null;
}
 
Example 9
Source File: ModuleEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object object, Method method, Object[] params) throws Throwable {
  final boolean needUpdate = myCheckedNames.contains(method.getName());
  try {
    final Object result = method.invoke(myDelegateTable, unwrapParams(params));
    if (result instanceof Library) {
      return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{result instanceof LibraryEx ? LibraryEx.class : Library.class},
                                    new LibraryInvocationHandler((Library)result));
    }
    else if (result instanceof LibraryTable.ModifiableModel) {
      return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryTableBase.ModifiableModelEx.class},
                                    new LibraryTableModelInvocationHandler((LibraryTable.ModifiableModel)result));
    }
    if (result instanceof Library[]) {
      Library[] libraries = (Library[])result;
      for (int idx = 0; idx < libraries.length; idx++) {
        Library library = libraries[idx];
        libraries[idx] =
        (Library)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{library instanceof LibraryEx ? LibraryEx.class : Library.class},
                                        new LibraryInvocationHandler(library));
      }
    }
    return result;
  }
  catch (InvocationTargetException e) {
    throw e.getCause();
  }
  finally {
    if (needUpdate) {
      fireModuleStateChanged();
    }
  }
}
 
Example 10
Source File: StructureConfigurableContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LibraryTable.ModifiableModel getModifiableLibraryTable(@Nonnull LibraryTable table) {
  final String tableLevel = table.getTableLevel();
  if (tableLevel.equals(LibraryTableImplUtil.MODULE_LEVEL)) {
    return table.getModifiableModel();
  }
  return myLevel2Providers.get(tableLevel);
}
 
Example 11
Source File: StructureConfigurableContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
public VirtualFile[] getLibraryFiles(Library library, final OrderRootType type) {
  final LibraryTable table = library.getTable();
  if (table != null) {
    final LibraryTable.ModifiableModel modifiableModel = getModifiableLibraryTable(table);
    if (modifiableModel instanceof LibrariesModifiableModel) {
      final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel;
      if (librariesModel.hasLibraryEditor(library)) {
        return librariesModel.getLibraryEditor(library).getFiles(type);
      }
    }
  }
  return library.getFiles(type);
}
 
Example 12
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getUniqueLibraryName(final String baseName, final LibraryTable.ModifiableModel model) {
  return UniqueNameGenerator.generateUniqueName(baseName, "", "", " (", ")", new Condition<String>() {
    @Override
    public boolean value(String s) {
      return model.getLibraryByName(s) == null;
    }
  });
}
 
Example 13
Source File: LibrariesModifiableModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private LibraryTable.ModifiableModel getLibrariesModifiableModel() {
  if (myLibrariesModifiableModel == null) {
    myLibrariesModifiableModel = myTable.getModifiableModel();
  }

  return myLibrariesModifiableModel;
}
 
Example 14
Source File: IdeaModifiableModelsProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public LibraryTable.ModifiableModel getLibraryTableModifiableModel(Project project) {
  StructureConfigurableContext context = getProjectStructureContext(project);
  if (context != null) {
    LibraryTableModifiableModelProvider provider = context.createModifiableModelProvider(LibraryTablesRegistrar.PROJECT_LEVEL);
    return provider.getModifiableModel();
  }
  return LibraryTablesRegistrar.getInstance().getLibraryTable(project).getModifiableModel();
}
 
Example 15
Source File: CreateNewLibraryDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected LibraryTable.ModifiableModel getTableModifiableModel() {
  final LibraryTable selectedTable = (LibraryTable)myLibraryLevelCombobox.getSelectedItem();
  return myContext.getModifiableLibraryTable(selectedTable);
}
 
Example 16
Source File: ModuleEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
LibraryTableModelInvocationHandler(LibraryTable.ModifiableModel delegateModel) {
  myDelegateModel = delegateModel;
}
 
Example 17
Source File: HaxelibProjectUpdater.java    From intellij-haxe with Apache License 2.0 2 votes vote down vote up
/**
 * Find an IDEA library in a module's LibraryTable (actually, its ModifiableModel)
 * matching a HaxeLibraryReference.
 *
 * @param table - the LibraryTable to look in.
 * @param ref - the library to find.
 * @return the Library, if found; null, otherwise.
 */
@Nullable
private Library lookupModelLibrary(@NotNull LibraryTable.ModifiableModel table, @NotNull HaxeLibraryReference ref) {
  return lookupLibrary(table.getLibraryIterator(), ref);
}
 
Example 18
Source File: LibraryTableModifiableModelProvider.java    From consulo with Apache License 2.0 votes vote down vote up
LibraryTable.ModifiableModel getModifiableModel(); 
Example 19
Source File: ModifiableModelsProvider.java    From consulo with Apache License 2.0 votes vote down vote up
LibraryTable.ModifiableModel getLibraryTableModifiableModel(Project project); 
Example 20
Source File: ModifiableModelsProvider.java    From consulo with Apache License 2.0 votes vote down vote up
LibraryTable.ModifiableModel getLibraryTableModifiableModel();