com.intellij.openapi.roots.impl.libraries.LibraryTableBase Java Examples

The following examples show how to use com.intellij.openapi.roots.impl.libraries.LibraryTableBase. 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: FileOrDirectoryDependencyTabContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Library createLibraryFromRoots(ModifiableModuleRootLayer layer, List<OrderRoot> roots, @Nullable final LibraryType libraryType) {
  final LibraryTable.ModifiableModel moduleLibraryModel = layer.getModuleLibraryTable().getModifiableModel();

  final PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
  final Library library = ((LibraryTableBase.ModifiableModelEx)moduleLibraryModel).createLibrary(null, kind);
  final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx)library.getModifiableModel();

  for (OrderRoot root : roots) {
    if (root.isJarDirectory()) {
      libModel.addJarDirectory(root.getFile(), false, root.getType());
    }
    else {
      libModel.addRoot(root.getFile(), root.getType());
    }
  }
  libModel.commit();
  return library;
}
 
Example #2
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Library createLibrary(@Nonnull NewLibraryEditor libraryEditor,
                             @Nonnull LibraryLevel level) {
  LibraryTableModifiableModelProvider provider = getProvider(level);
  if (provider == null) {
    LOG.error("cannot create module library in this context");
  }

  LibraryTableBase.ModifiableModelEx model = (LibraryTableBase.ModifiableModelEx)provider.getModifiableModel();
  final LibraryType<?> type = libraryEditor.getType();
  Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model), type == null ? null : type.getKind());
  ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
  createdLibraryEditor.setProperties(libraryEditor.getProperties());
  libraryEditor.applyTo(createdLibraryEditor);
  return library;
}
 
Example #3
Source File: QuarkusLanguageClient.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void handleLibraryUpdate(Library library) {
  if (library.getTable() instanceof LibraryTableBase) {
    long modif = ((LibraryTableBase)library.getTable()).getStateModificationCount();
    if (modif > lastModification) {
      sendPropertiesChangeEvent(MicroProfilePropertiesScope.dependencies, QuarkusModuleUtil.getModulesURIs(getProject()));
      lastModification = modif;
    }
  }
}
 
Example #4
Source File: LibrariesModifiableModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Library createLibrary(String name, @Nullable PersistentLibraryKind type) {
  final Library library = ((LibraryTableBase.ModifiableModelEx)getLibrariesModifiableModel()).createLibrary(name, type);
  //createLibraryEditor(library);                     \
  final BaseLibrariesConfigurable configurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
  configurable.createLibraryNode(library);
  return library;
}
 
Example #5
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Library createLibraryInTable(final @Nonnull NewLibraryEditor editor, final LibraryTable table) {
  LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx) table.getModifiableModel();
  final String name = StringUtil.isEmpty(editor.getName()) ? null : getUniqueLibraryName(editor.getName(), modifiableModel);
  final LibraryType<?> type = editor.getType();
  Library library = modifiableModel.createLibrary(name, type == null ? null : type.getKind());
  final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
  editor.applyTo(model);
  model.commit();
  modifiableModel.commit();
  return library;
}
 
Example #6
Source File: CreateNewLibraryDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Library createLibrary() {
  final LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx)getTableModifiableModel();
  final LibraryType<?> type = myLibraryEditor.getType();
  final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), type != null ? type.getKind() : null);
  final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
  myLibraryEditor.applyTo(model);
  WriteAction.run(model::commit);
  return library;
}
 
Example #7
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();
    }
  }
}