use of com.intellij.openapi.progress.ProgressManager in project buck by facebook.
the class BuckBuildManager method runBuckCommand.
/**
* Execute simple process asynchronously with progress.
*
* @param handler a handler
* @param operationTitle an operation title shown in progress dialog
*/
public synchronized void runBuckCommand(final BuckCommandHandler handler, final String operationTitle) {
if (!(handler instanceof BuckKillCommandHandler)) {
currentRunningBuckCommandHandler = handler;
// Save files for anything besides buck kill
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
}
}, ModalityState.NON_MODAL);
}
Project project = handler.project();
String exec = BuckSettingsProvider.getInstance().getState().buckExecutable;
if (exec == null) {
BuckToolWindowFactory.outputConsoleMessage(project, "Please specify the buck executable path!\n", ConsoleViewContentType.ERROR_OUTPUT);
BuckToolWindowFactory.outputConsoleMessage(project, "Preference -> Tools -> Buck -> Path to Buck executable\n", ConsoleViewContentType.NORMAL_OUTPUT);
return;
}
final ProgressManager manager = ProgressManager.getInstance();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
manager.run(new Task.Backgroundable(handler.project(), operationTitle, true) {
public void run(final ProgressIndicator indicator) {
runInCurrentThread(handler, indicator, true, operationTitle);
}
});
}
});
}
use of com.intellij.openapi.progress.ProgressManager in project buck by facebook.
the class TestExecutionState method showProgress.
private void showProgress(final OSProcessHandler result, final String title) {
final ProgressManager manager = ProgressManager.getInstance();
ApplicationManager.getApplication().invokeLater(() -> {
manager.run(new Task.Backgroundable(mProject, title, true) {
public void run(@NotNull final ProgressIndicator indicator) {
try {
result.waitFor();
} finally {
indicator.cancel();
}
}
});
});
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class SvnConfigureProxiesDialog method execute.
public void execute(final String url) {
Messages.showInfoMessage(myProject, SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.settings.will.be.stored.text"), SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.settings.will.be.stored.title"));
if (!applyImpl()) {
return;
}
final Ref<Exception> excRef = new Ref<>();
final ProgressManager pm = ProgressManager.getInstance();
pm.runProcessWithProgressSynchronously(() -> {
final ProgressIndicator pi = pm.getProgressIndicator();
if (pi != null) {
pi.setText("Connecting to " + url);
}
try {
SvnVcs.getInstance(myProject).getInfo(SvnUtil.createUrl(url), SVNRevision.HEAD);
} catch (SvnBindException e) {
excRef.set(e);
}
}, "Test connection", true, myProject);
if (!excRef.isNull()) {
Messages.showErrorDialog(myProject, excRef.get().getMessage(), SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.error.title"));
} else {
Messages.showInfoMessage(myProject, SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.succes.text"), SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.succes.title"));
}
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GroovyImportOptimizerRefactoringHelper method performOperation.
@Override
public void performOperation(final Project project, final Set<GroovyFile> files) {
final ProgressManager progressManager = ProgressManager.getInstance();
final Map<GroovyFile, Pair<List<GrImportStatement>, Set<GrImportStatement>>> redundants = new HashMap<>();
final Runnable findUnusedImports = () -> {
final ProgressIndicator progressIndicator = progressManager.getProgressIndicator();
final int total = files.size();
int i = 0;
for (final GroovyFile file : files) {
if (!file.isValid())
continue;
final VirtualFile virtualFile = file.getVirtualFile();
if (!ProjectRootManager.getInstance(project).getFileIndex().isInSource(virtualFile)) {
continue;
}
if (progressIndicator != null) {
progressIndicator.setText2(virtualFile.getPresentableUrl());
progressIndicator.setFraction((double) i++ / total);
}
ApplicationManager.getApplication().runReadAction(() -> {
final Set<GrImportStatement> usedImports = GroovyImportUtil.findUsedImports(file);
final List<GrImportStatement> validImports = PsiUtil.getValidImportStatements(file);
redundants.put(file, Pair.create(validImports, usedImports));
});
}
};
if (!progressManager.runProcessWithProgressSynchronously(findUnusedImports, "Optimizing imports (Groovy) ... ", false, project)) {
return;
}
WriteAction.run(() -> {
for (GroovyFile groovyFile : redundants.keySet()) {
if (!groovyFile.isValid())
continue;
final Pair<List<GrImportStatement>, Set<GrImportStatement>> pair = redundants.get(groovyFile);
final List<GrImportStatement> validImports = pair.getFirst();
final Set<GrImportStatement> usedImports = pair.getSecond();
for (GrImportStatement importStatement : validImports) {
if (!usedImports.contains(importStatement)) {
groovyFile.removeImport(importStatement);
}
}
}
});
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class InstalledPackagesPanel method doUpdatePackages.
public void doUpdatePackages(@NotNull final PackageManagementService packageManagementService) {
onUpdateStarted();
ProgressManager progressManager = ProgressManager.getInstance();
progressManager.run(new Task.Backgroundable(myProject, LOADING_PACKAGES_LIST_TITLE, true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Collection<InstalledPackage> packages = Lists.newArrayList();
try {
packages = packageManagementService.getInstalledPackages();
} catch (IOException e) {
// do nothing, we already have an empty list
LOG.warn(e.getMessage());
} finally {
final Collection<InstalledPackage> finalPackages = packages;
final Map<String, RepoPackage> cache = buildNameToPackageMap(packageManagementService.getAllPackagesCached());
final boolean shouldFetchLatestVersionsForOnlyInstalledPackages = shouldFetchLatestVersionsForOnlyInstalledPackages();
if (cache.isEmpty()) {
if (!shouldFetchLatestVersionsForOnlyInstalledPackages) {
refreshLatestVersions(packageManagementService);
}
}
UIUtil.invokeLaterIfNeeded(() -> {
if (packageManagementService == myPackageManagementService) {
myPackagesTableModel.getDataVector().clear();
for (InstalledPackage pkg : finalPackages) {
RepoPackage repoPackage = cache.get(pkg.getName());
final String version = repoPackage != null ? repoPackage.getLatestVersion() : null;
myPackagesTableModel.addRow(new Object[] { pkg, pkg.getVersion(), version == null ? "" : version });
}
if (!cache.isEmpty()) {
onUpdateFinished();
}
if (shouldFetchLatestVersionsForOnlyInstalledPackages) {
setLatestVersionsForInstalledPackages();
}
}
});
}
}
});
}
Aggregations