Search in sources :

Example 26 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class HierarchyBrowserBase method getNavigatables.

private Navigatable[] getNavigatables() {
    final HierarchyNodeDescriptor[] selectedDescriptors = getSelectedDescriptors();
    if (selectedDescriptors == null || selectedDescriptors.length == 0)
        return null;
    final ArrayList<Navigatable> result = new ArrayList<>();
    for (HierarchyNodeDescriptor descriptor : selectedDescriptors) {
        Navigatable navigatable = getNavigatable(descriptor);
        if (navigatable != null) {
            result.add(navigatable);
        }
    }
    return result.toArray(new Navigatable[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) Navigatable(com.intellij.pom.Navigatable)

Example 27 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class NavigatableRule method getData.

@Override
public Object getData(DataProvider dataProvider) {
    final Navigatable navigatable = CommonDataKeys.NAVIGATABLE.getData(dataProvider);
    if (navigatable != null && navigatable instanceof OpenFileDescriptor) {
        final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor) navigatable;
        if (openFileDescriptor.getFile().isValid()) {
            return openFileDescriptor;
        }
    }
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
    if (element instanceof Navigatable) {
        return element;
    }
    if (element != null) {
        return EditSourceUtil.getDescriptor(element);
    }
    final Object selection = PlatformDataKeys.SELECTED_ITEM.getData(dataProvider);
    if (selection instanceof Navigatable) {
        return selection;
    }
    return null;
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable)

Example 28 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class OccurenceNavigatorSupport method goNextOccurence.

@Override
public OccurenceInfo goNextOccurence() {
    Counters counters = new Counters();
    DefaultMutableTreeNode node = findNode(myTree, true, counters);
    if (node == null)
        return null;
    TreePath treePath = new TreePath(node.getPath());
    TreeUtil.selectPath(myTree, treePath);
    Navigatable editSourceDescriptor = createDescriptorForNode(node);
    if (editSourceDescriptor == null)
        return null;
    return new OccurenceInfo(editSourceDescriptor, counters.myFoundOccurenceNumber, counters.myOccurencesCount);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Navigatable(com.intellij.pom.Navigatable)

Example 29 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class SelectInContextImpl method createContext.

@Nullable
public static SelectInContext createContext(AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    SelectInContext result = createEditorContext(dataContext);
    if (result != null) {
        return result;
    }
    JComponent sourceComponent = getEventComponent(event);
    if (sourceComponent == null) {
        return null;
    }
    SelectInContext selectInContext = SelectInContext.DATA_KEY.getData(dataContext);
    if (selectInContext == null) {
        selectInContext = createPsiContext(event);
    }
    if (selectInContext == null) {
        Navigatable descriptor = CommonDataKeys.NAVIGATABLE.getData(dataContext);
        if (descriptor instanceof OpenFileDescriptor) {
            final VirtualFile file = ((OpenFileDescriptor) descriptor).getFile();
            if (file.isValid()) {
                Project project = CommonDataKeys.PROJECT.getData(dataContext);
                selectInContext = OpenFileDescriptorContext.create(project, file);
            }
        }
    }
    if (selectInContext == null) {
        VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
        Project project = CommonDataKeys.PROJECT.getData(dataContext);
        if (virtualFile != null && project != null) {
            return new VirtualFileSelectInContext(project, virtualFile);
        }
    }
    return selectInContext;
}
Also used : SelectInContext(com.intellij.ide.SelectInContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class AbstractProjectViewPane method getData.

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        TreePath[] paths = getSelectionPaths();
        if (paths == null)
            return null;
        final ArrayList<Navigatable> navigatables = new ArrayList<>();
        for (TreePath path : paths) {
            Object lastPathComponent = path.getLastPathComponent();
            if (lastPathComponent instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastPathComponent;
                Object userObject = node.getUserObject();
                if (userObject instanceof Navigatable) {
                    navigatables.add((Navigatable) userObject);
                } else if (node instanceof Navigatable) {
                    navigatables.add((Navigatable) node);
                }
            }
        }
        if (navigatables.isEmpty()) {
            return null;
        } else {
            return navigatables.toArray(new Navigatable[navigatables.size()]);
        }
    }
    if (myTreeStructure instanceof AbstractTreeStructureBase) {
        return ((AbstractTreeStructureBase) myTreeStructure).getDataFromProviders(getSelectedNodes(AbstractTreeNode.class), dataId);
    }
    return null;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) Navigatable(com.intellij.pom.Navigatable)

Aggregations

Navigatable (com.intellij.pom.Navigatable)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)19 Project (com.intellij.openapi.project.Project)14 Nullable (org.jetbrains.annotations.Nullable)14 PsiElement (com.intellij.psi.PsiElement)11 ArrayList (java.util.ArrayList)9 PsiFile (com.intellij.psi.PsiFile)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 TreePath (javax.swing.tree.TreePath)7 NotNull (org.jetbrains.annotations.NotNull)6 Editor (com.intellij.openapi.editor.Editor)4 List (java.util.List)4 TextRange (com.intellij.openapi.util.TextRange)3 XmlTag (com.intellij.psi.xml.XmlTag)3 BlazeConsoleView (com.google.idea.blaze.base.console.BlazeConsoleView)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2