Search in sources :

Example 6 with RunContentDescriptor

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

the class Tool method execute.

public void execute(AnActionEvent event, DataContext dataContext, long executionId, @Nullable final ProcessListener processListener) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    try {
        if (isUseConsole()) {
            ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(project, DefaultRunExecutor.getRunExecutorInstance(), new ToolRunProfile(this, dataContext)).build();
            environment.setExecutionId(executionId);
            environment.getRunner().execute(environment, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    ProcessHandler processHandler = descriptor.getProcessHandler();
                    if (processHandler != null && processListener != null) {
                        LOG.assertTrue(!processHandler.isStartNotified(), "ProcessHandler is already startNotified, the listener won't be correctly notified");
                        processHandler.addProcessListener(processListener);
                    }
                }
            });
        } else {
            GeneralCommandLine commandLine = createCommandLine(dataContext);
            if (commandLine == null) {
                return;
            }
            OSProcessHandler handler = new OSProcessHandler(commandLine);
            handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName()));
            if (processListener != null) {
                handler.addProcessListener(processListener);
            }
            handler.startNotify();
        }
    } catch (ExecutionException ex) {
        ExecutionErrorDialog.show(ex, ToolsBundle.message("tools.process.start.error"), project);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException)

Example 7 with RunContentDescriptor

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

the class RunContentExecutor method createConsole.

private ConsoleView createConsole() {
    TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(myProject);
    consoleBuilder.filters(myFilterList);
    final ConsoleView console = consoleBuilder.getConsole();
    if (myHelpId != null) {
        console.setHelpId(myHelpId);
    }
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    DefaultActionGroup actions = new DefaultActionGroup();
    final JComponent consolePanel = createConsolePanel(console, actions);
    RunContentDescriptor descriptor = new RunContentDescriptor(console, myProcess, consolePanel, myTitle);
    Disposer.register(descriptor, this);
    Disposer.register(descriptor, console);
    actions.add(new RerunAction(consolePanel));
    actions.add(new StopAction());
    actions.add(new CloseAction(executor, descriptor, myProject));
    ExecutionManager.getInstance(myProject).getContentManager().showRunContent(executor, descriptor);
    if (myActivateToolWindow) {
        activateToolWindow();
    }
    return console;
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) ConsoleView(com.intellij.execution.ui.ConsoleView) CloseAction(com.intellij.execution.ui.actions.CloseAction)

Example 8 with RunContentDescriptor

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

the class RunIdeConsoleAction method getConsoleView.

@NotNull
private static RunContentDescriptor getConsoleView(@NotNull Project project, @NotNull VirtualFile file) {
    PsiFile psiFile = ObjectUtils.assertNotNull(PsiManager.getInstance(project).findFile(file));
    WeakReference<RunContentDescriptor> ref = psiFile.getCopyableUserData(DESCRIPTOR_KEY);
    RunContentDescriptor descriptor = ref == null ? null : ref.get();
    if (descriptor == null || descriptor.getExecutionConsole() == null) {
        descriptor = createConsoleView(project, psiFile);
        psiFile.putCopyableUserData(DESCRIPTOR_KEY, new WeakReference<>(descriptor));
    }
    return descriptor;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with RunContentDescriptor

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

the class RunIdeConsoleAction method createConsoleView.

@NotNull
private static RunContentDescriptor createConsoleView(@NotNull Project project, @NotNull PsiFile psiFile) {
    ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole();
    DefaultActionGroup toolbarActions = new DefaultActionGroup();
    JComponent panel = new JPanel(new BorderLayout());
    panel.add(consoleView.getComponent(), BorderLayout.CENTER);
    ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false);
    toolbar.setTargetComponent(consoleView.getComponent());
    panel.add(toolbar.getComponent(), BorderLayout.WEST);
    final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, null, panel, psiFile.getName()) {

        @Override
        public boolean isContentReuseProhibited() {
            return true;
        }
    };
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    toolbarActions.addAll(consoleView.createConsoleActions());
    toolbarActions.add(new CloseAction(executor, descriptor, project));
    ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor);
    return descriptor;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) ConsoleView(com.intellij.execution.ui.ConsoleView) CloseAction(com.intellij.execution.ui.actions.CloseAction) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with RunContentDescriptor

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

the class ExecutionHelper method selectContentDescriptor.

public static void selectContentDescriptor(@NotNull final DataContext dataContext, @NotNull final Project project, @NotNull Collection<RunContentDescriptor> consoles, String selectDialogTitle, final Consumer<RunContentDescriptor> descriptorConsumer) {
    if (consoles.size() == 1) {
        RunContentDescriptor descriptor = consoles.iterator().next();
        descriptorConsumer.consume(descriptor);
        descriptorToFront(project, descriptor);
    } else if (consoles.size() > 1) {
        final JList list = new JBList(consoles);
        final Icon icon = DefaultRunExecutor.getRunExecutorInstance().getIcon();
        list.setCellRenderer(new ListCellRendererWrapper<RunContentDescriptor>() {

            @Override
            public void customize(final JList list, final RunContentDescriptor value, final int index, final boolean selected, final boolean hasFocus) {
                setText(value.getDisplayName());
                setIcon(icon);
            }
        });
        final PopupChooserBuilder builder = new PopupChooserBuilder(list);
        builder.setTitle(selectDialogTitle);
        builder.setItemChoosenCallback(() -> {
            final Object selectedValue = list.getSelectedValue();
            if (selectedValue instanceof RunContentDescriptor) {
                RunContentDescriptor descriptor = (RunContentDescriptor) selectedValue;
                descriptorConsumer.consume(descriptor);
                descriptorToFront(project, descriptor);
            }
        }).createPopup().showInBestPositionFor(dataContext);
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

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