use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class CreateExternalAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
VirtualFile file = notNull(getIfSingle(e.getData(VcsDataKeys.VIRTUAL_FILE_STREAM)));
SelectCreateExternalTargetDialog dialog = new SelectCreateExternalTargetDialog(project, file);
if (dialog.showAndGet()) {
String url = dialog.getSelectedURL();
boolean checkout = dialog.isCheckout();
String target = dialog.getLocalTarget().trim();
new Task.Backgroundable(project, "Creating External") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
doInBackground(project, file, url, checkout, target);
}
}.queue();
}
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class SvnUtil method doUnlockFiles.
public static void doUnlockFiles(Project project, final SvnVcs activeVcs, final File[] ioFiles) throws VcsException {
final boolean force = true;
final VcsException[] exception = new VcsException[1];
final Collection<String> failedUnlocks = new ArrayList<>();
final int[] count = new int[] { ioFiles.length };
final ProgressTracker eventHandler = new ProgressTracker() {
public void consume(ProgressEvent event) {
if (event.getAction() == EventAction.UNLOCK_FAILED) {
failedUnlocks.add(event.getErrorMessage() != null ? event.getErrorMessage().getFullMessage() : event.getFile().getAbsolutePath());
count[0]--;
}
}
public void checkCancelled() {
}
};
Runnable command = () -> {
ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
try {
if (progress != null) {
progress.setText(SvnBundle.message("progress.text.unlocking.files"));
}
for (File ioFile : ioFiles) {
if (progress != null) {
progress.checkCanceled();
}
if (progress != null) {
progress.setText2(SvnBundle.message("progress.text2.processing.file", ioFile.getName()));
}
activeVcs.getFactory(ioFile).createLockClient().unlock(ioFile, force, eventHandler);
}
} catch (VcsException e) {
exception[0] = e;
}
};
ProgressManager.getInstance().runProcessWithProgressSynchronously(command, SvnBundle.message("progress.title.unlock.files"), false, project);
if (!failedUnlocks.isEmpty()) {
String[] failedFiles = ArrayUtil.toStringArray(failedUnlocks);
List<VcsException> exceptions = new ArrayList<>();
for (String file : failedFiles) {
exceptions.add(new VcsException(SvnBundle.message("exception.text.failed.to.unlock.file", file)));
}
AbstractVcsHelper.getInstance(project).showErrors(exceptions, SvnBundle.message("message.title.unlock.failures"));
}
StatusBarUtil.setStatusBarInfo(project, SvnBundle.message("message.text.files.unlocked", count[0]));
if (exception[0] != null) {
throw new VcsException(exception[0]);
}
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class PythonSdkUpdater method runActivity.
/**
* Refreshes the SDKs of the modules for the open project after some delay.
*/
@Override
public void runActivity(@NotNull final Project project) {
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode()) {
return;
}
EdtExecutorService.getScheduledExecutorInstance().schedule(() -> ProgressManager.getInstance().run(new Task.Backgroundable(project, "Updating Python Paths", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final Project project = getProject();
if (project.isDisposed()) {
return;
}
for (final Sdk sdk : getPythonSdks(project)) {
update(sdk, null, project, null);
}
}
}), INITIAL_ACTIVITY_DELAY, TimeUnit.MILLISECONDS);
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class DuplicatePropertyInspection method checkFile.
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextBase context, final RefManager refManager, final ProblemDescriptionsProcessor processor) {
if (!(file instanceof PropertiesFile))
return;
if (!context.isToCheckFile(file, this) || SuppressionUtil.inspectionResultSuppressed(file, this))
return;
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
final PropertiesFile propertiesFile = (PropertiesFile) file;
final List<IProperty> properties = propertiesFile.getProperties();
Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null)
return;
final GlobalSearchScope scope = CURRENT_FILE ? GlobalSearchScope.fileScope(file) : MODULE_WITH_DEPENDENCIES ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(file.getProject());
final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator();
final ProgressIndicator progress = ProgressWrapper.wrap(original);
ProgressManager.getInstance().runProcess(() -> {
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, property -> {
if (original != null) {
if (original.isCanceled())
return false;
original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey()));
}
processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope);
processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope);
return true;
}))
throw new ProcessCanceledException();
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
Map<String, Set<String>> keyToDifferentValues = new HashMap<>();
if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original);
}
if (CHECK_DUPLICATE_VALUES)
prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original);
if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original);
}
if (!problemDescriptors.isEmpty()) {
processor.addProblemElement(refManager.getReference(file), problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]));
}
}, progress);
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class MvcModuleStructureSynchronizer method scheduleRunActions.
private void scheduleRunActions() {
if (myProject.isDisposed())
return;
final Application app = ApplicationManager.getApplication();
if (app.isUnitTestMode()) {
if (ourGrailsTestFlag && !myProject.isInitialized()) {
runActions(computeRawActions(takeOrderSnapshot()));
}
return;
}
final Set<Pair<Object, SyncAction>> orderSnapshot = takeOrderSnapshot();
ReadTask task = new ReadTask() {
@Nullable
@Override
public Continuation performInReadAction(@NotNull final ProgressIndicator indicator) throws ProcessCanceledException {
final Set<Trinity<Module, SyncAction, MvcFramework>> actions = isUpToDate() ? computeRawActions(orderSnapshot) : Collections.<Trinity<Module, SyncAction, MvcFramework>>emptySet();
return new Continuation(() -> {
if (isUpToDate()) {
runActions(actions);
} else if (!indicator.isCanceled()) {
scheduleRunActions();
}
}, ModalityState.NON_MODAL);
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
scheduleRunActions();
}
private boolean isUpToDate() {
return !myProject.isDisposed() && orderSnapshot.equals(takeOrderSnapshot());
}
};
GuiUtils.invokeLaterIfNeeded(() -> ProgressIndicatorUtils.scheduleWithWriteActionPriority(ourExecutor, task), ModalityState.NON_MODAL);
}
Aggregations