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); } } 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() { public void actionPerformed(AnActionEvent e) { final boolean succeeded = navigateSelectedElement(); if (succeeded) { unregisterCustomShortcutSet(panel); } } }.registerCustomShortcutSet(shortcutSet, panel); new AnAction() { 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) { 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 (PlatformDataKeys.PROJECT.is(dataId)) { return myProject; } if (LangDataKeys.PSI_ELEMENT.is(dataId)) { final Object node = ContainerUtil.getFirstItem(myAbstractTreeBuilder.getSelectedElements()); if (!(node instanceof FilteringTreeStructure.FilteringNode)) return null; return getPsi((FilteringTreeStructure.FilteringNode) node); } if (LangDataKeys.POSITION_ADJUSTER_POPUP.is(dataId)) { return myPopup; } if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) { return myTreeExpander; } return null; } }); return panel; }
public StructureViewComponent( final FileEditor editor, final StructureViewModel structureViewModel, final Project project, final boolean showRootNode) { super(true, true); myProject = project; myFileEditor = editor; myTreeModel = structureViewModel; myTreeModelWrapper = new TreeModelWrapper(myTreeModel, this); SmartTreeStructure treeStructure = new SmartTreeStructure(project, myTreeModelWrapper) { public void rebuildTree() { if (!isDisposed()) { super.rebuildTree(); } } public boolean isToBuildChildrenInBackground(final Object element) { return getRootElement() == element; } protected TreeElementWrapper createTree() { return new StructureViewTreeElementWrapper(myProject, myModel.getRoot(), myModel); } @Override public String toString() { return "structure view tree structure(model=" + myTreeModel + ")"; } }; final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure.getRootElement())); myTree = new Tree(model); myTree.setRootVisible(showRootNode); myTree.setShowsRootHandles(true); myAbstractTreeBuilder = new StructureTreeBuilder( project, myTree, (DefaultTreeModel) myTree.getModel(), treeStructure, myTreeModelWrapper) { @Override protected boolean validateNode(Object child) { return isValid(child); } }; Disposer.register(this, myAbstractTreeBuilder); Disposer.register( myAbstractTreeBuilder, new Disposable() { public void dispose() { storeState(); } }); setContent(ScrollPaneFactory.createScrollPane(myAbstractTreeBuilder.getTree())); myAbstractTreeBuilder.getTree().setCellRenderer(new NodeRenderer()); myAutoScrollToSourceHandler = new MyAutoScrollToSourceHandler(); myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(myProject, this); JComponent toolbarComponent = ActionManager.getInstance() .createActionToolbar(ActionPlaces.STRUCTURE_VIEW_TOOLBAR, createActionGroup(), true) .getComponent(); setToolbar(toolbarComponent); installTree(); myCopyPasteDelegator = new CopyPasteDelegator(myProject, getTree()) { @NotNull protected PsiElement[] getSelectedElements() { return getSelectedPsiElements(); } }; }