Java Code Examples for com.intellij.openapi.roots.OrderRootType#getAllTypes()

The following examples show how to use com.intellij.openapi.roots.OrderRootType#getAllTypes() . 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: SdkEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected JComponent createCenterComponent() {
  myTabbedPane = new TabbedPaneWrapper(myDisposable);
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    if (showTabForType(type)) {
      final OrderRootTypeUIFactory factory = OrderRootTypeUIFactory.FACTORY.getByKey(type);
      if(factory == null) {
        continue;
      }

      SdkPathEditor pathEditor = getPathEditor(type);

      myTabbedPane.addTab(pathEditor.getDisplayName(), pathEditor.createComponent());
    }
  }

  myTabbedPane.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(final ChangeEvent e) {
      myHistory.pushQueryPlace();
    }
  });
  return myTabbedPane.getComponent();
}
 
Example 2
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public VirtualFile getExistingRootDirectory() {
  for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
    final VirtualFile[] existingRoots = getLibraryEditor().getFiles(orderRootType);
    if (existingRoots.length > 0) {
      VirtualFile existingRoot = existingRoots[0];
      if (existingRoot.getFileSystem() instanceof ArchiveFileSystem) {
        existingRoot = ((ArchiveFileSystem)existingRoot.getFileSystem()).getLocalVirtualFileFor(existingRoot);
      }
      if (existingRoot != null) {
        if (existingRoot.isDirectory()) {
          return existingRoot;
        }
        else {
          return existingRoot.getParent();
        }
      }
    }
  }
  return null;
}
 
Example 3
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Set<VirtualFile> getNotExcludedRoots() {
  Set<VirtualFile> roots = new LinkedHashSet<VirtualFile>();
  String[] excludedRootUrls = getLibraryEditor().getExcludedRootUrls();
  Set<VirtualFile> excludedRoots = new HashSet<VirtualFile>();
  for (String url : excludedRootUrls) {
    ContainerUtil.addIfNotNull(excludedRoots, VirtualFileManager.getInstance().findFileByUrl(url));
  }
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    VirtualFile[] files = getLibraryEditor().getFiles(type);
    for (VirtualFile file : files) {
      if (!VfsUtilCore.isUnder(file, excludedRoots)) {
        roots.add(PathUtil.getLocalFile(file));
      }
    }
  }
  return roots;
}
 
Example 4
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addRootsFromModules(boolean includeSourceRoots, Set<String> recursive, Set<String> flat) {
  final Module[] modules = ModuleManager.getInstance(myProject).getModules();
  for (Module module : modules) {
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

    addRootsToTrack(moduleRootManager.getContentRootUrls(), recursive, flat);

    if (includeSourceRoots) {
      addRootsToTrack(moduleRootManager.getContentFolderUrls(ContentFolderScopes.all(false)), recursive, flat);
    }

    final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
    for (OrderEntry entry : orderEntries) {
      if (entry instanceof OrderEntryWithTracking) {
        for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
          addRootsToTrack(entry.getUrls(orderRootType), recursive, flat);
        }
      }
    }
  }
}
 
Example 5
Source File: RootsAsVirtualFilePointers.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void readExternal(@Nonnull Element element) {
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    read(element, type);
  }

  ApplicationManager.getApplication().runReadAction(() -> myRoots.values().forEach(container -> {
    if (myNoCopyJars) {
      for (String root : container.getUrls()) {
        setNoCopyJars(root);
      }
    }
  }));
}
 
Example 6
Source File: RootsAsVirtualFilePointers.java    From consulo with Apache License 2.0 5 votes vote down vote up
void copyRootsFrom(@Nonnull RootProvider rootContainer) {
  removeAllRoots();
  for (OrderRootType rootType : OrderRootType.getAllTypes()) {
    final String[] newRoots = rootContainer.getUrls(rootType);
    for (String newRoot : newRoots) {
      addRoot(newRoot, rootType);
    }
  }
}
 
Example 7
Source File: LibraryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static OrderRootType getJarDirectoryRootType(@Nullable String type) {
  for (OrderRootType rootType : OrderRootType.getAllTypes()) {
    if (rootType.name().equals(type)) {
      return rootType;
    }
  }
  return DEFAULT_JAR_DIRECTORY_TYPE;
}
 
Example 8
Source File: BaseSdkEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void createMainPanel() {
  myMainPanel = new JPanel(new GridBagLayout());

  for (OrderRootType type : OrderRootType.getAllTypes()) {
    if (showTabForType(type)) {
      final OrderRootTypeUIFactory factory = OrderRootTypeUIFactory.FACTORY.getByKey(type);
      if(factory == null) {
        LOGGER.error("OrderRootTypeUIFactory is not defined for order root type: " + type);
        continue;
      }
      final SdkPathEditor pathEditor = factory.createPathEditor(mySdk);
      if (pathEditor != null) {
        pathEditor.setAddBaseDir(mySdk.getHomeDirectory());
        myPathEditors.put(type, pathEditor);
      }
    }
  }

  JComponent centerComponent = createCenterComponent();

  myHomeComponent = createHomeComponent();
  myHomeComponent.getTextField().setEditable(false);
  myHomeComponent.getButton().setVisible(!mySdk.isPredefined() && ((SdkType)mySdk.getSdkType()).supportsUserAdd());

  myHomeFieldLabel = new JLabel(getHomeFieldLabelValue());
  myMainPanel.add(myHomeFieldLabel,
                  new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                                         new Insets(2, 10, 2, 2), 0, 0));
  myMainPanel.add(myHomeComponent, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER,
                                                          GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 10), 0, 0));

  myAdditionalDataPanel = new JPanel(new BorderLayout());
  myMainPanel.add(myAdditionalDataPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER,
                                                                GridBagConstraints.BOTH, new Insets(2, 0, 0, 0), 0, 0));

  myMainPanel.add(centerComponent,
                  new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                                         GridBagConstraints.BOTH, new Insets(2, 0, 0, 0), 0, 0));
}
 
Example 9
Source File: LibraryEditingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void copyLibrary(LibraryEx from, Map<String, String> rootMapping, LibraryEx.ModifiableModelEx target) {
  target.setProperties(from.getProperties());
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    final String[] urls = from.getUrls(type);
    for (String url : urls) {
      final String protocol = VirtualFileManager.extractProtocol(url);
      if (protocol == null) continue;
      final String fullPath = VirtualFileManager.extractPath(url);
      final int sep = fullPath.indexOf(ArchiveFileSystem.ARCHIVE_SEPARATOR);
      String localPath;
      String pathInJar;
      if (sep != -1) {
        localPath = fullPath.substring(0, sep);
        pathInJar = fullPath.substring(sep);
      }
      else {
        localPath = fullPath;
        pathInJar = "";
      }
      final String targetPath = rootMapping.get(localPath);
      String targetUrl = targetPath != null ? VirtualFileManager.constructUrl(protocol, targetPath + pathInJar) : url;

      if (from.isJarDirectory(url, type)) {
        target.addJarDirectory(targetUrl, false, type);
      }
      else {
        target.addRoot(targetUrl, type);
      }
    }
  }
}
 
Example 10
Source File: LibraryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private Collection<OrderRootType> getAllRootTypes() {
  return OrderRootType.getAllTypes();
}
 
Example 11
Source File: LibraryRootsComponentDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @return Array of root types supported by a library type associated with the roots
 *         component descriptor. All persistent root types are returned by default. 
 */
@Nonnull
public List<OrderRootType> getRootTypes() {
  return OrderRootType.getAllTypes();
}
 
Example 12
Source File: ExistingLibraryEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OrderRootType> getOrderRootTypes() {
  return OrderRootType.getAllTypes();
}
 
Example 13
Source File: NamedLibraryElementNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean orderEntryContainsFile(OrderEntry orderEntry, VirtualFile file) {
  for (OrderRootType rootType : OrderRootType.getAllTypes()) {
    if (containsFileInOrderType(orderEntry, rootType, file)) return true;
  }
  return false;
}