Search in sources :

Example 1 with TaskInfo

use of com.intellij.openapi.progress.TaskInfo in project android by JetBrains.

the class GradleSyncInvoker method isBuildInProgress.

private static boolean isBuildInProgress(@NotNull Project project) {
    IdeFrame frame = ((WindowManagerEx) WindowManager.getInstance()).findFrameFor(project);
    StatusBarEx statusBar = frame == null ? null : (StatusBarEx) frame.getStatusBar();
    if (statusBar == null) {
        return false;
    }
    for (Pair<TaskInfo, ProgressIndicator> backgroundProcess : statusBar.getBackgroundProcesses()) {
        TaskInfo task = backgroundProcess.getFirst();
        if (task instanceof GradleTasksExecutor) {
            ProgressIndicator second = backgroundProcess.getSecond();
            if (second.isRunning()) {
                return true;
            }
        }
    }
    return false;
}
Also used : TaskInfo(com.intellij.openapi.progress.TaskInfo) GradleTasksExecutor(com.android.tools.idea.gradle.project.build.invoker.GradleTasksExecutor) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowManagerEx(com.intellij.openapi.wm.ex.WindowManagerEx) StatusBarEx(com.intellij.openapi.wm.ex.StatusBarEx)

Example 2 with TaskInfo

use of com.intellij.openapi.progress.TaskInfo in project intellij-community by JetBrains.

the class StopAction method getItemsList.

@Nullable
private static Pair<List<HandlerItem>, HandlerItem> getItemsList(List<Pair<TaskInfo, ProgressIndicator>> tasks, List<RunContentDescriptor> descriptors, RunContentDescriptor toSelect) {
    if (tasks.isEmpty() && descriptors.isEmpty()) {
        return null;
    }
    List<HandlerItem> items = new ArrayList<>(tasks.size() + descriptors.size());
    HandlerItem selected = null;
    for (final RunContentDescriptor descriptor : descriptors) {
        final ProcessHandler handler = descriptor.getProcessHandler();
        if (handler != null) {
            HandlerItem item = new HandlerItem(descriptor.getDisplayName(), descriptor.getIcon(), false) {

                @Override
                void stop() {
                    ExecutionManagerImpl.stopProcess(descriptor);
                }
            };
            items.add(item);
            if (descriptor == toSelect) {
                selected = item;
            }
        }
    }
    boolean hasSeparator = true;
    for (final Pair<TaskInfo, ProgressIndicator> eachPair : tasks) {
        items.add(new HandlerItem(eachPair.first.getTitle(), AllIcons.Process.Step_passive, hasSeparator) {

            @Override
            void stop() {
                eachPair.second.cancel();
            }
        });
        hasSeparator = false;
    }
    return Pair.create(items, selected);
}
Also used : TaskInfo(com.intellij.openapi.progress.TaskInfo) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) ProcessHandler(com.intellij.execution.process.ProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with TaskInfo

use of com.intellij.openapi.progress.TaskInfo in project intellij-community by JetBrains.

the class StopAction method update.

@Override
public void update(final AnActionEvent e) {
    boolean enable = false;
    Icon icon = getTemplatePresentation().getIcon();
    String description = getTemplatePresentation().getDescription();
    Presentation presentation = e.getPresentation();
    if (isPlaceGlobal(e)) {
        List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(e.getDataContext());
        List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(e.getProject());
        int todoSize = stoppableDescriptors.size() + cancellableProcesses.size();
        if (todoSize > 1) {
            presentation.setText(getTemplatePresentation().getText() + "...");
        } else if (todoSize == 1) {
            if (stoppableDescriptors.size() == 1) {
                presentation.setText(ExecutionBundle.message("stop.configuration.action.name", StringUtil.escapeMnemonics(stoppableDescriptors.get(0).getDisplayName())));
            } else {
                TaskInfo taskInfo = cancellableProcesses.get(0).first;
                presentation.setText(taskInfo.getCancelText() + " " + taskInfo.getTitle());
            }
        } else {
            presentation.setText(getTemplatePresentation().getText());
        }
        enable = todoSize > 0;
        if (todoSize > 1) {
            icon = IconUtil.addText(icon, String.valueOf(todoSize));
        }
    } else {
        RunContentDescriptor contentDescriptor = e.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
        ProcessHandler processHandler = contentDescriptor == null ? null : contentDescriptor.getProcessHandler();
        if (processHandler != null && !processHandler.isProcessTerminated()) {
            if (!processHandler.isProcessTerminating()) {
                enable = true;
            } else if (processHandler instanceof KillableProcess && ((KillableProcess) processHandler).canKillProcess()) {
                enable = true;
                icon = AllIcons.Debugger.KillProcess;
                description = "Kill process";
            }
        }
        RunProfile runProfile = e.getData(LangDataKeys.RUN_PROFILE);
        if (runProfile == null && contentDescriptor == null) {
            presentation.setText(getTemplatePresentation().getText());
        } else {
            presentation.setText(ExecutionBundle.message("stop.configuration.action.name", StringUtil.escapeMnemonics(runProfile == null ? contentDescriptor.getDisplayName() : runProfile.getName())));
        }
    }
    presentation.setEnabled(enable);
    presentation.setIcon(icon);
    presentation.setDescription(description);
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RunProfile(com.intellij.execution.configurations.RunProfile) KillableProcess(com.intellij.execution.KillableProcess) TaskInfo(com.intellij.openapi.progress.TaskInfo) ProcessHandler(com.intellij.execution.process.ProcessHandler) Pair(com.intellij.openapi.util.Pair)

Example 4 with TaskInfo

use of com.intellij.openapi.progress.TaskInfo 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)

Aggregations

TaskInfo (com.intellij.openapi.progress.TaskInfo)4 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 KillableProcess (com.intellij.execution.KillableProcess)2 RunProfile (com.intellij.execution.configurations.RunProfile)2 Pair (com.intellij.openapi.util.Pair)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 GradleTasksExecutor (com.android.tools.idea.gradle.project.build.invoker.GradleTasksExecutor)1 ExecutionBundle (com.intellij.execution.ExecutionBundle)1 ExecutionManager (com.intellij.execution.ExecutionManager)1 ExecutionManagerImpl (com.intellij.execution.impl.ExecutionManagerImpl)1 AllIcons (com.intellij.icons.AllIcons)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 ListItemDescriptorAdapter (com.intellij.openapi.ui.popup.ListItemDescriptorAdapter)1