use of com.intellij.openapi.progress.util.ProgressWindow in project intellij-community by JetBrains.
the class AbstractLayoutCodeProcessor method runLayoutCodeProcess.
private void runLayoutCodeProcess(final Runnable readAction, final Runnable writeAction) {
final ProgressWindow progressWindow = new ProgressWindow(true, myProject);
progressWindow.setTitle(myCommandName);
progressWindow.setText(myProgressText);
final ModalityState modalityState = ModalityState.current();
final Runnable process = () -> ApplicationManager.getApplication().runReadAction(readAction);
Runnable runnable = () -> {
try {
ProgressManager.getInstance().runProcess(process, progressWindow);
} catch (ProcessCanceledException e) {
return;
} catch (IndexNotReadyException e) {
LOG.warn(e);
return;
}
final Runnable writeRunnable = () -> CommandProcessor.getInstance().executeCommand(myProject, () -> {
try {
writeAction.run();
if (myPostRunnable != null) {
ApplicationManager.getApplication().invokeLater(myPostRunnable);
}
} catch (IndexNotReadyException e) {
LOG.warn(e);
}
}, myCommandName, null);
if (ApplicationManager.getApplication().isUnitTestMode()) {
writeRunnable.run();
} else {
ApplicationManager.getApplication().invokeLater(writeRunnable, modalityState, myProject.getDisposed());
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
ApplicationManager.getApplication().executeOnPooledThread(runnable);
}
}
use of com.intellij.openapi.progress.util.ProgressWindow in project intellij-community by JetBrains.
the class JavaContentEntriesEditor method addSourceRoots.
private static void addSourceRoots(@NotNull Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) {
final HashMap<ContentEntry, Collection<JavaModuleSourceRoot>> entryToRootMap = new HashMap<>();
final Map<File, ContentEntry> fileToEntryMap = new HashMap<>();
for (final ContentEntry contentEntry : contentEntries) {
final VirtualFile file = contentEntry.getFile();
if (file != null) {
entryToRootMap.put(contentEntry, null);
fileToEntryMap.put(VfsUtilCore.virtualToIoFile(file), contentEntry);
}
}
final ProgressWindow progressWindow = new ProgressWindow(true, project);
final ProgressIndicator progressIndicator = new SmoothProgressAdapter(progressWindow, project);
final Runnable searchRunnable = () -> {
final Runnable process = () -> {
for (final File file : fileToEntryMap.keySet()) {
progressIndicator.setText(ProjectBundle.message("module.paths.searching.source.roots.progress", file.getPath()));
final Collection<JavaModuleSourceRoot> roots = JavaSourceRootDetectionUtil.suggestRoots(file);
entryToRootMap.put(fileToEntryMap.get(file), roots);
}
};
progressWindow.setTitle(ProjectBundle.message("module.paths.searching.source.roots.title"));
ProgressManager.getInstance().runProcess(process, progressIndicator);
};
final Runnable addSourcesRunnable = () -> {
for (final ContentEntry contentEntry : contentEntries) {
final Collection<JavaModuleSourceRoot> suggestedRoots = entryToRootMap.get(contentEntry);
if (suggestedRoots != null) {
for (final JavaModuleSourceRoot suggestedRoot : suggestedRoots) {
final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.getDirectory());
final VirtualFile fileContent = contentEntry.getFile();
if (sourceRoot != null && fileContent != null && VfsUtilCore.isAncestor(fileContent, sourceRoot, false)) {
contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getPackagePrefix());
}
}
}
}
if (finishRunnable != null) {
finishRunnable.run();
}
};
new SwingWorker() {
@Override
public Object construct() {
searchRunnable.run();
return null;
}
@Override
public void finished() {
addSourcesRunnable.run();
}
}.start();
}
use of com.intellij.openapi.progress.util.ProgressWindow in project intellij by bazelbuild.
the class ProgressiveTaskWithProgressIndicator method submitTaskWithResult.
/**
* Runs the given task on the specified executor (defaulting to BlazeExecutor's executor) with a
* progress dialog.
*/
public <T> ListenableFuture<T> submitTaskWithResult(ProgressiveWithResult<T> progressive) {
// The progress indicator must be created on the UI thread.
final ProgressWindow indicator = UIUtil.invokeAndWaitIfNeeded(() -> {
if (modality == Modality.MODAL) {
ProgressWindow window = new ProgressWindow(cancelable, project);
window.setTitle(title);
return window;
} else {
PerformInBackgroundOption backgroundOption = modality == Modality.BACKGROUNDABLE ? PerformInBackgroundOption.DEAF : PerformInBackgroundOption.ALWAYS_BACKGROUND;
return new BackgroundableProcessIndicator(project, title, backgroundOption, "Cancel", "Cancel", cancelable);
}
});
indicator.setIndeterminate(true);
indicator.start();
final ListenableFuture<T> future = executor.submit(() -> ProgressManager.getInstance().runProcess(() -> progressive.compute(indicator), indicator));
if (cancelable) {
indicator.addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
super.cancel();
future.cancel(true);
}
});
}
return future;
}
Aggregations