use of com.intellij.xml.index.IndexedRelevantResource in project intellij-community by JetBrains.
the class MapExternalResourceDialog method setupSchemasTree.
private void setupSchemasTree(String uri, @NotNull Project project, @Nullable PsiFile file, @Nullable String location) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
mySchemasTree.setModel(new DefaultTreeModel(root));
ConfigFileSearcher searcher = new ConfigFileSearcher(file == null ? null : ModuleUtilCore.findModuleForPsiElement(file), project) {
@Override
public Set<PsiFile> search(@Nullable Module module, @NotNull Project project) {
List<IndexedRelevantResource<String, XsdNamespaceBuilder>> resources = XmlNamespaceIndex.getAllResources(module, project, null);
HashSet<PsiFile> files = new HashSet<>();
PsiManager psiManager = PsiManager.getInstance(project);
for (IndexedRelevantResource<String, XsdNamespaceBuilder> resource : resources) {
VirtualFile file = resource.getFile();
PsiFile psiFile = psiManager.findFile(file);
ContainerUtil.addIfNotNull(files, psiFile);
}
return files;
}
};
searcher.search();
new ConfigFilesTreeBuilder(mySchemasTree).buildTree(root, searcher);
TreeUtil.expandAll(mySchemasTree);
mySchemasTree.setRootVisible(false);
mySchemasTree.setShowsRootHandles(true);
ColoredTreeCellRenderer renderer = new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
ConfigFilesTreeBuilder.renderNode(value, expanded, this);
}
};
renderer.setFont(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN));
mySchemasTree.setCellRenderer(renderer);
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1 && isOKActionEnabled()) {
doOKAction();
}
}
};
mySchemasTree.addMouseListener(mouseAdapter);
mySchemasTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
validateInput();
}
});
mySchemasTree.setSelectionRow(0);
PsiFile schema = null;
if (file != null) {
schema = XmlUtil.findNamespaceByLocation(file, uri);
} else if (location != null) {
VirtualFile virtualFile = VfsUtilCore.findRelativeFile(location, null);
if (virtualFile != null) {
schema = PsiManager.getInstance(project).findFile(virtualFile);
}
}
if (schema != null) {
DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, schema);
if (node != null) {
mySchemaFound = true;
TreeUtil.selectNode(mySchemasTree, node);
}
myFileTextField.setText(schema.getVirtualFile().getCanonicalPath());
}
}
Aggregations