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;
}
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);
}
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);
}
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));
}
}
Aggregations