Example usage for com.intellij.openapi.actionSystem PlatformDataKeys TREE_EXPANDER

List of usage examples for com.intellij.openapi.actionSystem PlatformDataKeys TREE_EXPANDER

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem PlatformDataKeys TREE_EXPANDER.

Prototype

DataKey TREE_EXPANDER

To view the source code for com.intellij.openapi.actionSystem PlatformDataKeys TREE_EXPANDER.

Click Source Link

Usage

From source file:com.intellij.ide.actions.CollapseAllAction.java

License:Apache License

protected TreeExpander getExpander(DataContext dataContext) {
    return PlatformDataKeys.TREE_EXPANDER.getData(dataContext);
}

From source file:com.intellij.ide.errorTreeView.NewErrorTreeViewPanel.java

License:Apache License

@Override
public Object getData(String dataId) {
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return this;
    }//from  ww  w  . j av  a  2 s  .c o  m
    if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
        final NavigatableMessageElement selectedMessageElement = getSelectedMessageElement();
        return selectedMessageElement != null ? selectedMessageElement.getNavigatable() : null;
    } else if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return myHelpId;
    } else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
        return myTreeExpander;
    } else if (PlatformDataKeys.EXPORTER_TO_TEXT_FILE.is(dataId)) {
        return myExporterToTextFile;
    } else if (CURRENT_EXCEPTION_DATA_KEY.is(dataId)) {
        NavigatableMessageElement selectedMessageElement = getSelectedMessageElement();
        return selectedMessageElement != null ? selectedMessageElement.getData() : null;
    }
    return null;
}

From source file:com.intellij.ide.hierarchy.HierarchyBrowserBase.java

License:Apache License

@Override
@Nullable/*from   ww w.  j a  v a 2s  .  c om*/
public Object getData(@NonNls final String dataId) {
    if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement anElement = getSelectedElement();
        return anElement != null && anElement.isValid() ? anElement : super.getData(dataId);
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return getSelectedElements();
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return null;
    }
    if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
        final DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode == null)
            return null;
        final HierarchyNodeDescriptor descriptor = getDescriptor(selectedNode);
        if (descriptor == null)
            return null;
        return getNavigatable(descriptor);
    }
    if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        return getNavigatables();
    }
    if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
        final JTree tree = getCurrentTree();
        if (tree != null) {
            return new DefaultTreeExpander(tree);
        }
    }
    return super.getData(dataId);
}

From source file:com.intellij.ide.util.FileStructurePopup.java

License:Apache License

public JComponent createCenterPanel() {
    List<FileStructureFilter> fileStructureFilters = new ArrayList<FileStructureFilter>();
    List<FileStructureNodeProvider> fileStructureNodeProviders = new ArrayList<FileStructureNodeProvider>();
    if (myTreeActionsOwner != null) {
        for (Filter filter : myBaseTreeModel.getFilters()) {
            if (filter instanceof FileStructureFilter) {
                final FileStructureFilter fsFilter = (FileStructureFilter) filter;
                myTreeActionsOwner.setActionIncluded(fsFilter, true);
                fileStructureFilters.add(fsFilter);
            }//from w ww. j a  v a  2s.co m
        }

        if (myBaseTreeModel instanceof ProvidingTreeModel) {
            for (NodeProvider provider : ((ProvidingTreeModel) myBaseTreeModel).getNodeProviders()) {
                if (provider instanceof FileStructureNodeProvider) {
                    fileStructureNodeProviders.add((FileStructureNodeProvider) provider);
                }
            }
        }
    }
    final JPanel panel = new JPanel(new BorderLayout());
    JPanel comboPanel = new JPanel(new GridLayout(0, 2, 0, 0));

    final Shortcut[] F4 = ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet()
            .getShortcuts();
    final Shortcut[] ENTER = CustomShortcutSet.fromString("ENTER").getShortcuts();
    final CustomShortcutSet shortcutSet = new CustomShortcutSet(ArrayUtil.mergeArrays(F4, ENTER));
    new AnAction() {
        @Override
        public void actionPerformed(AnActionEvent e) {
            final boolean succeeded = navigateSelectedElement();
            if (succeeded) {
                unregisterCustomShortcutSet(panel);
            }
        }
    }.registerCustomShortcutSet(shortcutSet, panel);

    new AnAction() {
        @Override
        public void actionPerformed(AnActionEvent e) {
            if (mySpeedSearch != null && mySpeedSearch.isPopupActive()) {
                mySpeedSearch.hidePopup();
            } else {
                myPopup.cancel();
            }
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("ESCAPE"), myTree);

    new ClickListener() {
        @Override
        public boolean onClick(MouseEvent e, int clickCount) {
            final TreePath path = myTree.getPathForLocation(e.getX(), e.getY());
            if (path == null)
                return false; // user wants to expand/collapse a node
            navigateSelectedElement();
            return true;
        }
    }.installOn(myTree);

    for (FileStructureFilter filter : fileStructureFilters) {
        addCheckbox(comboPanel, filter);
    }

    for (FileStructureNodeProvider provider : fileStructureNodeProviders) {
        addCheckbox(comboPanel, provider);
    }
    myPreferredWidth = Math.max(comboPanel.getPreferredSize().width, 350);
    panel.add(comboPanel, BorderLayout.NORTH);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myAbstractTreeBuilder.getTree());
    scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.BOTTOM));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.add(createSouthPanel(), BorderLayout.SOUTH);
    DataManager.registerDataProvider(panel, new DataProvider() {
        @Override
        public Object getData(@NonNls String dataId) {
            if (CommonDataKeys.PROJECT.is(dataId)) {
                return myProject;
            }
            if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
                return myFileEditor;
            }
            if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
                Object node = ContainerUtil.getFirstItem(myAbstractTreeBuilder.getSelectedElements());
                if (!(node instanceof FilteringTreeStructure.FilteringNode))
                    return null;
                return getPsi((FilteringTreeStructure.FilteringNode) node);
            }
            if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
                Set<Object> nodes = myAbstractTreeBuilder.getSelectedElements();
                if (nodes.isEmpty())
                    return PsiElement.EMPTY_ARRAY;
                ArrayList<PsiElement> result = new ArrayList<PsiElement>();
                for (Object o : nodes) {
                    if (!(o instanceof FilteringTreeStructure.FilteringNode))
                        continue;
                    ContainerUtil.addIfNotNull(result, getPsi((FilteringTreeStructure.FilteringNode) o));
                }
                return ContainerUtil.toArray(result, PsiElement.ARRAY_FACTORY);
            }
            if (LangDataKeys.POSITION_ADJUSTER_POPUP.is(dataId)) {
                return myPopup;
            }
            if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
                return myTreeExpander;
            }
            return null;
        }
    });

    panel.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            myPopup.cancel();
        }
    });

    return panel;
}

From source file:com.intellij.lang.ant.config.execution.AntBuildMessageView.java

License:Apache License

@Override
public Object getData(Key<?> dataId) {
    Object data = myCurrentView.getData(dataId);
    if (data != null)
        return data;
    if (PlatformDataKeys.TREE_EXPANDER == dataId) {
        return myTreeExpander;
    }/*w  w  w . j  a v a 2 s .c o m*/
    return null;
}

From source file:com.intellij.lang.ant.config.explorer.AntExplorer.java

License:Apache License

@Nullable
public Object getData(@NonNls Key<?> dataId) {
    if (PlatformDataKeys.NAVIGATABLE == dataId) {
        final AntBuildFile buildFile = getCurrentBuildFile();
        if (buildFile == null) {
            return null;
        }/*from w  w w.j a  va2s  . co  m*/
        final VirtualFile file = buildFile.getVirtualFile();
        if (file == null) {
            return null;
        }
        final TreePath treePath = myTree.getLeadSelectionPath();
        if (treePath == null) {
            return null;
        }
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (node == null) {
            return null;
        }
        if (node.getUserObject() instanceof AntTargetNodeDescriptor) {
            final AntTargetNodeDescriptor targetNodeDescriptor = (AntTargetNodeDescriptor) node.getUserObject();
            final AntBuildTargetBase buildTarget = targetNodeDescriptor.getTarget();
            final OpenFileDescriptor descriptor = buildTarget.getOpenFileDescriptor();
            if (descriptor != null) {
                final VirtualFile descriptorFile = descriptor.getFile();
                if (descriptorFile.isValid()) {
                    return descriptor;
                }
            }
        }
        if (file.isValid()) {
            return new OpenFileDescriptor(myProject, file);
        }
    } else if (PlatformDataKeys.TREE_EXPANDER == dataId) {
        return myProject != null ? myTreeExpander : null;
    } else if (PlatformDataKeys.VIRTUAL_FILE_ARRAY == dataId) {
        final TreePath[] paths = myTree.getSelectionPaths();
        if (paths == null) {
            return null;
        }
        final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>();
        for (final TreePath path : paths) {
            for (DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
                    .getLastPathComponent(); node != null; node = (DefaultMutableTreeNode) node.getParent()) {
                final Object userObject = node.getUserObject();
                if (!(userObject instanceof AntBuildFileNodeDescriptor)) {
                    continue;
                }
                final AntBuildFile buildFile = ((AntBuildFileNodeDescriptor) userObject).getBuildFile();
                if (buildFile != null) {
                    final VirtualFile virtualFile = buildFile.getVirtualFile();
                    if (virtualFile != null && virtualFile.isValid()) {
                        result.add(virtualFile);
                    }
                }
                break;
            }
        }
        if (result.size() == 0) {
            return null;
        }
        return VfsUtil.toVirtualFileArray(result);
    }
    return super.getData(dataId);
}

From source file:com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLErrorTreeViewPanel.java

License:Open Source License

JSGraphQLErrorTreeViewPanel(Project project, String helpId, @Nullable Runnable cleanAction,
        @Nullable AnAction... actions) {
    super(project, helpId, false, false);
    myHelpId = helpId;//from  w  w  w. jav  a2s . com
    myCleanAction = cleanAction;
    myActions = actions;
    myTreeExpander = (TreeExpander) getData(PlatformDataKeys.TREE_EXPANDER.getName());
    add(createToolPanel(), BorderLayout.WEST);
    myTree.getEmptyText().setText("No Errors");
}

From source file:org.napile.idea.thermit.config.execution.AntBuildMessageView.java

License:Apache License

public Object getData(String dataId) {
    Object data = myCurrentView.getData(dataId);
    if (data != null)
        return data;
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return HelpID.ANT;
    } else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
        return myTreeExpander;
    }//from  w  ww  . ja  v a2 s. co  m
    return null;
}

From source file:org.napile.idea.thermit.config.explorer.AntExplorer.java

License:Apache License

@Nullable
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.NAVIGATABLE.is(dataId)) {
        final AntBuildFile buildFile = getCurrentBuildFile();
        if (buildFile == null) {
            return null;
        }//from  w w w.  j a v a 2 s  .  co m
        final VirtualFile file = buildFile.getVirtualFile();
        if (file == null) {
            return null;
        }
        final TreePath treePath = myTree.getLeadSelectionPath();
        if (treePath == null) {
            return null;
        }
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (node == null) {
            return null;
        }
        if (node.getUserObject() instanceof AntTargetNodeDescriptor) {
            final AntTargetNodeDescriptor targetNodeDescriptor = (AntTargetNodeDescriptor) node.getUserObject();
            final AntBuildTargetBase buildTarget = targetNodeDescriptor.getTarget();
            final OpenFileDescriptor descriptor = buildTarget.getOpenFileDescriptor();
            if (descriptor != null) {
                final VirtualFile descriptorFile = descriptor.getFile();
                if (descriptorFile.isValid()) {
                    return descriptor;
                }
            }
        }
        if (file.isValid()) {
            return new OpenFileDescriptor(myProject, file);
        }
    } else if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return HelpID.ANT;
    } else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
        return myProject != null ? myTreeExpander : null;
    } else if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        final TreePath[] paths = myTree.getSelectionPaths();
        if (paths == null) {
            return null;
        }
        final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>();
        for (final TreePath path : paths) {
            for (DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
                    .getLastPathComponent(); node != null; node = (DefaultMutableTreeNode) node.getParent()) {
                final Object userObject = node.getUserObject();
                if (!(userObject instanceof AntBuildFileNodeDescriptor)) {
                    continue;
                }
                final AntBuildFile buildFile = ((AntBuildFileNodeDescriptor) userObject).getBuildFile();
                if (buildFile != null) {
                    final VirtualFile virtualFile = buildFile.getVirtualFile();
                    if (virtualFile != null && virtualFile.isValid()) {
                        result.add(virtualFile);
                    }
                }
                break;
            }
        }
        if (result.size() == 0) {
            return null;
        }
        return VfsUtil.toVirtualFileArray(result);
    }
    return super.getData(dataId);
}