public void showRunContent( @NotNull final Executor executor, final RunContentDescriptor descriptor) { if (ApplicationManager.getApplication().isUnitTestMode()) return; final ContentManager contentManager = getContentManagerForRunner(executor); RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor); final Content content; if (oldDescriptor != null) { content = oldDescriptor.getAttachedContent(); getSyncPublisher().contentRemoved(oldDescriptor, executor); oldDescriptor.dispose(); // is of the same category, can be reused } else { content = createNewContent(contentManager, descriptor, executor); final Icon icon = descriptor.getIcon(); content.setIcon(icon == null ? executor.getToolWindowIcon() : icon); } content.setComponent(descriptor.getComponent()); content.putUserData(DESCRIPTOR_KEY, descriptor); final ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler != null) { final ProcessAdapter processAdapter = new ProcessAdapter() { public void startNotified(final ProcessEvent event) { LaterInvocator.invokeLater( new Runnable() { public void run() { final Icon icon = descriptor.getIcon(); content.setIcon(icon == null ? executor.getToolWindowIcon() : icon); } }); } public void processTerminated(final ProcessEvent event) { LaterInvocator.invokeLater( new Runnable() { public void run() { final Icon icon = descriptor.getIcon(); content.setIcon( icon == null ? executor.getDisabledIcon() : IconLoader.getTransparentIcon(icon)); } }); } }; processHandler.addProcessListener(processAdapter); final Disposable disposer = content.getDisposer(); if (disposer != null) { Disposer.register( disposer, new Disposable() { public void dispose() { processHandler.removeProcessListener(processAdapter); } }); } } content.setDisplayName(descriptor.getDisplayName()); descriptor.setAttachedContent(content); content.getManager().setSelectedContent(content); ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { ToolWindow window = ToolWindowManager.getInstance(myProject) .getToolWindow(executor.getToolWindowId()); // let's activate tool window, but don't move focus // // window.show() isn't valid here, because it will not // mark the window as "last activated" windows and thus // some action like navigation up/down in stactrace wont // work correctly window.activate(null, false, false); } }); }
@NotNull private Content createContent(String contentName) { if (project == null) { throw new IllegalStateException("Project not opened"); } ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); ToolWindow wm = ToolWindowManager.getInstance(project).getToolWindow(QUERY_RESULT_PANE); if (wm == null) { wm = toolWindowManager.registerToolWindow(QUERY_RESULT_PANE, true, ToolWindowAnchor.BOTTOM); wm.setIcon(Icons.QUERY_RESULT_PANE); wm.setToHideOnEmptyContent(true); } Content content = wm.getContentManager().findContent(contentName); if (content == null) { JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addContainerListener(new JTabbedPaneListener()); tabbedPane.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { ((JComponent) e.getComponent()).putClientProperty(JTABBED_CONTROL, e.isControlDown()); } public void keyReleased(KeyEvent e) { ((JComponent) e.getComponent()).putClientProperty(JTABBED_CONTROL, e.isControlDown()); } }); tabbedPane.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent e) { Object source = e.getSource(); Component c = e.getOppositeComponent(); } public void focusLost(FocusEvent e) { ((JComponent) e.getSource()).putClientProperty(JTABBED_CONTROL, false); } }); JPanel jpanel = new JPanel(new BorderLayout()); DefaultActionGroup actionGroup = new DefaultActionGroup("PsiActionGroup22", false); actionGroup.add( new LocalToggleAction( "Refresh Query Result", "Refresh Query Result", Icons.REFRESH_RESULTSET, REFRESH_RESULTSET)); actionGroup.add(new LocalToggleAction("Copy", "Copy", Icons.EXPORT_DATA, EXPORT_DATA)); // todo -- problem with keeping sql markers and tabs in sync // actionGroup.add(new LocalToggleAction("Close", "Close", Icons.CLOSE_PANEL, // CLOSE_PANEL)); ActionManager actionManager = ActionManager.getInstance(); ActionToolbar toolBar = actionManager.createActionToolbar("DataGridActionToolbar", actionGroup, false); jpanel.add(toolBar.getComponent(), "West"); jpanel.add(tabbedPane, "Center"); // ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); // ContentFactory contentFactory = PeerFactory.getInstance().getContentFactory(); ContentFactory contentFactory = ContentFactoryEx.getContentFactory(); content = contentFactory.createContent(jpanel, contentName, false); // content.setActions(actionGroup, "UKNOWN", null); content.setIcon(Icons.DISCONNECT); wm.getContentManager().addContent(content); } return content; }