private void rebuildFiles(boolean groupByPackages, @Nullable Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { for (int i = getChildCount() - 1; i >= 0; i--) { final TreeNode node = getChildAt(i); if (node instanceof Disposable) { Disposer.dispose((Disposable)node); } } removeAllChildren(); if (groupByPackages) { buildPackages(); acceptFilter(filter, showOnlyFilteredItems); } else { buildFiles(filter, showOnlyFilteredItems); } setTreeModel(myTreeModel); if (myTreeModel != null) { myTreeModel.nodeStructureChanged(this); } }
@Override protected boolean acceptFilter(Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { try { VirtualFilePointer filePointer = getFilePointer(); if (!filePointer.isValid()) { return false; } VirtualFile file = filePointer.getFile(); if (file != null && file.isValid() && filter.first.contains(file, getProject(), filter.second)) { applyFilter(true); return true; } } catch (Throwable e) { // TODO: catch and ignore exceptions: see to FilePatternPackageSet // sometimes for new file DirectoryFileIndex.getContentRootForFile() return random path } return false; }
protected boolean acceptFilter(@Nullable Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { boolean apply = false; if (children != null && filter != null) { for (Iterator it = children.iterator(); it.hasNext(); ) { AbstractTreeNode node = (AbstractTreeNode)it.next(); if (node.acceptFilter(filter, showOnlyFilteredItems)) { apply = true; } else if (showOnlyFilteredItems) { if (node instanceof Disposable) { Disposer.dispose((Disposable)node); } it.remove(); } } applyFilter(apply); } return apply; }
@Nullable private Pair<PackageSetBase, NamedScopesHolder> getScopeFilter() { String scopeName = VcsConfiguration.getInstance(myProject).UPDATE_FILTER_SCOPE_NAME; if (scopeName != null) { for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(myProject)) { NamedScope scope = holder.getScope(scopeName); if (scope != null) { PackageSet packageSet = scope.getValue(); if (packageSet instanceof PackageSetBase) { return Pair.create((PackageSetBase)packageSet, holder); } } } } return null; }
@Nullable private Pair<PackageSetBase, NamedScopesHolder> getScopeFilter() { String scopeName = VcsConfiguration.getInstance(myProject).UPDATE_FILTER_SCOPE_NAME; if (scopeName != null) { for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(myProject)) { NamedScope scope = holder.getScope(scopeName); if (scope != null) { PackageSet packageSet = scope.getValue(); if (packageSet instanceof PackageSetBase) { return new Pair<PackageSetBase, NamedScopesHolder>((PackageSetBase)packageSet, holder); } } } } return null; }
@Override protected boolean acceptFilter(Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { try { VirtualFilePointer filePointer = getFilePointer(); if (!filePointer.isValid()) { return false; } VirtualFile file = filePointer.getFile(); if (file != null && file.isValid() && filter.first.contains(file, filter.second)) { applyFilter(true); return true; } } catch (Throwable e) { // TODO: catch and ignore exceptions: see to FilePatternPackageSet // sometimes for new file DirectoryFileIndex.getContentRootForFile() return random path } return false; }
@Nullable private Pair<PackageSetBase, NamedScopesHolder> getScopeFilter() { String scopeName = getFilterScopeName(); if (scopeName != null) { for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(myProject)) { NamedScope scope = holder.getScope(scopeName); if (scope != null) { PackageSet packageSet = scope.getValue(); if (packageSet instanceof PackageSetBase) { return Pair.create((PackageSetBase)packageSet, holder); } } } } return null; }
public void rebuild(boolean groupByPackages, @Nullable Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { myFilterAttributes = null; if (containsGroups()) { rebuildGroups(groupByPackages, filter, showOnlyFilteredItems); } else { rebuildFiles(groupByPackages, filter, showOnlyFilteredItems); } }
private void rebuildGroups(boolean groupByPackages, @Nullable Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { boolean apply = false; for (int i = 0; i < getChildCount(); i++) { GroupTreeNode childGroup = (GroupTreeNode)getChildAt(i); childGroup.rebuild(groupByPackages, filter, showOnlyFilteredItems); apply |= childGroup.myFilterAttributes != null; } applyFilter(apply); }
private void buildFiles(@Nullable Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { Collections.sort(myFilePaths, new Comparator<String>() { @Override public int compare(String path1, String path2) { return path1.compareToIgnoreCase(path2); } }); boolean apply = false; for (final String filePath : myFilePaths) { final FileTreeNode child = new FileTreeNode(filePath, myInvalidAttributes, myProject, null); if (filter != null) { if (child.acceptFilter(filter, showOnlyFilteredItems)) { apply = true; } else if (showOnlyFilteredItems) { Disposer.dispose(child); continue; } } final String error = myErrorsMap.get(filePath); if (error != null) { child.setErrorText(error); } add(child); Disposer.register(this, child); } applyFilter(apply); }
@Nullable private FileColorConfiguration findConfiguration(@NotNull final VirtualFile colored) { for (FileColorConfiguration configuration : ContainerUtil.concat(myApplicationLevelConfigurations, myProjectLevelConfigurations)) { NamedScope scope = NamedScopesHolder.getScope(myProject, configuration.getScopeName()); if (scope != null) { NamedScopesHolder namedScopesHolder = NamedScopesHolder.getHolder(myProject, configuration.getScopeName(), null); PackageSet packageSet = scope.getValue(); if (packageSet instanceof PackageSetBase && namedScopesHolder != null && ((PackageSetBase)packageSet).contains(colored, myProject, namedScopesHolder)) { return configuration; } } } return null; }
private void buildFiles(@Nullable Pair<PackageSetBase, NamedScopesHolder> filter, boolean showOnlyFilteredItems) { Collections.sort(myFilePaths, new Comparator<String>() { @Override public int compare(String path1, String path2) { return path1.compareToIgnoreCase(path2); } }); boolean apply = false; for (final String filePath : myFilePaths) { final FileTreeNode child = new FileTreeNode(filePath, myInvalidAttributes, myProject, null); if (filter != null) { if (child.acceptFilter(filter, showOnlyFilteredItems)) { apply = true; } else if (showOnlyFilteredItems) { continue; } } final String error = myErrorsMap.get(filePath); if (error != null) { child.setErrorText(error); } add(child); Disposer.register(this, child); } applyFilter(apply); }
int getFilteredFilesCount() { Pair<PackageSetBase, NamedScopesHolder> scopeFilter = getScopeFilter(); int[] result = new int[1]; TreeUtil.traverse(myRoot, node -> { if (node instanceof FileTreeNode) { if (((FileTreeNode)node).acceptFilter(scopeFilter, true)) { result[0]++; } } return true; }); return result[0]; }
@Nullable NamedScope getFilterScope() { Pair<PackageSetBase, NamedScopesHolder> filter = getScopeFilter(); return filter == null ? null : filter.second.getScope(getFilterScopeName()); }