@Nullable public static GradleProjectStructureTreeModel getProjectStructureTreeModel( @NotNull Project project) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); final ToolWindow toolWindow = toolWindowManager.getToolWindow(GradleConstants.TOOL_WINDOW_ID); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider) component).getData(GradleDataKeys.SYNC_TREE_MODEL.getName()); if (data instanceof GradleProjectStructureTreeModel) { return (GradleProjectStructureTreeModel) data; } } } return null; }
public static void showTestResultsToolWindow( @NotNull final Project project, @NotNull final String message, boolean solved) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID); if (window == null) { toolWindowManager.registerToolWindow( StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM); window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID); new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window); } final Content[] contents = window.getContentManager().getContents(); for (Content content : contents) { final JComponent component = content.getComponent(); if (component instanceof ConsoleViewImpl) { ((ConsoleViewImpl) component).clear(); if (!solved) { ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.ERROR_OUTPUT); } else { ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.NORMAL_OUTPUT); } window.setAvailable(true, () -> {}); window.show(() -> {}); return; } } }
@Override public void showSettings() { Content selectedContent = UsageViewManager.getInstance(myProject).getSelectedContent(true); JComponent component = selectedContent == null ? null : selectedContent.getComponent(); FindInProjectManager findInProjectManager = FindInProjectManager.getInstance(myProject); findInProjectManager.findInProject(DataManager.getInstance().getDataContext(component)); }
@SuppressWarnings("unchecked") @Nullable public static <T> T getToolWindowElement( @NotNull Class<T> clazz, @NotNull Project project, @NotNull DataKey<T> key, @NotNull ProjectSystemId externalSystemId) { if (project.isDisposed() || !project.isOpen()) { return null; } final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager == null) { return null; } final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider) component).getData(key.getName()); if (data != null && clazz.isInstance(data)) { return (T) data; } } } return null; }
private void close() { MessageView messageView = MessageView.SERVICE.getInstance(myProject); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (content.getComponent() == this) { messageView.getContentManager().removeContent(content, true); return; } } }
@Nullable public static CheckStyleToolWindowPanel panelFor(final Project project) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager == null) { LOG.debug("Couldn't get tool window manager for project " + project); return null; } final ToolWindow toolWindow = toolWindowManager.getToolWindow(ID_TOOLWINDOW); if (toolWindow == null) { LOG.debug("Couldn't get tool window for ID " + ID_TOOLWINDOW); return null; } for (Content currentContent : toolWindow.getContentManager().getContents()) { if (currentContent.getComponent() instanceof CheckStyleToolWindowPanel) { return ((CheckStyleToolWindowPanel) currentContent.getComponent()); } } LOG.debug("Could not find tool window panel on tool window with ID " + ID_TOOLWINDOW); return null; }
public void actionPerformed(AnActionEvent e) { if (myContentManager != null) { Content content = myContentManager.getContent(PanelWithActionsAndCloseButton.this); if (content != null) { ContentsUtil.closeContentTab(myContentManager, content); if (content instanceof TabbedContent && ((TabbedContent) content).getTabs().size() > 1) { final TabbedContent tabbedContent = (TabbedContent) content; final JComponent component = content.getComponent(); tabbedContent.removeContent(component); myContentManager.setSelectedContent( content, true, true); // we should request focus here } else { myContentManager.removeContent(content, true); } } } }
public static void updateToolWindows() { for (Project project : ProjectManager.getInstance().getOpenProjects()) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); for (String id : toolWindowManager.getToolWindowIds()) { final ToolWindow toolWindow = toolWindowManager.getToolWindow(id); for (Content content : toolWindow.getContentManager().getContents()) { final JComponent component = content.getComponent(); if (component != null) { IJSwingUtilities.updateComponentTreeUI(component); } } final JComponent c = toolWindow.getComponent(); if (c != null) { IJSwingUtilities.updateComponentTreeUI(c); } } } }
private static void removeContents( @Nullable final Content notToRemove, @NotNull final Project myProject, @NotNull final String tabDisplayName) { MessageView messageView = ServiceManager.getService(myProject, MessageView.class); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { LOG.assertTrue(content != null); if (content.isPinned()) continue; if (tabDisplayName.equals(content.getDisplayName()) && content != notToRemove) { ErrorTreeView listErrorView = (ErrorTreeView) content.getComponent(); if (listErrorView != null) { if (messageView.getContentManager().removeContent(content, true)) { content.release(); } } } } }
public void setSelected(final AnActionEvent event, final boolean selected) { final Project project = DataKeys.PROJECT.getData(event.getDataContext()); if (project == null) { return; } final CheckStylePlugin checkStylePlugin = project.getComponent(CheckStylePlugin.class); if (checkStylePlugin == null) { throw new IllegalStateException("Couldn't get checkstyle plugin"); } final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(CheckStyleConstants.ID_TOOLWINDOW); final Content content = toolWindow.getContentManager().getContent(0); if (content != null) { final ToolWindowPanel panel = (ToolWindowPanel) content.getComponent(); panel.setDisplayingWarnings(selected); panel.filterDisplayedResults(); } }
private static void addHierarchyScope(@NotNull Project project, Collection<SearchScope> result) { final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY); if (toolWindow == null) { return; } final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentManager.getSelectedContent(); if (content == null) { return; } final String name = content.getDisplayName(); final JComponent component = content.getComponent(); if (!(component instanceof HierarchyBrowserBase)) { return; } final HierarchyBrowserBase hierarchyBrowserBase = (HierarchyBrowserBase) component; final PsiElement[] elements = hierarchyBrowserBase.getAvailableElements(); if (elements.length > 0) { result.add(new LocalSearchScope(elements, "Hierarchy '" + name + "' (visible nodes only)")); } }
public int addTab( String s, JComponent component, boolean selectTab, boolean replaceContent, boolean lockable, boolean addDefaultToolbar, @Nullable final ActionGroup toolbarActions, @NonNls String helpId) { int existing = getComponentNumNamed(s); if (existing != -1) { Content existingContent = getContentManager().getContent(existing); final JComponent existingComponent = existingContent.getComponent(); if (existingComponent instanceof DeactivateListener) { ((DeactivateListener) existingComponent).deactivated(); } if (!replaceContent) { getContentManager().setSelectedContent(existingContent); return existing; } else if (!existingContent.isPinned()) { getContentManager().removeContent(existingContent, true); existingContent.release(); } } CvsTabbedWindowComponent newComponent = new CvsTabbedWindowComponent( component, addDefaultToolbar, toolbarActions, getContentManager(), helpId); Content content = ContentFactory.SERVICE .getInstance() .createContent(newComponent.getShownComponent(), s, lockable); newComponent.setContent(content); getContentManager().addContent(content); return getComponentAt(getContentManager().getContentCount() - 1, selectTab); }
public static void restart(@NotNull Content content) { restart(content.getComponent()); }
private JTabbedPane getTabComponent(Content content) { Component[] comps = (content.getComponent()).getComponents(); JTabbedPane tabbedPane = (JTabbedPane) comps[1]; return tabbedPane; }