public void execute(ClassEntity targetClass) { this.targetClass = targetClass; ProgressManager.getInstance().run(new Task.Backgroundable(project, "GsonFormat") { @Override public void run(@NotNull ProgressIndicator progressIndicator) { progressIndicator.setIndeterminate(true); long currentTimeMillis = System.currentTimeMillis(); execute(); progressIndicator.setIndeterminate(false); progressIndicator.setFraction(1.0); StringBuffer sb = new StringBuffer(); sb.append("GsonFormat [" + (System.currentTimeMillis() - currentTimeMillis) + " ms]\n"); // sb.append("generate class : ( "+generateClassList.size()+" )\n"); // for (String item: generateClassList) { // sb.append(" at "+item+"\n"); // } // sb.append(" \n"); // NotificationCenter.info(sb.toString()); Toast.make(project, MessageType.INFO, sb.toString()); } }); }
@Override public boolean process(T s) { ProgressManager.checkCanceled(); return super.process(s); } }
@Override public Boolean compute() throws Exception { ProgressManager.getInstance().getProgressIndicator().setText("Trying to login to Gerrit"); return testConnection(gerritAuthData); } });
/** * Runs the process that enables the set of {@link CloudLibrary apis} on GCP. * * @param apisToEnable the APIs selected by the user for enablement */ private void runApiEnablement(Set<CloudLibrary> apisToEnable) { ProgressManager.getInstance() .runProcessWithProgressSynchronously( () -> CloudApiManager.enableApis(apisToEnable, getCloudProject(), project), GoogleCloudApisMessageBundle.message("cloud.apis.enable.progress.title"), true /*canBeCanceled*/, project); }
private void initListeners() { testConnectionButton.addActionListener(actionEvent -> { ServerConfiguration configuration = createServerConfigurationForTesting(); final Ref<Exception> excRef = new Ref<>(); final ProgressManager progressManager = ProgressManager.getInstance(); progressManager.runProcessWithProgressSynchronously(() -> { final ProgressIndicator progressIndicator = progressManager.getProgressIndicator(); if (progressIndicator != null) { progressIndicator.setText("Connecting to Mongo server..."); } try { mongoManager.connect(configuration); } catch (Exception ex) { excRef.set(ex); } }, "Testing Connection", true, ServerConfigurationPanel.this.project); if (!excRef.isNull()) { Messages.showErrorDialog(rootPanel, excRef.get().getMessage(), "Connection Test Failed"); } else { Messages.showInfoMessage(rootPanel, "Connection test successful", "Connection Test Successful"); } }); }
public SonarLintJobManager(Project project, SonarLintTaskFactory taskFactory, SonarLintStatus status, SonarLintConsole console) { this(project, taskFactory, ProgressManager.getInstance(), status, console); }
try { final TreeElement finalMirrorTreeElement = mirrorTreeElement; ProgressManager.getInstance().executeNonCancelableSection(new Runnable() { public void run() { setMirror(finalMirrorTreeElement);
static List<HighlightInfo> doHighlighting(final Disposable context, final EditorEx editor, final PsiFile psiFile) { final DaemonProgressIndicator progress = new DaemonProgressIndicator(); Disposer.register(context, progress); return ProgressManager.getInstance().runProcess(new Computable<List<HighlightInfo>>() { @Override public List<HighlightInfo> compute() { final Project project = psiFile.getProject(); final DaemonCodeAnalyzerEx analyzer = DaemonCodeAnalyzerEx.getInstanceEx(project); // ensure we get fresh results; the restart also seems to // prevent the "process canceled" issue (see #30) PsiDocumentManager.getInstance(project).commitAllDocuments(); analyzer.restart(psiFile); // analyze! return analyzer.runMainPasses( psiFile, editor.getDocument(), progress); } }, progress); }
@Test public void testUserTask() { manager.submitManual(mockFiles(), TriggerType.ACTION, true, null); verify(factory).createUserTask(any(SonarLintJob.class), eq(true)); verify(app).isDispatchThread(); verify(progressManager).run(task); }
/** * Depending on the type of task (Modal or Backgroundable), it will prepare related UI and execute the task in the current thread * or in the executor. * It needs to be called from EDT because of the creation of the Indicator. */ private void runTask(SonarLintTask task) { if (myProject.isDisposed()) { return; } notifyStart(task.getJob()); if (task.isConditionalModal() || task.isModal()) { progressManager.run(task); } else { ProgressIndicator progressIndicator = new BackgroundableProcessIndicator(task); executor.submit(() -> progressManager.runProcess(() -> task.run(progressIndicator), progressIndicator)); } }
ServiceManager.getService(ProgressManager.class).getProgressIndicator();
@VisibleForTesting boolean checkIfCancelled() { return ProgressManager.getInstance().getProgressIndicator().isCanceled(); }
/** * Runs the process that creates the service account and generates the service account key file. * * @param selectedRoles the {@link Role roles} selected by the user * @param serviceAccountName the name of the service account * @param serviceAccountKeyDownloadPath the {@link Path} to the chosen download folder */ private void runServiceAccountManagement( Set<Role> selectedRoles, String serviceAccountName, Path serviceAccountKeyDownloadPath) { ProgressManager.getInstance() .runProcessWithProgressSynchronously( () -> CloudApiManager.createServiceAccountAndDownloadKey( selectedRoles, serviceAccountName, serviceAccountKeyDownloadPath, getCloudProject(), project), GoogleCloudApisMessageBundle.message( "cloud.apis.service.account.create.progress.title"), true /*canBeCanceled*/, project); }
); final ProgressManager progressManager = ProgressManager.getInstance(); progressManager.runProcessWithProgressSynchronously(() -> { final ProgressIndicator indicator = progressManager.getProgressIndicator(); if (indicator != null) { indicator.setIndeterminate(true);
@Before public void setUp() { MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(CommandUtils.class, VersionControlPath.class, TfsFileUtil.class, ProgressManager.class, VcsNotifier.class); when(mockServerContext.getUri()).thenReturn(URI.create("http://account.visualstudio.com")); when(mockTFSVcs.getServerContext(anyBoolean())).thenReturn(mockServerContext); when(ProgressManager.getInstance()).thenReturn(mockProgressManager); when(mockTFSVcs.getProject()).thenReturn(mockProject); when(VcsNotifier.getInstance(mockProject)).thenReturn(mockVcsNotifier); tfsCheckinEnvironment = new TFSCheckinEnvironment(mockTFSVcs); }
@Test public void testRunBackground() { manager.submitBackground(mockFiles(), TriggerType.ACTION, null); verify(factory).createTask(any(SonarLintJob.class), eq(true)); verify(app).isDispatchThread(); verify(progressManager).run(task); }
@Before public void setUp() throws IOException { when(googleLoginService.getLoggedInUser("user")).thenReturn(Optional.of(user)); when(progressManager.getProgressIndicator()).thenReturn(progressIndicator); when(apiClientFactory.getIamClient(any())).thenReturn(iam); when(apiClientFactory.getCloudResourceManagerClient(any())).thenReturn(resourceManager); setupFakeServiceAccount(); setupFakeServiceAccountKey(); setupFakePolicy(); setupMockIamClient(); setupMockResourceManagerClient(); testFixture .getProject() .getMessageBus() .connect() .subscribe(Notifications.TOPIC, notifications); // TODO: consider shutting down timer instead when clear what is creating the timer. ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(), "Timer-0"); }
public void executeWithProgress(boolean modal, @NotNull Consumer<Boolean> consumer) { ProgressManager.getInstance().run(new Task.Backgroundable(myProject, getPresentableName(), true) { private boolean doNotStart; @Override public void onCancel() { doNotStart = true; ProcessHandler handler = getProcessHandler(); if (handler != null) { handler.destroyProcess(); } } @Override public boolean shouldStartInBackground() { return !modal; } @Override public boolean isConditionalModal() { return modal; } @Override public void run(@NotNull ProgressIndicator indicator) { if (doNotStart || myProject == null || myProject.isDisposed()) { return; } indicator.setIndeterminate(true); consumer.consume(execute()); } }); }
/** * Sets {@code newText} to the progress indicator if available. * * @return old indicator text */ @Nullable public static String setProgressText(@Nullable String newText) { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { String oldText = indicator.getText(); indicator.setText(newText); return oldText; } return null; }
actionEvent -> { DownloadResourcesRunnable downloadResourcesRunnable = new DownloadResourcesRunnable(); ProgressManager.getInstance() .runProcessWithProgressSynchronously( downloadResourcesRunnable, "Loading SonarQube resources from server",