Search in sources :

Example 1 with HierarchyBrowserManager

use of com.intellij.ide.hierarchy.HierarchyBrowserManager in project intellij-community by JetBrains.

the class BrowseHierarchyActionBase method createAndAddToPanel.

@NotNull
public static HierarchyBrowser createAndAddToPanel(@NotNull Project project, @NotNull final HierarchyProvider provider, @NotNull PsiElement target) {
    HierarchyBrowser hierarchyBrowser = provider.createHierarchyBrowser(target);
    final Content content;
    HierarchyBrowserManager hierarchyBrowserManager = HierarchyBrowserManager.getInstance(project);
    final ContentManager contentManager = hierarchyBrowserManager.getContentManager();
    final Content selectedContent = contentManager.getSelectedContent();
    if (selectedContent != null && !selectedContent.isPinned()) {
        content = selectedContent;
        final Component component = content.getComponent();
        if (component instanceof Disposable) {
            Disposer.dispose((Disposable) component);
        }
        content.setComponent(hierarchyBrowser.getComponent());
    } else {
        content = ContentFactory.SERVICE.getInstance().createContent(hierarchyBrowser.getComponent(), null, true);
        contentManager.addContent(content);
    }
    contentManager.setSelectedContent(content);
    hierarchyBrowser.setContent(content);
    final Runnable runnable = () -> {
        if (hierarchyBrowser instanceof HierarchyBrowserBase && ((HierarchyBrowserBase) hierarchyBrowser).isDisposed()) {
            return;
        }
        provider.browserActivated(hierarchyBrowser);
    };
    ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY).activate(runnable);
    return hierarchyBrowser;
}
Also used : Disposable(com.intellij.openapi.Disposable) Content(com.intellij.ui.content.Content) ContentManager(com.intellij.ui.content.ContentManager) HierarchyBrowser(com.intellij.ide.hierarchy.HierarchyBrowser) HierarchyBrowserManager(com.intellij.ide.hierarchy.HierarchyBrowserManager) HierarchyBrowserBase(com.intellij.ide.hierarchy.HierarchyBrowserBase) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HierarchyBrowser (com.intellij.ide.hierarchy.HierarchyBrowser)1 HierarchyBrowserBase (com.intellij.ide.hierarchy.HierarchyBrowserBase)1 HierarchyBrowserManager (com.intellij.ide.hierarchy.HierarchyBrowserManager)1 Disposable (com.intellij.openapi.Disposable)1 Content (com.intellij.ui.content.Content)1 ContentManager (com.intellij.ui.content.ContentManager)1 NotNull (org.jetbrains.annotations.NotNull)1