use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class FileStructurePopup method navigateSelectedElement.
public boolean navigateSelectedElement() {
final AbstractTreeNode selectedNode = getSelectedNode();
if (ApplicationManager.getApplication().isInternal()) {
String enteredPrefix = getSpeedSearch().getEnteredPrefix();
String itemText = getSpeedSearchText(selectedNode);
if (StringUtil.isNotEmpty(enteredPrefix) && StringUtil.isNotEmpty(itemText)) {
LOG.info("Chosen in file structure popup by prefix '" + enteredPrefix + "': '" + itemText + "'");
}
}
final Ref<Boolean> succeeded = new Ref<>();
final CommandProcessor commandProcessor = CommandProcessor.getInstance();
commandProcessor.executeCommand(myProject, () -> {
if (selectedNode != null) {
if (selectedNode.canNavigateToSource()) {
myPopup.cancel();
selectedNode.navigate(true);
succeeded.set(true);
} else {
succeeded.set(false);
}
} else {
succeeded.set(false);
}
IdeDocumentHistory.getInstance(myProject).includeCurrentCommandAsNavigation();
}, "Navigate", null);
return succeeded.get();
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class ProjectViewNode method someChildContainsFile.
public boolean someChildContainsFile(final VirtualFile file, boolean optimizeByCheckingFileRootsFirst) {
VirtualFile parent = file.getParent();
boolean mayContain = false;
if (optimizeByCheckingFileRootsFirst && parent != null) {
Collection<VirtualFile> roots = getRoots();
for (VirtualFile eachRoot : roots) {
if (parent.equals(eachRoot.getParent())) {
mayContain = true;
break;
}
if (VfsUtilCore.isAncestor(eachRoot, file, true)) {
mayContain = true;
break;
}
}
} else {
mayContain = true;
}
if (!mayContain) {
return false;
}
Collection<? extends AbstractTreeNode> kids = getChildren();
for (final AbstractTreeNode kid : kids) {
ProjectViewNode node = (ProjectViewNode) kid;
if (node.contains(file))
return true;
}
return false;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class MigrationPanel method selectionChanged.
private void selectionChanged() {
myConflictsPanel.setToInitialPosition();
myUsagesPanel.setToInitialPosition();
final DefaultMutableTreeNode[] migrationNodes = myRootsTree.getSelectedNodes(DefaultMutableTreeNode.class, null);
if (migrationNodes.length == 0)
return;
final Object userObject = migrationNodes[0].getUserObject();
if (userObject instanceof MigrationNode) {
final MigrationNode migrationNode = (MigrationNode) userObject;
final UsageInfo[] failedUsages = myLabeler.getFailedUsages(migrationNode.getInfo());
if (failedUsages.length > 0) {
myConflictsPanel.showUsages(PsiElement.EMPTY_ARRAY, failedUsages);
}
final AbstractTreeNode rootNode = migrationNode.getParent();
if (rootNode instanceof MigrationNode) {
myUsagesPanel.showRootUsages(((MigrationNode) rootNode).getInfo(), migrationNode.getInfo(), myLabeler);
}
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class AddToFavoritesAction method getNodesToAdd.
@NotNull
public static Collection<AbstractTreeNode> getNodesToAdd(final DataContext dataContext, final boolean inProjectView) {
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null)
return Collections.emptyList();
Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
Collection<AbstractTreeNode> nodesToAdd = null;
for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
nodesToAdd = provider.getFavoriteNodes(dataContext, ViewSettings.DEFAULT);
if (nodesToAdd != null) {
break;
}
}
if (nodesToAdd == null) {
Object elements = collectSelectedElements(dataContext);
if (elements != null) {
nodesToAdd = createNodes(project, moduleContext, elements, inProjectView, ViewSettings.DEFAULT);
}
}
return nodesToAdd == null ? Collections.<AbstractTreeNode>emptyList() : nodesToAdd;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class AddToFavoritesAction method createNodes.
@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
if (project == null)
return Collections.emptyList();
ArrayList<AbstractTreeNode> result = new ArrayList<>();
for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
if (treeNode != null) {
result.add(treeNode);
return result;
}
}
final PsiManager psiManager = PsiManager.getInstance(project);
final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
//on psi elements
if (object instanceof PsiElement[]) {
for (PsiElement psiElement : (PsiElement[]) object) {
addPsiElementNode(psiElement, project, result, favoritesConfig);
}
return result;
}
//on psi element
if (object instanceof PsiElement) {
Module containingModule = null;
if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
abstractTreeNode = abstractTreeNode.getParent();
}
if (abstractTreeNode != null) {
containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
}
}
}
addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
return result;
}
if (object instanceof VirtualFile[]) {
for (VirtualFile vFile : (VirtualFile[]) object) {
PsiElement element = psiManager.findFile(vFile);
if (element == null)
element = psiManager.findDirectory(vFile);
addPsiElementNode(element, project, result, favoritesConfig);
}
return result;
}
//on form in editor
if (object instanceof VirtualFile) {
final VirtualFile vFile = (VirtualFile) object;
final PsiFile psiFile = psiManager.findFile(vFile);
addPsiElementNode(psiFile, project, result, favoritesConfig);
return result;
}
//on module groups
if (object instanceof ModuleGroup[]) {
for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
}
return result;
}
//on module nodes
if (object instanceof Module)
object = new Module[] { (Module) object };
if (object instanceof Module[]) {
for (Module module1 : (Module[]) object) {
result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
}
return result;
}
//on library group node
if (object instanceof LibraryGroupElement[]) {
for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
}
return result;
}
//on named library node
if (object instanceof NamedLibraryElement[]) {
for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
}
return result;
}
return result;
}
Aggregations