Search in sources :

Example 56 with RunContentDescriptor

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

the class StopAction method getActiveStoppableDescriptors.

@NotNull
private static List<RunContentDescriptor> getActiveStoppableDescriptors(final DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return Collections.emptyList();
    }
    final List<RunContentDescriptor> runningProcesses = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
    if (runningProcesses.isEmpty()) {
        return Collections.emptyList();
    }
    final List<RunContentDescriptor> activeDescriptors = new ArrayList<>();
    for (RunContentDescriptor descriptor : runningProcesses) {
        if (canBeStopped(descriptor)) {
            activeDescriptors.add(descriptor);
        }
    }
    return activeDescriptors;
}
Also used : Project(com.intellij.openapi.project.Project) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with RunContentDescriptor

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

the class StopAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(project);
    List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(dataContext);
    if (isPlaceGlobal(e)) {
        int todoSize = cancellableProcesses.size() + stoppableDescriptors.size();
        if (todoSize == 1) {
            if (!stoppableDescriptors.isEmpty()) {
                ExecutionManagerImpl.stopProcess(stoppableDescriptors.get(0));
            } else {
                cancellableProcesses.get(0).second.cancel();
            }
            return;
        }
        Pair<List<HandlerItem>, HandlerItem> handlerItems = getItemsList(cancellableProcesses, stoppableDescriptors, getRecentlyStartedContentDescriptor(dataContext));
        if (handlerItems == null || handlerItems.first.isEmpty()) {
            return;
        }
        final JBList list = new JBList(handlerItems.first);
        if (handlerItems.second != null)
            list.setSelectedValue(handlerItems.second, true);
        list.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptorAdapter() {

            @Nullable
            @Override
            public String getTextFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).displayName : null;
            }

            @Nullable
            @Override
            public Icon getIconFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).icon : null;
            }

            @Override
            public boolean hasSeparatorAboveOf(Object value) {
                return value instanceof HandlerItem && ((HandlerItem) value).hasSeparator;
            }
        }));
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setMovable(true).setTitle(handlerItems.first.size() == 1 ? "Confirm process stop" : "Stop process").setFilteringEnabled(o -> ((HandlerItem) o).displayName).setItemChoosenCallback(() -> {
            List valuesList = list.getSelectedValuesList();
            for (Object o : valuesList) {
                if (o instanceof HandlerItem)
                    ((HandlerItem) o).stop();
            }
        }).setRequestFocus(true).createPopup();
        InputEvent inputEvent = e.getInputEvent();
        Component component = inputEvent != null ? inputEvent.getComponent() : null;
        if (component != null && ActionPlaces.MAIN_TOOLBAR.equals(e.getPlace())) {
            popup.showUnderneathOf(component);
        } else if (project == null) {
            popup.showInBestPositionFor(dataContext);
        } else {
            popup.showCenteredInCurrentWindow(project);
        }
    } else {
        ExecutionManagerImpl.stopProcess(getRecentlyStartedContentDescriptor(dataContext));
    }
}
Also used : InputEvent(java.awt.event.InputEvent) AllIcons(com.intellij.icons.AllIcons) ExecutionManager(com.intellij.execution.ExecutionManager) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) ExecutionBundle(com.intellij.execution.ExecutionBundle) JBList(com.intellij.ui.components.JBList) TaskInfo(com.intellij.openapi.progress.TaskInfo) StringUtil(com.intellij.openapi.util.text.StringUtil) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) RunProfile(com.intellij.execution.configurations.RunProfile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ProcessHandler(com.intellij.execution.process.ProcessHandler) KillableProcess(com.intellij.execution.KillableProcess) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) Pair(com.intellij.openapi.util.Pair) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) Project(com.intellij.openapi.project.Project) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) JBList(com.intellij.ui.components.JBList) InputEvent(java.awt.event.InputEvent) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Pair(com.intellij.openapi.util.Pair)

Example 58 with RunContentDescriptor

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

the class ExecutionHelper method findRunningConsole.

public static Collection<RunContentDescriptor> findRunningConsole(@NotNull Project project, @NotNull NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) {
    RunContentManager contentManager = ExecutionManager.getInstance(project).getContentManager();
    final RunContentDescriptor selectedContent = contentManager.getSelectedContent();
    if (selectedContent != null) {
        final ToolWindow toolWindow = contentManager.getToolWindowByDescriptor(selectedContent);
        if (toolWindow != null && toolWindow.isVisible()) {
            if (descriptorMatcher.fun(selectedContent)) {
                return Collections.singletonList(selectedContent);
            }
        }
    }
    final ArrayList<RunContentDescriptor> result = ContainerUtil.newArrayList();
    for (RunContentDescriptor runContentDescriptor : contentManager.getAllDescriptors()) {
        if (descriptorMatcher.fun(runContentDescriptor)) {
            result.add(runContentDescriptor);
        }
    }
    return result;
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RunContentManager(com.intellij.execution.ui.RunContentManager)

Example 59 with RunContentDescriptor

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

the class EOFAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
    ProcessHandler activeProcessHandler = descriptor != null ? descriptor.getProcessHandler() : null;
    if (activeProcessHandler == null || activeProcessHandler.isProcessTerminated())
        return;
    try {
        OutputStream input = activeProcessHandler.getProcessInput();
        if (input != null) {
            ConsoleView console = e.getData(LangDataKeys.CONSOLE_VIEW);
            if (console != null) {
                console.print("^D\n", ConsoleViewContentType.SYSTEM_OUTPUT);
            }
            input.close();
        }
    } catch (IOException ignored) {
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleView(com.intellij.execution.ui.ConsoleView) OutputStream(java.io.OutputStream) ProcessHandler(com.intellij.execution.process.ProcessHandler) IOException(java.io.IOException)

Example 60 with RunContentDescriptor

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

the class GroovyConsole method createConsole.

@Nullable
public static GroovyConsole createConsole(@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull Module module) {
    final ProcessHandler processHandler = createProcessHandler(module);
    if (processHandler == null)
        return null;
    final GroovyConsoleStateService consoleStateService = GroovyConsoleStateService.getInstance(project);
    consoleStateService.setFileModule(contentFile, module);
    final String title = consoleStateService.getSelectedModuleTitle(contentFile);
    final ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
    final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, processHandler, new JPanel(new BorderLayout()), title);
    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(AnActionEvent e) {
            // use force
            processHandler.destroyProcess();
            super.actionPerformed(e);
        }
    });
    final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, false);
    toolbar.setTargetComponent(consoleViewComponent);
    final JComponent ui = descriptor.getComponent();
    ui.add(consoleViewComponent, BorderLayout.CENTER);
    ui.add(toolbar.getComponent(), BorderLayout.WEST);
    project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (file.equals(contentFile)) {
                // if file was closed then kill process and hide console content
                console.stop();
            }
        }
    });
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(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();
    ExecutionManager.getInstance(project).getContentManager().showRunContent(defaultExecutor, descriptor);
    return console;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CloseAction(com.intellij.execution.ui.actions.CloseAction) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Nullable(org.jetbrains.annotations.Nullable)

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