use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class ProjectViewModuleNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
Module module = getValue();
if (module == null || module.isDisposed()) {
// module has been disposed
return Collections.emptyList();
}
final List<VirtualFile> contentRoots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelModuleRoots(module, getSettings());
final List<AbstractTreeNode> children = new ArrayList<>(contentRoots.size());
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
for (final VirtualFile contentRoot : contentRoots) {
if (contentRoot.isDirectory()) {
PsiDirectory directory = psiManager.findDirectory(contentRoot);
if (directory != null) {
children.add(new PsiDirectoryNode(getProject(), directory, getSettings()));
}
} else {
PsiFile file = psiManager.findFile(contentRoot);
if (file != null) {
children.add(new PsiFileNode(getProject(), file, getSettings()));
}
}
}
return children;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class GroupByTypeComparator method compare.
@Override
public int compare(NodeDescriptor descriptor1, NodeDescriptor descriptor2) {
if (!isSortByType() && descriptor1 instanceof ProjectViewNode && ((ProjectViewNode) descriptor1).isSortByFirstChild()) {
final Collection<AbstractTreeNode> children = ((ProjectViewNode) descriptor1).getChildren();
if (!children.isEmpty()) {
descriptor1 = children.iterator().next();
descriptor1.update();
}
}
if (!isSortByType() && descriptor2 instanceof ProjectViewNode && ((ProjectViewNode) descriptor2).isSortByFirstChild()) {
final Collection<AbstractTreeNode> children = ((ProjectViewNode) descriptor2).getChildren();
if (!children.isEmpty()) {
descriptor2 = children.iterator().next();
descriptor2.update();
}
}
if (descriptor1 instanceof ProjectViewNode && descriptor2 instanceof ProjectViewNode) {
final Project project = descriptor1.getProject();
final ProjectView projectView = ProjectView.getInstance(project);
ProjectViewNode node1 = (ProjectViewNode) descriptor1;
ProjectViewNode node2 = (ProjectViewNode) descriptor2;
if (isManualOrder()) {
final Comparable key1 = node1.getManualOrderKey();
final Comparable key2 = node2.getManualOrderKey();
int result = compare(key1, key2);
if (result != 0)
return result;
}
boolean isFoldersOnTop = !(projectView instanceof ProjectViewImpl && !((ProjectViewImpl) projectView).isFoldersAlwaysOnTop());
if (isFoldersOnTop) {
int typeWeight1 = node1.getTypeSortWeight(isSortByType());
int typeWeight2 = node2.getTypeSortWeight(isSortByType());
if (typeWeight1 != 0 && typeWeight2 == 0) {
return -1;
}
if (typeWeight1 == 0 && typeWeight2 != 0) {
return 1;
}
if (typeWeight1 != 0 && typeWeight2 != typeWeight1) {
return typeWeight1 - typeWeight2;
}
}
if (isSortByType()) {
final Comparable typeSortKey1 = node1.getTypeSortKey();
final Comparable typeSortKey2 = node2.getTypeSortKey();
int result = compare(typeSortKey1, typeSortKey2);
if (result != 0)
return result;
} else {
final Comparable typeSortKey1 = node1.getSortKey();
final Comparable typeSortKey2 = node2.getSortKey();
if (typeSortKey1 != null && typeSortKey2 != null) {
int result = compare(typeSortKey1, typeSortKey2);
if (result != 0)
return result;
}
}
if (isAbbreviateQualifiedNames()) {
String key1 = node1.getQualifiedNameSortKey();
String key2 = node2.getQualifiedNameSortKey();
if (key1 != null && key2 != null) {
return naturalCompare(key1, key2);
}
}
}
if (descriptor1 == null)
return -1;
if (descriptor2 == null)
return 1;
return AlphaComparator.INSTANCE.compare(descriptor1, descriptor2);
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class AbstractProjectNode method modulesAndGroups.
protected Collection<AbstractTreeNode> modulesAndGroups(Module[] modules) {
Map<String, List<Module>> groups = new THashMap<>();
List<Module> nonGroupedModules = new ArrayList<>(Arrays.asList(modules));
for (final Module module : modules) {
final String[] path = ModuleManager.getInstance(getProject()).getModuleGroupPath(module);
if (path != null) {
final String topLevelGroupName = path[0];
groups.computeIfAbsent(topLevelGroupName, k -> new ArrayList<>()).add(module);
nonGroupedModules.remove(module);
}
}
List<AbstractTreeNode> result = new ArrayList<>();
try {
for (String groupPath : groups.keySet()) {
result.add(createModuleGroupNode(new ModuleGroup(Collections.singletonList(groupPath))));
}
for (Module module : nonGroupedModules) {
result.add(createModuleGroup(module));
}
} catch (Exception e) {
LOG.error(e);
return new ArrayList<>();
}
return result;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class AbstractPsiBasedNode method getChildren.
@Override
@NotNull
public final Collection<AbstractTreeNode> getChildren() {
final PsiElement psiElement = extractPsiFromValue();
if (psiElement == null) {
return new ArrayList<>();
}
final boolean valid = psiElement.isValid();
if (!LOG.assertTrue(valid)) {
return Collections.emptyList();
}
final Collection<AbstractTreeNode> children = getChildrenImpl();
return children != null ? children : Collections.<AbstractTreeNode>emptyList();
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class ExternalLibrariesNode method getChildren.
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
Project project = Objects.requireNonNull(getProject());
List<AbstractTreeNode> children = new ArrayList<>();
ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
Module[] modules = ModuleManager.getInstance(project).getModules();
Set<Library> processedLibraries = new THashSet<>();
Set<Sdk> processedSdk = new THashSet<>();
for (Module module : modules) {
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
for (final OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
final Library library = libraryOrderEntry.getLibrary();
if (library == null)
continue;
if (processedLibraries.contains(library))
continue;
processedLibraries.add(library);
if (!hasExternalEntries(fileIndex, libraryOrderEntry))
continue;
final String libraryName = library.getName();
if (libraryName == null || libraryName.length() == 0) {
addLibraryChildren(libraryOrderEntry, children, project, this);
} else {
children.add(new NamedLibraryElementNode(project, new NamedLibraryElement(null, libraryOrderEntry), getSettings()));
}
} else if (orderEntry instanceof JdkOrderEntry) {
final JdkOrderEntry jdkOrderEntry = (JdkOrderEntry) orderEntry;
final Sdk jdk = jdkOrderEntry.getJdk();
if (jdk != null) {
if (processedSdk.contains(jdk))
continue;
processedSdk.add(jdk);
children.add(new NamedLibraryElementNode(project, new NamedLibraryElement(null, jdkOrderEntry), getSettings()));
}
}
}
}
for (AdditionalLibraryRootsProvider provider : AdditionalLibraryRootsProvider.EP_NAME.getExtensions()) {
Collection<SyntheticLibrary> libraries = provider.getAdditionalProjectLibraries(project);
for (SyntheticLibrary library : libraries) {
//noinspection InstanceofIncompatibleInterface
if (library instanceof ItemPresentation) {
children.add(new SyntheticLibraryElementNode(project, library, getSettings()));
}
}
}
return children;
}
Aggregations