com.intellij.ui.content.ContentManager Java Examples
The following examples show how to use
com.intellij.ui.content.ContentManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectLevelVcsManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
private Content getOrCreateConsoleContent(final ContentManager contentManager) { final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name"); Content content = contentManager.findContent(displayName); if (content == null) { releaseConsole(); myConsole = TextConsoleBuilderFactory.getInstance().createBuilder(myProject).getConsole(); JPanel panel = new JPanel(new BorderLayout()); panel.add(myConsole.getComponent(), BorderLayout.CENTER); ActionToolbar toolbar = ActionManager.getInstance() .createActionToolbar("VcsManager", new DefaultActionGroup(myConsole.createConsoleActions()), false); panel.add(toolbar.getComponent(), BorderLayout.WEST); content = ContentFactory.getInstance().createContent(panel, displayName, true); content.setDisposer(myConsoleDisposer); contentManager.addContent(content); for (Pair<String, ConsoleViewContentType> pair : myPendingOutput) { printToConsole(pair.first, pair.second); } myPendingOutput.clear(); } return content; }
Example #2
Source File: ToggleToolbarAction.java From consulo with Apache License 2.0 | 6 votes |
private ToggleToolbarAction(@Nonnull ToolWindow toolWindow, @Nonnull PropertiesComponent propertiesComponent) { super("Show Toolbar"); myPropertiesComponent = propertiesComponent; myToolWindow = toolWindow; myToolWindow.getContentManager().addContentManagerListener(new ContentManagerAdapter() { @Override public void contentAdded(ContentManagerEvent event) { JComponent component = event.getContent().getComponent(); setContentToolbarVisible(component, getVisibilityValue()); // support nested content managers, e.g. RunnerLayoutUi as content component ContentManager contentManager = component instanceof DataProvider ? ((DataProvider)component).getDataUnchecked(PlatformDataKeys.CONTENT_MANAGER) : null; if (contentManager != null) contentManager.addContentManagerListener(this); } }); }
Example #3
Source File: FlutterPerformanceView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void updateForEmptyContent(ToolWindow toolWindow) { // There's a possible race here where the tool window gets disposed while we're displaying contents. if (toolWindow.isDisposed()) { return; } toolWindow.setIcon(FlutterIcons.Flutter_13); // Display a 'No running applications' message. final ContentManager contentManager = toolWindow.getContentManager(); final JPanel panel = new JPanel(new BorderLayout()); final JBLabel label = new JBLabel("No running applications", SwingConstants.CENTER); label.setForeground(UIUtil.getLabelDisabledForeground()); panel.add(label, BorderLayout.CENTER); emptyContent = contentManager.getFactory().createContent(panel, null, false); contentManager.addContent(emptyContent); }
Example #4
Source File: PredefinedSearchScopeProviderImpl.java From consulo with Apache License 2.0 | 6 votes |
private static void addHierarchyScope(@Nonnull 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)")); } }
Example #5
Source File: FlutterView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void updateForEmptyContent(ToolWindow toolWindow) { // There's a possible race here where the tool window gets disposed while we're displaying contents. if (toolWindow.isDisposed()) { return; } toolWindow.setIcon(FlutterIcons.Flutter_13); // Display a 'No running applications' message. final ContentManager contentManager = toolWindow.getContentManager(); final JPanel panel = new JPanel(new BorderLayout()); final JBLabel label = new JBLabel("No running applications", SwingConstants.CENTER); label.setForeground(UIUtil.getLabelDisabledForeground()); panel.add(label, BorderLayout.CENTER); emptyContent = contentManager.getFactory().createContent(panel, null, false); contentManager.addContent(emptyContent); }
Example #6
Source File: FlutterView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void listenForRenderTreeActivations(@NotNull ToolWindow toolWindow) { final ContentManager contentManager = toolWindow.getContentManager(); contentManager.addContentManagerListener(new ContentManagerAdapter() { @Override public void selectionChanged(@NotNull ContentManagerEvent event) { final ContentManagerEvent.ContentOperation operation = event.getOperation(); if (operation == ContentManagerEvent.ContentOperation.add) { final String name = event.getContent().getTabName(); if (Objects.equals(name, RENDER_TAB_LABEL)) { FlutterInitializer.getAnalytics().sendEvent("inspector", "renderTreeSelected"); } else if (Objects.equals(name, WIDGET_TAB_LABEL)) { FlutterInitializer.getAnalytics().sendEvent("inspector", "widgetTreeSelected"); } } } }); }
Example #7
Source File: FileHistorySessionPartner.java From consulo with Apache License 2.0 | 6 votes |
private void createOrSelectContentIfNeeded() { ToolWindow toolWindow = getToolWindow(myVcs.getProject()); if (myRefresherI.isFirstTime()) { ContentManager manager = toolWindow.getContentManager(); boolean selectedExistingContent = ContentUtilEx.selectContent(manager, myFileHistoryPanel, true); if (!selectedExistingContent) { String tabName = myPath.getName(); if (myStartingRevisionNumber != null) { tabName += " ("; if (myStartingRevisionNumber instanceof ShortVcsRevisionNumber) { tabName += ((ShortVcsRevisionNumber)myStartingRevisionNumber).toShortString(); } else { tabName += myStartingRevisionNumber.asString(); } tabName += ")"; } ContentUtilEx.addTabbedContent(manager, myFileHistoryPanel, "History", tabName, true); } toolWindow.activate(null); } }
Example #8
Source File: CloseActiveTabAction.java From consulo with Apache License 2.0 | 6 votes |
public void actionPerformed(AnActionEvent e) { ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(e.getDataContext(), true); boolean processed = false; if (contentManager != null && contentManager.canCloseContents()) { final Content selectedContent = contentManager.getSelectedContent(); if (selectedContent != null && selectedContent.isCloseable()) { contentManager.removeContent(selectedContent, true); processed = true; } } if (!processed && contentManager != null) { final DataContext context = DataManager.getInstance().getDataContext(contentManager.getComponent()); final ToolWindow tw = context.getData(PlatformDataKeys.TOOL_WINDOW); if (tw != null) { tw.hide(null); } } }
Example #9
Source File: BuckToolWindowFactory.java From Buck-IntelliJ-Plugin with Apache License 2.0 | 6 votes |
@Override public void createToolWindowContent( @NotNull final Project project, @NotNull ToolWindow toolWindow) { toolWindow.setAvailable(true, null); toolWindow.setToHideOnEmptyContent(true); RunnerLayoutUi runnerLayoutUi = BuckUIManager.getInstance(project).getLayoutUi(project); Content consoleContent = createConsoleContent(runnerLayoutUi, project); runnerLayoutUi.addContent(consoleContent, 0, PlaceInGrid.center, false); runnerLayoutUi.getOptions().setLeftToolbar( getLeftToolbarActions(project), ActionPlaces.UNKNOWN); runnerLayoutUi.updateActionsNow(); final ContentManager contentManager = toolWindow.getContentManager(); Content content = contentManager.getFactory().createContent( runnerLayoutUi.getComponent(), "", true); contentManager.addContent(content); updateBuckToolWindowTitle(project); }
Example #10
Source File: TodoCheckinHandler.java From consulo with Apache License 2.0 | 6 votes |
private void showTodo(TodoCheckinHandlerWorker worker) { String title = "For commit (" + DateFormatUtil.formatDateTime(System.currentTimeMillis()) + ")"; ServiceManager.getService(myProject, TodoView.class).addCustomTodoView(new TodoTreeBuilderFactory() { @Override public TodoTreeBuilder createTreeBuilder(JTree tree, Project project) { return new CustomChangelistTodosTreeBuilder(tree, myProject, title, worker.inOneList()); } }, title, new TodoPanelSettings(myConfiguration.myTodoPanelSettings)); ApplicationManager.getApplication().invokeLater(() -> { ToolWindowManager manager = ToolWindowManager.getInstance(myProject); if (manager != null) { ToolWindow window = manager.getToolWindow("TODO"); if (window != null) { window.show(() -> { ContentManager cm = window.getContentManager(); Content[] contents = cm.getContents(); if (contents.length > 0) { cm.setSelectedContent(contents[contents.length - 1], true); } }); } } }, ModalityState.NON_MODAL, myProject.getDisposed()); }
Example #11
Source File: AnalyzeSizeToolWindowFactory.java From size-analyzer with Apache License 2.0 | 6 votes |
@Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { ContentManager contentManager = toolWindow.getContentManager(); AnalyzeSizeToolWindow analyzeSizeToolWindow = new AnalyzeSizeToolWindow( toolWindow, project, categorizedSuggestions, categoryDisplayOrder ); Content content = ContentFactory.SERVICE .getInstance() .createContent(analyzeSizeToolWindow.getContent(), CONTENT_TITLE, false); // We want only one content tab to exist at a time, but clearing all of them will cause the // tool window to disappear, so we add the new tab and remove the others after. contentManager.addContent(content); contentManager.setSelectedContent(content); for (Content otherContent : contentManager.getContents()) { if (otherContent != content) { contentManager.removeContent(otherContent, true); } } toolWindow.show(null); }
Example #12
Source File: ContentsUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void addOrReplaceContent(ContentManager manager, Content content, boolean select) { final String contentName = content.getDisplayName(); Content[] contents = manager.getContents(); Content oldContentFound = null; for(Content oldContent: contents) { if (!oldContent.isPinned() && oldContent.getDisplayName().equals(contentName)) { oldContentFound = oldContent; break; } } manager.addContent(content); if (oldContentFound != null) { manager.removeContent(oldContentFound, true); } if (select) { manager.setSelectedContent(content); } }
Example #13
Source File: ContentUtilEx.java From consulo with Apache License 2.0 | 6 votes |
/** * Searches through all {@link Content simple} and {@link TabbedContent tabbed} contents of the given ContentManager, * and selects the one which holds the specified {@code contentComponent}. * * @return true if the necessary content was found (and thus selected) among content components of the given ContentManager. */ public static boolean selectContent(@Nonnull ContentManager manager, @Nonnull final JComponent contentComponent, boolean requestFocus) { for (Content content : manager.getContents()) { if (content instanceof TabbedContentImpl) { boolean found = ((TabbedContentImpl)content).findAndSelectContent(contentComponent); if (found) { manager.setSelectedContent(content, requestFocus); return true; } } else if (Comparing.equal(content.getComponent(), contentComponent)) { manager.setSelectedContent(content, requestFocus); return true; } } return false; }
Example #14
Source File: TabNavigationActionBase.java From consulo with Apache License 2.0 | 6 votes |
public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { return; } ToolWindowManager windowManager = ToolWindowManager.getInstance(project); if (windowManager.isEditorComponentActive()) { doNavigate(dataContext, project); return; } ContentManager contentManager = e.getData(PlatformDataKeys.NONEMPTY_CONTENT_MANAGER); if (contentManager == null) return; doNavigate(contentManager); }
Example #15
Source File: TabNavigationActionBase.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(@Nonnull AnActionEvent event) { Presentation presentation = event.getPresentation(); Project project = event.getData(CommonDataKeys.PROJECT); presentation.setEnabled(false); if (project == null) { return; } final ToolWindowManager windowManager = ToolWindowManager.getInstance(project); if (windowManager.isEditorComponentActive()) { final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project); EditorWindow currentWindow = event.getData(EditorWindow.DATA_KEY); if (currentWindow == null) { editorManager.getCurrentWindow(); } if (currentWindow != null) { final VirtualFile[] files = currentWindow.getFiles(); presentation.setEnabled(files.length > 1); } return; } ContentManager contentManager = event.getData(PlatformDataKeys.NONEMPTY_CONTENT_MANAGER); presentation.setEnabled(contentManager != null && contentManager.getContentCount() > 1 && contentManager.isSingleSelection()); }
Example #16
Source File: VcsDockedComponent.java From p4ic4idea with Apache License 2.0 | 6 votes |
private VcsDockedComponent(final Project project) { this.project = project; ApplicationManager.getApplication().invokeLater(() -> { if (project.isDisposed()) { return; } final ToolWindow toolWindow = getToolWindow(); if (toolWindow == null) { // can happen if the project isn't fully initialized yet return; } final ContentManager contentManager = toolWindow.getContentManager(); contentManager.addContentManagerListener(new ContentManagerAdapter() { @Override public void contentRemoved(ContentManagerEvent event) { final JComponent component = event.getContent().getComponent(); if (component instanceof Disposable) { Disposer.dispose((Disposable) component); } } }); toolWindow.installWatcher(contentManager); }); }
Example #17
Source File: ContentUtilEx.java From consulo with Apache License 2.0 | 6 votes |
/** * Searches through all {@link Content simple} and {@link TabbedContent tabbed} contents of the given ContentManager, * trying to find the first one which matches the given condition. */ @Nullable public static JComponent findContentComponent(@Nonnull ContentManager manager, @Nonnull Condition<JComponent> condition) { for (Content content : manager.getContents()) { if (content instanceof TabbedContentImpl) { List<Pair<String, JComponent>> tabs = ((TabbedContentImpl)content).getTabs(); for (Pair<String, JComponent> tab : tabs) { if (condition.value(tab.second)) { return tab.second; } } } else if (condition.value(content.getComponent())) { return content.getComponent(); } } return null; }
Example #18
Source File: ContentUtilEx.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static TabbedContent findTabbedContent(@Nonnull ContentManager manager, @Nonnull String groupPrefix) { TabbedContent tabbedContent = null; for (Content content : manager.getContents()) { if (content instanceof TabbedContent && content.getTabName().startsWith(getFullPrefix(groupPrefix))) { tabbedContent = (TabbedContent)content; break; } } return tabbedContent; }
Example #19
Source File: ContentsUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void closeContentTab(@Nonnull ContentManager contentManager, @Nonnull Content content) { if (content instanceof TabbedContent) { TabbedContent tabbedContent = (TabbedContent)content; if (tabbedContent.getTabs().size() > 1) { JComponent component = tabbedContent.getComponent(); tabbedContent.removeContent(component); contentManager.setSelectedContent(tabbedContent, true, true); dispose(component); return; } } contentManager.removeContent(content, true); }
Example #20
Source File: CloseLogTabAction.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static Content getTabbedContent(@Nonnull ContentManager contentManager) { Content content = contentManager.getSelectedContent(); if (content != null) { if (ContentUtilEx.isContentTab(content, VcsLogContentProvider.TAB_NAME)) return content; } return null; }
Example #21
Source File: UnifiedToolWindowImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override protected void init(boolean canCloseContent, @Nullable Object component) { final ContentFactory contentFactory = ContentFactory.getInstance(); ContentManager contentManager = myContentManager = contentFactory.createContentManager(new UnifiedToolWindowContentUI(this), canCloseContent, myToolWindowManager.getProject()); if (component != null) { final Content content = contentFactory.createUIContent((Component)component, "", false); contentManager.addContent(content); contentManager.setSelectedContent(content, false); } myComponent = contentManager.getUIComponent(); }
Example #22
Source File: PinToolwindowTabAction.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static Content getContextContent(@Nonnull AnActionEvent event) { final ToolWindow window = event.getData(PlatformDataKeys.TOOL_WINDOW); if (window != null) { final ContentManager contentManager = window.getContentManager(); if (contentManager != null) { return contentManager.getSelectedContent(); } } return null; }
Example #23
Source File: XDebugView.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static <T> T getData(Key<T> key, @Nonnull Component component) { DataContext dataContext = DataManager.getInstance().getDataContext(component); ViewContext viewContext = dataContext.getData(ViewContext.CONTEXT_KEY); ContentManager contentManager = viewContext == null ? null : viewContext.getContentManager(); if (contentManager != null) { T data = DataManager.getInstance().getDataContext(contentManager.getComponent()).getData(key); if (data != null) { return data; } } return dataContext.getData(key); }
Example #24
Source File: ExternalSystemUtil.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Nullable public static <T> T getToolWindowElement(@Nonnull Class<T> clazz, @Nonnull Project project, @Nonnull Key<T> key, @Nonnull 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); if (data != null && clazz.isInstance(data)) { return (T)data; } } } return null; }
Example #25
Source File: ReactNativeConsole.java From react-native-console with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void focusGained(FocusEvent e) { ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(RNToolWindowFactory.TOOL_WINDOW_ID); if (toolWindow != null) { try { ContentManager contentManager = toolWindow.getContentManager(); JComponent component = contentManager.getSelectedContent().getComponent(); if (component != null) { component.requestFocusInWindow(); } } catch (Exception e1) { e1.printStackTrace(); } } }
Example #26
Source File: ProjectLevelVcsManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override public ContentManager getContentManager() { if (myContentManager == null) { ToolWindow changes = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS); myContentManager = changes == null ? null : changes.getContentManager(); } return myContentManager; }
Example #27
Source File: UpdateInfoTree.java From consulo with Apache License 2.0 | 5 votes |
public UpdateInfoTree(@Nonnull ContentManager contentManager, @Nonnull Project project, UpdatedFiles updatedFiles, String rootName, ActionInfo actionInfo) { super(contentManager, "reference.versionControl.toolwindow.update"); myActionInfo = actionInfo; myFileStatusListener = new FileStatusListener() { public void fileStatusesChanged() { myTree.repaint(); } public void fileStatusChanged(@Nonnull VirtualFile virtualFile) { myTree.repaint(); } }; myProject = project; myUpdatedFiles = updatedFiles; myRootName = rootName; myShowOnlyFilteredItems = VcsConfiguration.getInstance(myProject).UPDATE_FILTER_BY_SCOPE; myFileStatusManager = FileStatusManager.getInstance(myProject); myFileStatusManager.addFileStatusListener(myFileStatusListener); createTree(); init(); myTreeExpander = new DefaultTreeExpander(myTree); myTreeIterable = new MyTreeIterable(); }
Example #28
Source File: BuckToolWindowImpl.java From buck with Apache License 2.0 | 5 votes |
@Override public void initBuckToolWindow() { mainToolWindow = ToolWindowManager.getInstance(project).getToolWindow(MAIN_TOOL_WINDOW_ID); runToolWindow = ToolWindowManager.getInstance(project).getToolWindow(RUN_TOOL_WINDOW_ID); runnerLayoutUi.getOptions().setLeftToolbar(getLeftToolbarActions(), ActionPlaces.UNKNOWN); runnerLayoutUi.updateActionsNow(); final ContentManager contentManager = mainToolWindow.getContentManager(); Content content = contentManager.getFactory().createContent(runnerLayoutUi.getComponent(), "", true); contentManager.addContent(content); updateMainToolWindowTitleByTarget(); }
Example #29
Source File: ShTerminalRunner.java From react-native-console with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable private static Pair<Content, Process> getSuitableProcess(@NotNull ContentManager contentManager, @NotNull String workingDirectory) { Content selectedContent = contentManager.getSelectedContent(); if (selectedContent != null) { Pair<Content, Process> pair = getSuitableProcess(selectedContent, workingDirectory); if (pair != null) return pair; } return Arrays.stream(contentManager.getContents()) .map(content -> getSuitableProcess(content, workingDirectory)) .filter(Objects::nonNull) .findFirst() .orElse(null); }
Example #30
Source File: ContentUtilEx.java From consulo with Apache License 2.0 | 5 votes |
public static void addTabbedContent(@Nonnull ContentManager manager, @Nonnull JComponent contentComponent, @Nonnull String groupPrefix, @Nonnull String tabName, boolean select) { addTabbedContent(manager, contentComponent, groupPrefix, tabName, select, null); }