Search in sources :

Example 1 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.

the class PydevConsoleRunnerImpl method showErrorsInConsole.

private void showErrorsInConsole(Exception e) {
    DefaultActionGroup actionGroup = new DefaultActionGroup(createRerunAction());
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, false);
    // Runner creating
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(actionToolbar.getComponent(), BorderLayout.WEST);
    NewErrorTreeViewPanel errorViewPanel = new NewErrorTreeViewPanel(myProject, null, false, false, null);
    String[] messages = StringUtil.isNotEmpty(e.getMessage()) ? StringUtil.splitByLines(e.getMessage()) : ArrayUtil.EMPTY_STRING_ARRAY;
    if (messages.length == 0) {
        messages = new String[] { "Unknown error" };
    }
    errorViewPanel.addMessage(MessageCategory.ERROR, messages, null, -1, -1, null);
    panel.add(errorViewPanel, BorderLayout.CENTER);
    final RunContentDescriptor contentDescriptor = new RunContentDescriptor(null, myProcessHandler, panel, "Error running console");
    actionGroup.add(createCloseAction(contentDescriptor));
    showContentDescriptor(contentDescriptor);
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) NewErrorTreeViewPanel(com.intellij.ide.errorTreeView.NewErrorTreeViewPanel)

Example 2 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.

the class PythonConsoleToolWindow method resetContent.

private static void resetContent(RunContentDescriptor contentDescriptor, SimpleToolWindowPanel panel, Content content) {
    RunContentDescriptor oldDescriptor = content.getDisposer() instanceof RunContentDescriptor ? (RunContentDescriptor) content.getDisposer() : null;
    if (oldDescriptor != null)
        Disposer.dispose(oldDescriptor);
    panel.setContent(contentDescriptor.getComponent());
    content.setComponent(panel);
    content.setDisposer(contentDescriptor);
    content.setPreferredFocusableComponent(contentDescriptor.getComponent());
    content.putUserData(CONTENT_DESCRIPTOR, contentDescriptor);
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor)

Example 3 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.

the class ConfigurationBasedProcessRunner method runProcess.

@Override
final void runProcess(@NotNull final String sdkPath, @NotNull final Project project, @NotNull final ProcessListener processListener, @NotNull final String tempWorkingPath) throws ExecutionException {
    ensureConsoleOk(myConsole);
    // Do not create new environment from factory, if child provided environment to rerun
    final ExecutionEnvironment executionEnvironment = // TODO: RENAME
    (myRerunExecutionEnvironment != null ? myRerunExecutionEnvironment : createExecutionEnvironment(sdkPath, project, tempWorkingPath));
    // Engine to be run after process end to post process console
    final ProcessListener consolePostprocessor = new ProcessAdapter() {

        @Override
        public void processTerminated(final ProcessEvent event) {
            super.processTerminated(event);
            ApplicationManager.getApplication().invokeAndWait(() -> prepareConsoleAfterProcessEnd(), ModalityState.NON_MODAL);
        }
    };
    /// Find all available runners to report them to the test
    myAvailableRunnersForLastRun.clear();
    for (final ProgramRunner<?> runner : ProgramRunner.PROGRAM_RUNNER_EP.getExtensions()) {
        for (final Executor executor : Executor.EXECUTOR_EXTENSION_NAME.getExtensions()) {
            if (runner.canRun(executor.getId(), executionEnvironment.getRunProfile())) {
                myAvailableRunnersForLastRun.add(runner);
            }
        }
    }
    executionEnvironment.getRunner().execute(executionEnvironment, new ProgramRunner.Callback() {

        @Override
        public void processStarted(final RunContentDescriptor descriptor) {
            final ProcessHandler handler = descriptor.getProcessHandler();
            assert handler != null : "No process handler";
            handler.addProcessListener(consolePostprocessor);
            handler.addProcessListener(processListener);
            myConsole = null;
            fetchConsoleAndSetToField(descriptor);
            assert myConsole != null : "fetchConsoleAndSetToField did not set console!";
            // Console does not work with out of this method
            final JComponent component = myConsole.getComponent();
            assert component != null;
            myLastProcessDescriptor = descriptor;
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 4 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.

the class PyExecuteSelectionAction method startConsole.

private static void startConsole(final Project project, final Consumer<PyCodeExecutor> consumer, Module context) {
    final PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(project);
    if (toolWindow != null && toolWindow.getConsoleContentDescriptors().size() > 0) {
        toolWindow.activate(() -> {
            List<RunContentDescriptor> descs = toolWindow.getConsoleContentDescriptors();
            RunContentDescriptor descriptor = descs.get(0);
            if (descriptor != null && descriptor.getExecutionConsole() instanceof PyCodeExecutor) {
                consumer.consume((PyCodeExecutor) descriptor.getExecutionConsole());
            }
        });
    } else {
        PythonConsoleRunnerFactory consoleRunnerFactory = PythonConsoleRunnerFactory.getInstance();
        PydevConsoleRunner runner = consoleRunnerFactory.createConsoleRunner(project, null);
        runner.addConsoleListener(new PydevConsoleRunner.ConsoleListener() {

            @Override
            public void handleConsoleInitialized(LanguageConsoleView consoleView) {
                if (consoleView instanceof PyCodeExecutor) {
                    consumer.consume((PyCodeExecutor) consoleView);
                    if (toolWindow != null) {
                        toolWindow.getToolWindow().show(null);
                    }
                }
            }
        });
        runner.run();
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView)

Example 5 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.

the class PyExecuteSelectionAction method getConsoles.

private static Collection<RunContentDescriptor> getConsoles(Project project) {
    PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(project);
    if (toolWindow != null && toolWindow.getToolWindow().isVisible()) {
        RunContentDescriptor selectedContentDescriptor = toolWindow.getSelectedContentDescriptor();
        return selectedContentDescriptor != null ? Lists.newArrayList(selectedContentDescriptor) : Lists.newArrayList();
    }
    Collection<RunContentDescriptor> descriptors = ExecutionHelper.findRunningConsole(project, dom -> dom.getExecutionConsole() instanceof PyCodeExecutor && isAlive(dom));
    if (descriptors.isEmpty() && toolWindow != null) {
        return toolWindow.getConsoleContentDescriptors();
    } else {
        return descriptors;
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor)

Aggregations

RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)70 ProcessHandler (com.intellij.execution.process.ProcessHandler)26 Project (com.intellij.openapi.project.Project)18 NotNull (org.jetbrains.annotations.NotNull)14 Nullable (org.jetbrains.annotations.Nullable)13 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)11 Executor (com.intellij.execution.Executor)10 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 ExecutionException (com.intellij.execution.ExecutionException)7 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)7 ArrayList (java.util.ArrayList)7 ProgramRunner (com.intellij.execution.runners.ProgramRunner)6 ExecutionResult (com.intellij.execution.ExecutionResult)5 RunProfile (com.intellij.execution.configurations.RunProfile)5 CloseAction (com.intellij.execution.ui.actions.CloseAction)5 Pair (com.intellij.openapi.util.Pair)5 IOException (java.io.IOException)5 RunContentManager (com.intellij.execution.ui.RunContentManager)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4