use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class ConvertParameterToMapEntryIntention method collectOwnerOccurrences.
private static boolean collectOwnerOccurrences(final Project project, final GrParametersOwner owner, final Collection<PsiElement> occurrences) {
final PsiElement namedElem = getReferencedElement(owner);
if (namedElem == null)
return true;
final Ref<Boolean> result = new Ref<>(true);
final Task task = new Task.Modal(project, GroovyIntentionsBundle.message("find.method.ro.closure.usages.0", owner instanceof GrClosableBlock ? CLOSURE_CAPTION : METHOD_CAPTION), true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
final Collection<PsiReference> references = Collections.synchronizedSet(new HashSet<PsiReference>());
final Processor<PsiReference> consumer = psiReference -> {
references.add(psiReference);
return true;
};
ReferencesSearch.search(namedElem).forEach(consumer);
boolean isProperty = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return namedElem instanceof GrField && ((GrField) namedElem).isProperty();
}
});
if (isProperty) {
final GrAccessorMethod[] getters = ApplicationManager.getApplication().runReadAction(new Computable<GrAccessorMethod[]>() {
@Override
public GrAccessorMethod[] compute() {
return ((GrField) namedElem).getGetters();
}
});
for (GrAccessorMethod getter : getters) {
MethodReferencesSearch.search(getter).forEach(consumer);
}
}
for (final PsiReference reference : references) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = reference.getElement();
if (element != null) {
occurrences.add(element);
}
});
}
}
@Override
public void onCancel() {
result.set(false);
}
@Override
public void onThrowable(@NotNull Throwable error) {
super.onThrowable(error);
result.set(false);
}
@Override
public void onSuccess() {
result.set(true);
}
};
ProgressManager.getInstance().run(task);
return result.get().booleanValue();
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class PythonSdkUpdater method update.
/**
* Updates the paths of an SDK and regenerates its skeletons as a background task.
*
* May be invoked from any thread. May freeze the current thread while evaluating sys.path.
*
* For a local SDK it commits all the SDK paths and runs a background task for updating skeletons. For a remote SDK it runs a background
* task for updating skeletons that saves path mappings in the additional SDK data and then commits all the SDK paths.
*
* The commit of the changes in the SDK happens in the AWT thread while the current thread is waiting the result.
*
* @param sdkModificator if null then it tries to get an SDK modifier from the SDK table, falling back to the modifier of the SDK
* passed as an argument accessed from the AWT thread
* @return false if there was an immediate problem updating the SDK. Other problems are reported as log entries and balloons.
*/
public static boolean update(@NotNull Sdk sdk, @Nullable SdkModificator sdkModificator, @Nullable final Project project, @Nullable final Component ownerComponent) {
final String key = PythonSdkType.getSdkKey(sdk);
synchronized (ourLock) {
ourScheduledToRefresh.add(key);
}
if (!updateLocalSdkPaths(sdk, sdkModificator, project)) {
return false;
}
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode()) {
// updates skeleton, see PySkeletonRefresher
return true;
}
@SuppressWarnings("ThrowableInstanceNeverThrown") final Throwable methodCallStacktrace = new Throwable();
application.invokeLater(() -> {
synchronized (ourLock) {
if (!ourScheduledToRefresh.contains(key)) {
return;
}
ourScheduledToRefresh.remove(key);
}
if (project != null && project.isDisposed()) {
return;
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, PyBundle.message("sdk.gen.updating.interpreter"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final Project project1 = getProject();
final Sdk sdkInsideTask = PythonSdkType.findSdkByKey(key);
if (sdkInsideTask != null) {
ourUnderRefresh.put(key);
try {
final String skeletonsPath = getBinarySkeletonsPath(sdk.getHomePath());
try {
if (PythonSdkType.isRemote(sdkInsideTask) && project1 == null && ownerComponent == null) {
LOG.error("For refreshing skeletons of remote SDK, either project or owner component must be specified");
}
final String sdkPresentableName = getSdkPresentableName(sdk);
LOG.info("Performing background update of skeletons for SDK " + sdkPresentableName);
indicator.setText("Updating skeletons...");
PySkeletonRefresher.refreshSkeletonsOfSdk(project1, ownerComponent, skeletonsPath, sdkInsideTask);
updateRemoteSdkPaths(sdkInsideTask, getProject());
indicator.setIndeterminate(true);
indicator.setText("Scanning installed packages...");
indicator.setText2("");
LOG.info("Performing background scan of packages for SDK " + sdkPresentableName);
try {
PyPackageManager.getInstance(sdkInsideTask).refreshAndGetPackages(true);
} catch (ExecutionException e) {
if (LOG.isDebugEnabled()) {
e.initCause(methodCallStacktrace);
LOG.debug(e);
} else {
LOG.warn(e.getMessage());
}
}
} catch (InvalidSdkException e) {
if (PythonSdkType.isVagrant(sdkInsideTask) || new CredentialsTypeExChecker() {
@Override
protected boolean checkLanguageContribution(PyCredentialsContribution languageContribution) {
return languageContribution.shouldNotifySdkSkeletonFail();
}
}.check(sdkInsideTask)) {
PythonSdkType.notifyRemoteSdkSkeletonsFail(e, () -> {
final Sdk sdkInsideNotify = PythonSdkType.findSdkByKey(key);
if (sdkInsideNotify != null) {
update(sdkInsideNotify, null, project1, ownerComponent);
}
});
} else if (!PythonSdkType.isInvalid(sdkInsideTask)) {
LOG.error(e);
}
}
} finally {
try {
ourUnderRefresh.remove(key);
} catch (IllegalStateException e) {
LOG.error(e);
}
}
}
}
});
}, ModalityState.NON_MODAL);
return true;
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class CCPushTask method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
return;
}
final PsiDirectory lessonDir = taskDir.getParentDirectory();
if (lessonDir == null)
return;
final Lesson lesson = course.getLesson(lessonDir.getName());
if (lesson == null)
return;
final com.jetbrains.edu.learning.courseFormat.Task task = lesson.getTask(taskDir.getName());
if (task == null)
return;
ProgressManager.getInstance().run(new Task.Modal(project, "Uploading Task", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText("Uploading task to " + EduStepicNames.STEPIC_URL);
if (task.getStepId() <= 0) {
CCStepicConnector.postTask(project, task, lesson.getId());
} else {
CCStepicConnector.updateTask(project, task);
}
}
});
}
use of com.intellij.openapi.progress.Task in project android by JetBrains.
the class FirstRunWizardHost method runSensitiveOperation.
@Override
public void runSensitiveOperation(@NotNull ProgressIndicator progressIndicator, boolean cancellable, @NotNull final Runnable operation) {
final Application application = ApplicationManager.getApplication();
application.assertIsDispatchThread();
if (!myCurrentProgressIndicator.compareAndSet(null, progressIndicator)) {
throw new IllegalStateException("Submitting an operation while another is in progress.");
}
final JRootPane rootPane = myFrame.getRootPane();
final JButton defaultButton = rootPane.getDefaultButton();
rootPane.setDefaultButton(null);
updateButtons(false, false, true, false);
Task.Backgroundable task = new LongRunningOperationWrapper(operation, cancellable, defaultButton);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, progressIndicator);
}
use of com.intellij.openapi.progress.Task in project android by JetBrains.
the class NewGradleSync method sync.
@Override
public void sync(@NotNull Project project, @NotNull GradleSyncInvoker.Request request, @Nullable GradleSyncListener listener) {
String title = String.format("Syncing project '%1$s' with Gradle", project.getName());
Task task;
ProgressExecutionMode executionMode = request.getProgressExecutionMode();
switch(executionMode) {
case MODAL_SYNC:
task = new Task.Modal(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
sync(project, indicator, listener);
}
};
break;
case IN_BACKGROUND_ASYNC:
task = new Task.Backgroundable(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
sync(project, indicator, listener);
}
};
break;
default:
throw new IllegalArgumentException(executionMode + " is not a supported execution mode");
}
invokeAndWaitIfNeeded((Runnable) task::queue);
}
Aggregations