GroovyConsole (@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull Module module) { final ProcessHandler processHandler = createProcessHandler(module); if (processHandler == null) return null; final ConsoleViewImpl consoleView = new GroovyConsoleView(project); final RunContentDescriptor descriptor = new RunContentDescriptor( consoleView, processHandler, new JPanel(new BorderLayout()), contentFile.getNameWithoutExtension() ); final GroovyConsole console = new GroovyConsole(project, descriptor, consoleView, processHandler); // must call getComponent before createConsoleActions() final JComponent consoleViewComponent = consoleView.getComponent(); final DefaultActionGroup actionGroup = new DefaultActionGroup(); actionGroup.add(new BuildAndRestartConsoleAction(module, project, defaultExecutor, descriptor, restarter(project, contentFile))); actionGroup.addSeparator(); actionGroup.addAll(consoleView.createConsoleActions()); actionGroup.add(new CloseAction(defaultExecutor, descriptor, project) { @Override public void actionPerformed(@NotNull AnActionEvent e) { processHandler.destroyProcess(); // use force super.actionPerformed(e); } }); final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("GroovyConsole", actionGroup, false); toolbar.setTargetComponent(consoleViewComponent); final JComponent ui = descriptor.getComponent(); ui.add(consoleViewComponent, BorderLayout.CENTER); ui.add(toolbar.getComponent(), BorderLayout.WEST); processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull ProcessEvent event) { if (contentFile.getUserData(GROOVY_CONSOLE) == console) { // process terminated either by closing file or by close action contentFile.putUserData(GROOVY_CONSOLE, null); } } }); contentFile.putUserData(GROOVY_CONSOLE, console); consoleView.attachToProcess(processHandler); processHandler.startNotify(); RunContentManager.getInstance(project).showRunContent(defaultExecutor, descriptor); return console; }