private static JTree createTree() { JTree resultsTree = new JTree(); resultsTree.setName("TREEVIEW"); resultsTree.setRootVisible(false); resultsTree.setEditable(false); resultsTree.setShowsRootHandles(true); resultsTree.setCellRenderer(new FailureCellRenderer()); ToolTipManager tipManager = ToolTipManager.sharedInstance(); tipManager.registerComponent(resultsTree); resultsTree.addKeyListener(new EnterPressListener()); return resultsTree; }
private void initTree() { myTree.setRootVisible(false); myTree.setShowsRootHandles(true); SmartExpander.installOn(myTree); TreeUtil.installActions(myTree); EditSourceOnDoubleClickHandler.install(myTree); myTree.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { TreePath leadSelectionPath = myTree.getLeadSelectionPath(); if (leadSelectionPath == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent(); if (node instanceof UsageNode) { final Usage usage = ((UsageNode) node).getUsage(); usage.navigate(false); usage.highlightInEditor(); } else if (node.isLeaf()) { Navigatable navigatable = getNavigatableForNode(node); if (navigatable != null && navigatable.canNavigate()) { navigatable.navigate(false); } } } } }); TreeUtil.selectFirstNode(myTree); PopupHandler.installPopupHandler( myTree, IdeActions.GROUP_USAGE_VIEW_POPUP, ActionPlaces.USAGE_VIEW_POPUP); // TODO: install speed search. Not in openapi though. It makes sense to create a common // TreeEnchancer service. }