Search in sources :

Example 36 with RunContentDescriptor

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

the class RunIdeConsoleAction method executeQuery.

private static void executeQuery(@NotNull Project project, @NotNull VirtualFile file, @NotNull Editor editor, @NotNull IdeScriptEngine engine) {
    String command = getCommandText(project, editor);
    if (StringUtil.isEmptyOrSpaces(command))
        return;
    String profile = getProfileText(file);
    RunContentDescriptor descriptor = getConsoleView(project, file);
    ConsoleViewImpl consoleView = (ConsoleViewImpl) descriptor.getExecutionConsole();
    prepareEngine(project, engine, descriptor);
    try {
        long ts = System.currentTimeMillis();
        //myHistoryController.getModel().addToHistory(command);
        consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT);
        consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
        String script = profile == null ? command : profile + "\n" + command;
        Object o = engine.eval(script);
        String prefix = "[" + (StringUtil.formatDuration(System.currentTimeMillis() - ts)) + "]";
        consoleView.print(prefix + "=> " + o, ConsoleViewContentType.NORMAL_OUTPUT);
        consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
    } catch (Throwable e) {
        //noinspection ThrowableResultOfMethodCallIgnored
        Throwable ex = ExceptionUtil.getRootCause(e);
        consoleView.print(ex.getClass().getSimpleName() + ": " + ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
        consoleView.print("\n", ConsoleViewContentType.ERROR_OUTPUT);
    }
    selectContent(descriptor);
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl)

Example 37 with RunContentDescriptor

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

the class ExecutionManagerImpl method restartRunProfile.

@Override
public void restartRunProfile(@NotNull final ExecutionEnvironment environment) {
    RunnerAndConfigurationSettings configuration = environment.getRunnerAndConfigurationSettings();
    List<RunContentDescriptor> runningIncompatible;
    if (configuration == null) {
        runningIncompatible = Collections.emptyList();
    } else {
        runningIncompatible = getIncompatibleRunningDescriptors(configuration);
    }
    RunContentDescriptor contentToReuse = environment.getContentToReuse();
    final List<RunContentDescriptor> runningOfTheSameType = new SmartList<>();
    if (configuration != null && configuration.isSingleton()) {
        runningOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
    } else if (isProcessRunning(contentToReuse)) {
        runningOfTheSameType.add(contentToReuse);
    }
    List<RunContentDescriptor> runningToStop = ContainerUtil.concat(runningOfTheSameType, runningIncompatible);
    if (!runningToStop.isEmpty()) {
        if (configuration != null) {
            if (!runningOfTheSameType.isEmpty() && (runningOfTheSameType.size() > 1 || contentToReuse == null || runningOfTheSameType.get(0) != contentToReuse) && !userApprovesStopForSameTypeConfigurations(environment.getProject(), configuration.getName(), runningOfTheSameType.size())) {
                return;
            }
            if (!runningIncompatible.isEmpty() && !userApprovesStopForIncompatibleConfigurations(myProject, configuration.getName(), runningIncompatible)) {
                return;
            }
        }
        for (RunContentDescriptor descriptor : runningToStop) {
            stopProcess(descriptor);
        }
    }
    if (myAwaitingRunProfiles.get(environment.getRunProfile()) == environment) {
        // defense from rerunning exactly the same ExecutionEnvironment
        return;
    }
    myAwaitingRunProfiles.put(environment.getRunProfile(), environment);
    awaitTermination(new Runnable() {

        @Override
        public void run() {
            if (myAwaitingRunProfiles.get(environment.getRunProfile()) != environment) {
                // a new rerun has been requested before starting this one, ignore this rerun
                return;
            }
            if ((DumbService.getInstance(myProject).isDumb() && !Registry.is("dumb.aware.run.configurations")) || ExecutorRegistry.getInstance().isStarting(environment)) {
                awaitTermination(this, 100);
                return;
            }
            for (RunContentDescriptor descriptor : runningOfTheSameType) {
                ProcessHandler processHandler = descriptor.getProcessHandler();
                if (processHandler != null && !processHandler.isProcessTerminated()) {
                    awaitTermination(this, 100);
                    return;
                }
            }
            myAwaitingRunProfiles.remove(environment.getRunProfile());
            start(environment);
        }
    }, 50);
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessHandler(com.intellij.execution.process.ProcessHandler) SmartList(com.intellij.util.SmartList)

Example 38 with RunContentDescriptor

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

the class CloseAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final RunContentDescriptor contentDescriptor = getContentDescriptor();
    if (contentDescriptor == null) {
        return;
    }
    final boolean removedOk = ExecutionManager.getInstance(myProject).getContentManager().removeRunContent(getExecutor(), contentDescriptor);
    if (removedOk) {
        myContentDescriptor = null;
        myExecutor = null;
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor)

Example 39 with RunContentDescriptor

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

the class RunConfigurationsComboBoxAction method setConfigurationIcon.

private static void setConfigurationIcon(final Presentation presentation, final RunnerAndConfigurationSettings settings, final Project project) {
    try {
        Icon icon = RunManagerEx.getInstanceEx(project).getConfigurationIcon(settings);
        ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
        List<RunContentDescriptor> runningDescriptors = executionManager.getRunningDescriptors(s -> s == settings);
        if (runningDescriptors.size() == 1) {
            icon = ExecutionUtil.getLiveIndicator(icon);
        }
        if (runningDescriptors.size() > 1) {
            icon = IconUtil.addText(icon, String.valueOf(runningDescriptors.size()));
        }
        presentation.setIcon(icon);
    } catch (IndexNotReadyException ignored) {
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) SizedIcon(com.intellij.ui.SizedIcon) EmptyIcon(com.intellij.util.ui.EmptyIcon) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl)

Example 40 with RunContentDescriptor

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

the class ShowRunningListAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null || project.isDisposed())
        return;
    final Ref<Pair<? extends JComponent, String>> stateRef = new Ref<>();
    final Ref<Balloon> balloonRef = new Ref<>();
    final Timer timer = UIUtil.createNamedTimer("runningLists", 250);
    ActionListener actionListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            Balloon balloon = balloonRef.get();
            if (project.isDisposed() || (balloon != null && balloon.isDisposed())) {
                timer.stop();
                return;
            }
            ArrayList<Project> projects = new ArrayList<>(Arrays.asList(ProjectManager.getInstance().getOpenProjects()));
            //List should begin with current project
            projects.remove(project);
            projects.add(0, project);
            Pair<? extends JComponent, String> state = getCurrentState(projects);
            Pair<? extends JComponent, String> prevState = stateRef.get();
            if (prevState != null && prevState.getSecond().equals(state.getSecond()))
                return;
            stateRef.set(state);
            BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(state.getFirst());
            builder.setShowCallout(false).setTitle(ExecutionBundle.message("show.running.list.balloon.title")).setBlockClicksThroughBalloon(true).setDialogMode(true).setHideOnKeyOutside(false);
            IdeFrame frame = IdeFrame.KEY.getData(e.getDataContext());
            if (frame == null) {
                frame = WindowManagerEx.getInstanceEx().getFrame(project);
            }
            if (balloon != null) {
                balloon.hide();
            }
            builder.setClickHandler(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (e.getSource() instanceof MouseEvent) {
                        MouseEvent mouseEvent = (MouseEvent) e.getSource();
                        Component component = mouseEvent.getComponent();
                        component = SwingUtilities.getDeepestComponentAt(component, mouseEvent.getX(), mouseEvent.getY());
                        Object value = ((JComponent) component).getClientProperty(KEY);
                        if (value instanceof Trinity) {
                            Project aProject = (Project) ((Trinity) value).first;
                            JFrame aFrame = WindowManager.getInstance().getFrame(aProject);
                            if (aFrame != null && !aFrame.isActive()) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(aFrame, true);
                                });
                            }
                            ExecutionManagerImpl.getInstance(aProject).getContentManager().toFrontRunContent((Executor) ((Trinity) value).second, (RunContentDescriptor) ((Trinity) value).third);
                        }
                    }
                }
            }, false);
            balloon = builder.createBalloon();
            balloonRef.set(balloon);
            JComponent component = frame.getComponent();
            RelativePoint point = new RelativePoint(component, new Point(component.getWidth(), 0));
            balloon.show(point, Balloon.Position.below);
        }
    };
    timer.addActionListener(actionListener);
    timer.setInitialDelay(0);
    timer.start();
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ArrayList(java.util.ArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) IdeFrame(com.intellij.openapi.wm.IdeFrame) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder) Executor(com.intellij.execution.Executor) Pair(com.intellij.openapi.util.Pair) MouseEvent(java.awt.event.MouseEvent) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RelativePoint(com.intellij.ui.awt.RelativePoint) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener)

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