Java Code Examples for com.intellij.ui.content.ContentManager#setSelectedContent()
The following examples show how to use
com.intellij.ui.content.ContentManager#setSelectedContent() .
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: 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 2
Source File: RestfulWindowToolWindowFactory.java From NutzCodeInsight with Apache License 2.0 | 6 votes |
@Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { final SimpleTree apiTree = new SimpleTree(); apiTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.toolWindowEx = (ToolWindowEx) toolWindow; RefreshAction refreshAction = new RefreshAction("刷新", "重新加载URL", AllIcons.Actions.Refresh, toolWindowEx, apiTree); toolWindowEx.setTitleActions(refreshAction, actionManager.getAction("GoToRequestMapping")); apiTree.addMouseListener(new ApiTreeMouseAdapter(apiTree)); ContentManager contentManager = toolWindow.getContentManager(); Content content = contentManager.getFactory().createContent(new RestServicesNavigatorPanel(apiTree), null, false); contentManager.addContent(content); contentManager.setSelectedContent(content); if (project.isInitialized()) { refreshAction.loadTree(project); } }
Example 3
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 4
Source File: DesktopToolWindowImpl.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override protected void init(boolean canCloseContent, @Nullable Object component) { final ContentFactory contentFactory = ContentFactory.getInstance(); myContentUI = new DesktopToolWindowContentUi(this); ContentManager contentManager = myContentManager = contentFactory.createContentManager(myContentUI, canCloseContent, myToolWindowManager.getProject()); if (component != null) { final Content content = contentFactory.createContent((JComponent)component, "", false); contentManager.addContent(content); contentManager.setSelectedContent(content, false); } myComponent = contentManager.getComponent(); DesktopInternalDecorator.installFocusTraversalPolicy(myComponent, new LayoutFocusTraversalPolicy()); UiNotifyConnector notifyConnector = new UiNotifyConnector(myComponent, new Activatable() { @Override public void showNotify() { myShowing.onReady(); } }); Disposer.register(contentManager, notifyConnector); }
Example 5
Source File: ShTerminalRunner.java From react-native-console with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void run(@NotNull String command, @NotNull String workingDirectory) { TerminalView terminalView = TerminalView.getInstance(myProject); ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID); if (window == null) return; ContentManager contentManager = window.getContentManager(); Pair<Content, Process> pair = getSuitableProcess(contentManager, workingDirectory); if (pair != null) { try { window.activate(null); contentManager.setSelectedContent(pair.first); runCommand(pair.second, command); } catch (ExecutionException e) { LOG.warn("Error running terminal", e); } } else { terminalView.createNewSession(new LocalTerminalDirectRunner(myProject) { @Override protected PtyProcess createProcess(@Nullable String directory, @Nullable String commandHistoryFilePath) throws ExecutionException { PtyProcess process = super.createProcess(workingDirectory, commandHistoryFilePath); runCommand(process, command); return process; } }); } }
Example 6
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 7
Source File: SelectContentTabStep.java From consulo with Apache License 2.0 | 5 votes |
@Override public PopupStep onChosen(Integer selectedValue, boolean finalChoice) { ContentManager manager = myContent.getManager(); if(manager == null) { return FINAL_CHOICE; } myContent.selectContent(selectedValue); manager.setSelectedContent(myContent); return FINAL_CHOICE; }
Example 8
Source File: VcsDockedComponent.java From p4ic4idea with Apache License 2.0 | 5 votes |
public boolean addVcsTab(@NotNull @NonNls String title, @NotNull JComponent component, boolean showTab, boolean replaceExistingComponent) { if (component instanceof Disposable) { Disposer.register(this, (Disposable) component); } final ToolWindow toolW = getToolWindow(); if (toolW == null) { // cannot do anything return false; } final ContentManager contentManager = getToolWindow().getContentManager(); final Content existingContent = contentManager.findContent(title); if (existingContent != null) { if (!replaceExistingComponent) { contentManager.setSelectedContent(existingContent); return true; } else if (!existingContent.isPinned()) { contentManager.removeContent(existingContent, true); existingContent.release(); } } final Content content = contentManager.getFactory().createContent(component, title, false); contentManager.addContent(content); if (showTab) { getToolWindow().activate(null, false); } return true; }
Example 9
Source File: ConsoleLogToolWindowFactory.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
static void createContent(Project project, ToolWindow toolWindow, ConsoleLogConsole console, String title) { // update default Event Log tab title ContentManager contentManager = toolWindow.getContentManager(); Content generalContent = contentManager.getContent(0); if (generalContent != null && contentManager.getContentCount() == 1) { generalContent.setDisplayName("General"); } final Editor editor = console.getConsoleEditor(); SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) { @Override public Object getData(@NonNls String dataId) { return PlatformDataKeys.HELP_ID.is(dataId) ? ConsoleLog.HELP_ID : super.getData(dataId); } }; panel.setContent(editor.getComponent()); panel.addAncestorListener(new LogShownTracker(project)); ActionToolbar toolbar = createToolbar(project, editor, console); toolbar.setTargetComponent(editor.getContentComponent()); panel.setToolbar(toolbar.getComponent()); Content content = ContentFactory.SERVICE.getInstance().createContent(panel, title, false); contentManager.addContent(content); contentManager.setSelectedContent(content); }
Example 10
Source File: FlutterConsole.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Moves this console to the end of the tool window's tab list, selects it, and shows the tool window. */ void bringToFront() { // Move the tab to be last and select it. final MessageView messageView = MessageView.SERVICE.getInstance(project); final ContentManager contentManager = messageView.getContentManager(); contentManager.addContent(content); contentManager.setSelectedContent(content); // Show the panel. final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW); if (toolWindow != null) { toolWindow.activate(null, true); } }
Example 11
Source File: FlutterConsole.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Moves this console to the end of the tool window's tab list, selects it, and shows the tool window. */ void bringToFront() { // Move the tab to be last and select it. final MessageView messageView = MessageView.SERVICE.getInstance(project); final ContentManager contentManager = messageView.getContentManager(); contentManager.addContent(content); contentManager.setSelectedContent(content); // Show the panel. final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW); if (toolWindow != null) { toolWindow.activate(null, true); } }
Example 12
Source File: BrowseHierarchyActionBase.java From consulo with Apache License 2.0 | 5 votes |
public static HierarchyBrowser createAndAddToPanel(@Nonnull Project project, @Nonnull final HierarchyProvider provider, @Nonnull PsiElement target) { final HierarchyBrowser hierarchyBrowser = provider.createHierarchyBrowser(target); final Content content; final 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.getInstance().createContent(hierarchyBrowser.getComponent(), null, true); contentManager.addContent(content); } contentManager.setSelectedContent(content); hierarchyBrowser.setContent(content); final Runnable runnable = new Runnable() { @Override public void run() { provider.browserActivated(hierarchyBrowser); } }; ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY).activate(runnable); return hierarchyBrowser; }
Example 13
Source File: EventLogToolWindowFactory.java From consulo with Apache License 2.0 | 5 votes |
static void createContent(Project project, ToolWindow toolWindow, EventLogConsole console, String title) { // update default Event Log tab title ContentManager contentManager = toolWindow.getContentManager(); Content generalContent = contentManager.getContent(0); if (generalContent != null && contentManager.getContentCount() == 1) { generalContent.setDisplayName("General"); } final Editor editor = console.getConsoleEditor(); SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) { @Override public Object getData(@Nonnull @NonNls Key dataId) { return PlatformDataKeys.HELP_ID == dataId ? EventLog.HELP_ID : super.getData(dataId); } }; panel.setContent(editor.getComponent()); panel.addAncestorListener(new LogShownTracker(project)); ActionToolbar toolbar = createToolbar(project, editor, console); toolbar.setTargetComponent(editor.getContentComponent()); panel.setToolbar(toolbar.getComponent()); Content content = ContentFactory.getInstance().createContent(panel, title, false); contentManager.addContent(content); contentManager.setSelectedContent(content); }
Example 14
Source File: PreviewView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void initToolWindow(@NotNull ToolWindow toolWindow) { final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentFactory.createContent(null, null, false); content.setCloseable(false); windowPanel = new OutlineComponent(this); content.setComponent(windowPanel); windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent()); final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); tree = new OutlineTree(rootNode); tree.setCellRenderer(new OutlineTreeCellRenderer()); tree.expandAll(); initTreePopup(); // Add collapse all, expand all, and show only widgets buttons. if (toolWindow instanceof ToolWindowEx) { final ToolWindowEx toolWindowEx = (ToolWindowEx)toolWindow; final CommonActionsManager actions = CommonActionsManager.getInstance(); final TreeExpander expander = new DefaultTreeExpander(tree); final AnAction expandAllAction = actions.createExpandAllAction(expander, tree); expandAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Expandall); final AnAction collapseAllAction = actions.createCollapseAllAction(expander, tree); collapseAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Collapseall); final ShowOnlyWidgetsAction showOnlyWidgetsAction = new ShowOnlyWidgetsAction(); toolWindowEx.setTitleActions(expandAllAction, collapseAllAction, showOnlyWidgetsAction); } new TreeSpeedSearch(tree) { @Override protected String getElementText(Object element) { final TreePath path = (TreePath)element; final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); final Object object = node.getUserObject(); if (object instanceof OutlineObject) { return ((OutlineObject)object).getSpeedSearchString(); } return null; } }; tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { selectPath(selectionPath, true); } } } }); tree.addTreeSelectionListener(treeSelectionListener); scrollPane = ScrollPaneFactory.createScrollPane(tree); content.setPreferredFocusableComponent(tree); contentManager.addContent(content); contentManager.setSelectedContent(content); splitter = new Splitter(true); setSplitterProportion(getState().getSplitterProportion()); getState().addListener(e -> { final float newProportion = getState().getSplitterProportion(); if (splitter.getProportion() != newProportion) { setSplitterProportion(newProportion); } }); //noinspection Convert2Lambda splitter.addPropertyChangeListener("proportion", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!isSettingSplitterProportion) { getState().setSplitterProportion(splitter.getProportion()); } } }); scrollPane.setMinimumSize(new Dimension(1, 1)); splitter.setFirstComponent(scrollPane); windowPanel.setContent(splitter); }
Example 15
Source File: FlutterView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) { final ContentManager contentManager = toolWindow.getContentManager(); final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true); final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this); runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange); final JPanel tabContainer = new JPanel(new BorderLayout()); final String tabName; final FlutterDevice device = app.device(); if (device == null) { tabName = app.getProject().getName(); } else { final List<FlutterDevice> existingDevices = new ArrayList<>(); for (FlutterApp otherApp : perAppViewState.keySet()) { existingDevices.add(otherApp.device()); } tabName = device.getUniqueName(existingDevices); } final Content content = contentManager.getFactory().createContent(null, tabName, false); tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER); content.setComponent(tabContainer); content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE); content.setIcon(FlutterIcons.Phone); contentManager.addContent(content); if (emptyContent != null) { contentManager.removeContent(emptyContent, true); emptyContent = null; } contentManager.setSelectedContent(content); final PerAppState state = getOrCreateStateForApp(app); assert (state.content == null); state.content = content; final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService); toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent()); toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app)); final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true); final JComponent toolbarComponent = toolbar.getComponent(); toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM)); tabContainer.add(toolbarComponent, BorderLayout.NORTH); final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection(); final boolean hasInspectorService = inspectorService != null; // If the inspector is available (non-release mode), then show it. if (debugConnectionAvailable) { if (hasInspectorService) { final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported(); addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow, toolbarGroup, true, detailsSummaryViewSupported); addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService, toolWindow, toolbarGroup, false, false); } else { // If in profile mode, add disabled tabs for the inspector. addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup); addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup); } } else { // Add a message about the inspector not being available in release mode. final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER); label.setForeground(UIUtil.getLabelDisabledForeground()); tabContainer.add(label, BorderLayout.CENTER); } }
Example 16
Source File: SymfonyWebProfilerPane.java From idea-php-symfony2-plugin with MIT License | 4 votes |
public void setup(ToolWindowEx toolWindow) { ContentManager contentManager = toolWindow.getContentManager(); Content content = contentManager.getFactory().createContent(new Symfony2WebProfilerForm(this.project).createComponent(), null, true); contentManager.addContent(content); contentManager.setSelectedContent(content, true); }
Example 17
Source File: FlutterView.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) { final ContentManager contentManager = toolWindow.getContentManager(); final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true); final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this); runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange); final JPanel tabContainer = new JPanel(new BorderLayout()); final String tabName; final FlutterDevice device = app.device(); if (device == null) { tabName = app.getProject().getName(); } else { final List<FlutterDevice> existingDevices = new ArrayList<>(); for (FlutterApp otherApp : perAppViewState.keySet()) { existingDevices.add(otherApp.device()); } tabName = device.getUniqueName(existingDevices); } final Content content = contentManager.getFactory().createContent(null, tabName, false); tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER); content.setComponent(tabContainer); content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE); content.setIcon(FlutterIcons.Phone); contentManager.addContent(content); if (emptyContent != null) { contentManager.removeContent(emptyContent, true); emptyContent = null; } contentManager.setSelectedContent(content); final PerAppState state = getOrCreateStateForApp(app); assert (state.content == null); state.content = content; final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService); toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent()); toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app)); final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true); final JComponent toolbarComponent = toolbar.getComponent(); toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM)); tabContainer.add(toolbarComponent, BorderLayout.NORTH); final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection(); final boolean hasInspectorService = inspectorService != null; // If the inspector is available (non-release mode), then show it. if (debugConnectionAvailable) { if (hasInspectorService) { final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported(); addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow, toolbarGroup, true, detailsSummaryViewSupported); addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService, toolWindow, toolbarGroup, false, false); } else { // If in profile mode, add disabled tabs for the inspector. addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup); addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup); } } else { // Add a message about the inspector not being available in release mode. final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER); label.setForeground(UIUtil.getLabelDisabledForeground()); tabContainer.add(label, BorderLayout.CENTER); } }
Example 18
Source File: ContentTabLabel.java From consulo with Apache License 2.0 | 4 votes |
protected void selectContent() { final ContentManager mgr = contentManager(); if (mgr.getIndexOfContent(myContent) >= 0) { mgr.setSelectedContent(myContent, true); } }
Example 19
Source File: ProblemsView.java From consulo with Apache License 2.0 | 4 votes |
private static void selectContent(@Nonnull ContentManager manager, int index) { Content content = manager.getContent(index); if (content != null) manager.setSelectedContent(content); }
Example 20
Source File: ContentUtilEx.java From consulo with Apache License 2.0 | 4 votes |
public static void addTabbedContent(@Nonnull ContentManager manager, @Nonnull JComponent contentComponent, @Nonnull String groupPrefix, @Nonnull String tabName, boolean select, @Nullable Disposable childDisposable) { if (PropertiesComponent.getInstance().getBoolean(TabbedContent.SPLIT_PROPERTY_PREFIX + groupPrefix)) { final Content content = ContentFactory.getInstance().createContent(contentComponent, getFullName(groupPrefix, tabName), true); content.putUserData(Content.TABBED_CONTENT_KEY, Boolean.TRUE); content.putUserData(Content.TAB_GROUP_NAME_KEY, groupPrefix); for (Content c : manager.getContents()) { if (c.getComponent() == contentComponent) { if (select) { manager.setSelectedContent(c); } return; } } addContent(manager, content, select); registerDisposable(content, childDisposable, contentComponent); return; } TabbedContent tabbedContent = findTabbedContent(manager, groupPrefix); if (tabbedContent == null) { final Disposable disposable = Disposable.newDisposable(); tabbedContent = new TabbedContentImpl(contentComponent, tabName, true, groupPrefix); ContentsUtil.addOrReplaceContent(manager, tabbedContent, select); Disposer.register(tabbedContent, disposable); } else { for (Pair<String, JComponent> tab : new ArrayList<>(tabbedContent.getTabs())) { if (Comparing.equal(tab.second, contentComponent)) { tabbedContent.removeContent(tab.second); } } if (select) { manager.setSelectedContent(tabbedContent, true, true); } tabbedContent.addContent(contentComponent, tabName, true); } registerDisposable(tabbedContent, childDisposable, contentComponent); }