Java Code Examples for com.intellij.openapi.progress.ProgressIndicator#setIndeterminate()

The following examples show how to use com.intellij.openapi.progress.ProgressIndicator#setIndeterminate() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: consulo   File: VcsLogRefresherImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(@Nonnull ProgressIndicator indicator) {
  LOG.debug("Refresh task started");
  indicator.setIndeterminate(true);
  DataPack dataPack = myCurrentDataPack;
  while (true) {
    List<RefreshRequest> requests = mySingleTaskController.popRequests();
    Collection<VirtualFile> rootsToRefresh = getRootsToRefresh(requests);
    LOG.debug("Requests: " + requests + ". roots to refresh: " + rootsToRefresh);
    if (rootsToRefresh.isEmpty()) {
      mySingleTaskController.taskCompleted(dataPack);
      break;
    }
    dataPack = doRefresh(rootsToRefresh);
  }
}
 
Example 2
@Override
public void startBackgroundTask(@Nonnull final MMDPrintPanel source, @Nonnull final String taskName, @Nonnull final Runnable task) {
  final Task.Backgroundable backgroundTask = new Task.Backgroundable(this.project, taskName) {
    @Override
    public void run(@Nonnull final ProgressIndicator indicator) {
      try {
        indicator.setIndeterminate(true);
        task.run();
        IdeaUtils.showPopup(String.format("%s has been sent to the printer", taskName), MessageType.INFO);
      } catch (Exception ex) {
        LOGGER.error("Print error", ex);
        IdeaUtils.showPopup("Print error! See the log!", MessageType.ERROR);
      } finally {
        indicator.stop();
      }
    }
  };
  ProgressManager.getInstance().run(backgroundTask);
}
 
Example 3
Source Project: railways   File: RoutesManager.java    License: MIT License 6 votes vote down vote up
@Override
public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Updating route list for module "  +
            getModule().getName() + "...");
    indicator.setFraction(0.0);
    indicator.setIndeterminate(false);

    // Save indicator to be able to cancel task execution.
    routesUpdateIndicator = indicator;

    output = RailwaysUtils.queryRakeRoutes(getModule(),
            myModuleSettings.routesTaskName,
            myModuleSettings.environment);

    if (output == null)
        setState(UPDATED);

    indicator.setFraction(1.0);
}
 
Example 4
@Override
public boolean cancel(@Nonnull final ProgressIndicator indicator, @Nonnull ExternalSystemTaskNotificationListener... listeners) {
  indicator.setIndeterminate(true);
  ExternalSystemTaskNotificationListenerAdapter adapter = new ExternalSystemTaskNotificationListenerAdapter() {
    @Override
    public void onStatusChange(@Nonnull ExternalSystemTaskNotificationEvent event) {
      indicator.setText(wrapProgressText(event.getDescription()));
    }
  };
  final ExternalSystemTaskNotificationListener[] ls;
  if (listeners.length > 0) {
    ls = ArrayUtil.append(listeners, adapter);
  }
  else {
    ls = new ExternalSystemTaskNotificationListener[]{adapter};
  }

  return cancel(ls);
}
 
Example 5
Source Project: markdown-image-kit   File: MikTaskBase.java    License: MIT License 5 votes vote down vote up
@Override
public void run(@NotNull ProgressIndicator indicator) {
    indicator.pushState();
    indicator.setIndeterminate(false);
    try {
        indicator.setFraction(0.0);
        manager.invoke(indicator);
    } finally {
        indicator.setFraction(1.0);
        indicator.popState();
    }
}
 
Example 6
private static void collectAndShowDuplicates(final Project project) {
  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null && !indicator.isCanceled()) {
    indicator.setText("Collecting project images...");
    indicator.setIndeterminate(false);
    final List<VirtualFile> images = new ArrayList<VirtualFile>();
    for (String ext : IMAGE_EXTENSIONS) {
      images.addAll(FilenameIndex.getAllFilesByExt(project, ext));
    }

    final Map<Long, Set<VirtualFile>> duplicates = new HashMap<Long, Set<VirtualFile>>();
    final Map<Long, VirtualFile> all = new HashMap<Long, VirtualFile>();
    for (int i = 0; i < images.size(); i++) {
      indicator.setFraction((double)(i + 1) / (double)images.size());
      final VirtualFile file = images.get(i);
      if (!(file.getFileSystem() instanceof LocalFileSystem)) continue;
      final long length = file.getLength();
      if (all.containsKey(length)) {
        if (!duplicates.containsKey(length)) {
          final HashSet<VirtualFile> files = new HashSet<VirtualFile>();
          files.add(all.get(length));
          duplicates.put(length, files);
        }
        duplicates.get(length).add(file);
      } else {
        all.put(length, file);
      }
      indicator.checkCanceled();
    }
    showResults(project, images, duplicates, all);
  }
}
 
Example 7
Source Project: consulo   File: VcsLogData.java    License: Apache License 2.0 5 votes vote down vote up
private void runInBackground(@Nonnull ThrowableConsumer<ProgressIndicator, VcsException> task) {
  Task.Backgroundable backgroundable = new Task.Backgroundable(myProject, "Loading History...", false) {
    @Override
    public void run(@Nonnull ProgressIndicator indicator) {
      indicator.setIndeterminate(true);
      try {
        task.consume(indicator);
      }
      catch (VcsException e) {
        throw new RuntimeException(e); // TODO
      }
    }
  };
  myDataLoaderQueue.run(backgroundable, null, myRefresher.getProgress().createProgressIndicator());
}
 
Example 8
Source Project: intellij   File: PrefetchIndexingTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void performInDumbMode(ProgressIndicator indicator) {
  indicator.setIndeterminate(true);
  indicator.setText("Prefetching files...");
  while (!future.isCancelled() && !future.isDone()) {
    indicator.checkCanceled();
    TimeoutUtil.sleep(50);
  }
  long end = System.currentTimeMillis();
  logger.info(String.format("%s took: %d ms", taskName, (end - startTimeMillis)));
}
 
Example 9
Source Project: GitToolBox   File: BlameCacheExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void executeWithProgress(ExecutableTask executable) {
  Task.Backgroundable task = new Task.Backgroundable(project, executable.getTitle()) {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      indicator.setIndeterminate(true);
      executable.run();
    }
  };
  task.queue();
}
 
Example 10
@Override
public boolean executeTask(@NotNull ProgressIndicator progressIndicator) {

    progressIndicator.setIndeterminate(true);
    progressIndicator.setText(ResourceBundle.getBundle("Bundle").getString("AsposeManager.projectMessage"));
    AsposeMavenProjectManager comManager = AsposeMavenProjectManager.getInstance();

    return comManager.retrieveAsposeMavenDependencies(progressIndicator);
}
 
Example 11
Source Project: consulo   File: Waiter.java    License: Apache License 2.0 5 votes vote down vote up
public void run(@Nonnull ProgressIndicator indicator) {
  indicator.setIndeterminate(true);
  indicator.setText2(VcsBundle.message("commit.wait.util.synched.text"));

  if (!myStarted.compareAndSet(false, true)) {
    LOG.error("Waiter running under progress being started again.");
  }
  else {
    while (!mySemaphore.waitFor(500)) {
      indicator.checkCanceled();
    }
  }
}
 
Example 12
public void doRun(@Nonnull ProgressIndicator indicator) throws InvocationTargetException, InterruptedException {
  final SequentialTask task = myTask;
  if (task == null) {
    return;
  }
  
  myIndicator = indicator;
  indicator.setIndeterminate(false);
  prepare(task);
  
  // We need to sync background thread and EDT here in order to avoid situation when event queue is full of processing requests.
  while (!task.isDone()) {
    if (indicator.isCanceled()) {
      task.stop();
      break;
    }
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        try {
          while (!task.isDone() && System.currentTimeMillis() - start < myMinIterationTime) {
            task.iteration();
          }
        }
        catch (RuntimeException e) {
          task.stop();
          throw e;
        }
      }
    });
    //if (ApplicationManager.getApplication().isDispatchThread()) {
    //  runnable.run();
    //}
    //else {
    //  ApplicationManagerEx.getApplicationEx().suspendReadAccessAndRunWriteAction(runnable);
    //}
  }
}
 
Example 13
@Override
public void run(@NotNull ProgressIndicator indicator) {
    indicator.setIndeterminate(true);
    myCallback.consume(AnonymousFeedback.sendFeedback(errorReportInformation));
}
 
Example 14
@Nullable
public static DumbModeTask createChangedFilesIndexingTask(final Project project) {
  final FileBasedIndex i = FileBasedIndex.getInstance();
  if (!(i instanceof FileBasedIndexImpl) || !IndexInfrastructure.hasIndices()) {
    return null;
  }

  FileBasedIndexImpl index = (FileBasedIndexImpl)i;

  if (!mightHaveManyChangedFilesInProject(project, index)) {
    return null;
  }

  return new DumbModeTask(project.getComponent(FileBasedIndexProjectHandler.class)) {
    @Override
    public void performInDumbMode(@Nonnull ProgressIndicator indicator) {
      long start = System.currentTimeMillis();
      Collection<VirtualFile> files = index.getFilesToUpdate(project);
      long calcDuration = System.currentTimeMillis() - start;

      indicator.setIndeterminate(false);
      indicator.setText(IdeBundle.message("progress.indexing.updating"));

      LOG.info("Reindexing refreshed files: " + files.size() + " to update, calculated in " + calcDuration + "ms");
      if (!files.isEmpty()) {
        PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
        reindexRefreshedFiles(indicator, files, project, index);
        snapshot.logResponsivenessSinceCreation("Reindexing refreshed files");
      }
    }

    @Override
    public String toString() {
      StringBuilder sampleOfChangedFilePathsToBeIndexed = new StringBuilder();

      index.processChangedFiles(project, new Processor<VirtualFile>() {
        int filesInProjectToBeIndexed;
        final String projectBasePath = project.getBasePath();

        @Override
        public boolean process(VirtualFile file) {
          if (filesInProjectToBeIndexed != 0) sampleOfChangedFilePathsToBeIndexed.append(", ");

          String filePath = file.getPath();
          String loggedPath = projectBasePath != null ? FileUtil.getRelativePath(projectBasePath, filePath, '/') : null;
          if (loggedPath == null) loggedPath = filePath;
          else loggedPath = "%project_path%/" + loggedPath;
          sampleOfChangedFilePathsToBeIndexed.append(loggedPath);

          return ++filesInProjectToBeIndexed < ourMinFilesToStartDumMode;
        }
      });
      return super.toString() + " [" + project + ", " + sampleOfChangedFilePathsToBeIndexed + "]";
    }
  };
}
 
Example 15
@Override
public void run(@NotNull ProgressIndicator indicator) {
    if (myProject.isDisposed()) {
        LOG.debug("Project is disposed, can't download rincewind");
        return;
    }

    InsightManagerImpl insightManager = (InsightManagerImpl) ServiceManager.getService(myProject, InsightManager.class);
    if (!insightManager.isDownloading.compareAndSet(false, true)) {
        // We are already in the process of downloading
        LOG.debug("Already downloading, abort");
        return;
    }

    try {
        File targetFile = insightManager.getRincewindFile(m_sourceFile);
        if (targetFile == null) {
            LOG.debug("No target file, abort downloading");
            return;
        }

        String rincewindFilename = insightManager.getRincewindFilename(m_sourceFile);
        if (rincewindFilename == null) {
            LOG.debug("No rincewind version found, abort downloading");
            return;
        }

        LOG.info("Downloading " + targetFile.getName() + "...");
        indicator.setIndeterminate(false);
        indicator.setFraction(0.0);

        boolean downloaded = WGet.apply(DOWNLOAD_URL + rincewindFilename, targetFile, indicator, TOTAL_BYTES);
        if (downloaded) {
            Application application = ApplicationManager.getApplication();
            application.executeOnPooledThread(() -> {
                DumbService dumbService = DumbService.getInstance(myProject);
                dumbService.runReadActionInSmartMode(() -> {
                    LOG.info("Rincewind downloaded, query types for opened files");
                    PsiManager psiManager = PsiManager.getInstance(myProject);
                    VirtualFile[] openedFiles = FileEditorManager.getInstance(myProject).getOpenFiles();
                    for (VirtualFile openedFile : openedFiles) {
                        // Query types and update psi cache
                        PsiFile cmtFile = ORFileManager.findCmtFileFromSource(myProject, openedFile.getNameWithoutExtension());
                        if (cmtFile != null) {
                            Path cmtPath = FileSystems.getDefault().getPath(cmtFile.getVirtualFile().getPath());

                            application.invokeLater(() -> application.runReadAction(() -> {
                                PsiFile psiFile = psiManager.findFile(openedFile);
                                if (psiFile instanceof FileBase) {
                                    LOG.debug("Query types for " + openedFile);
                                    insightManager.queryTypes(openedFile, cmtPath, inferredTypes -> InferredTypesService
                                            .annotatePsiFile(myProject, psiFile.getLanguage(), openedFile, inferredTypes));
                                }
                            }));
                        }
                    }
                });
            });
        }

        indicator.setFraction(1.0);
    } finally {
        insightManager.isDownloading.set(false);
    }
}
 
Example 16
Source Project: azure-devops-intellij   File: TFSProgressUtil.java    License: MIT License 4 votes vote down vote up
public static void setIndeterminate(final @Nullable ProgressIndicator progressIndicator, final boolean indeterminate) {
    if (progressIndicator != null) {
        progressIndicator.setIndeterminate(indeterminate);
    }
}
 
Example 17
private void execute(final Project project, final VCSBuilder vcsBuilder, VirtualFile[] vFiles) throws Exception {
    vcsBuilder.build(project, vFiles);
    final String diff = vcsBuilder.getDiff();
    if (diff == null) {
        Messages.showMessageDialog(project, "No diff generated", "Warn", null);
        return;
    }

    final ReviewBoardClient reviewBoardClient = new ReviewBoardClient();
    Task.Backgroundable task = new Task.Backgroundable(project, "Query Repository...", false, new PerformInBackgroundOption() {
        @Override
        public boolean shouldStartInBackground() {
            return false;
        }

        @Override
        public void processSentToBackground() {
        }
    }) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(true);
            Repository[] repositories;
            try {
                repositories = reviewBoardClient.getRepositories().repositories;
            } catch (Exception e) {
                PopupUtil.showBalloonForActiveFrame("Error to list repository:" + e.getMessage(), MessageType.ERROR);
                throw new RuntimeException(e);
            }
            if (repositories != null) {
                final Repository[] finalRepositories = repositories;
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        showPostForm(project, vcsBuilder, finalRepositories);
                    }
                });

            }
        }
    };
    ProgressManager.getInstance().run(task);
}
 
Example 18
@Override
public void run(@NotNull ProgressIndicator indicator) {
  indicator.setText("Connecting...");
  indicator.setFraction(0);
  indicator.setIndeterminate(true);

  final CrucibleTestConnector connector = new CrucibleTestConnector(myProject);
  connector.run();

  while (connector.getConnectionState() == CrucibleTestConnector.ConnectionState.NOT_FINISHED) {
    try {
      if (indicator.isCanceled()) {
        connector.setInterrupted();
        break;
      }
      else {
        Thread.sleep(CHECK_CANCEL_INTERVAL);
      }
    }
    catch (InterruptedException e) {
      LOG.info(e.getMessage());
    }
  }

  CrucibleTestConnector.ConnectionState state = connector.getConnectionState();
  switch (state) {
    case FAILED:
      EventQueue.invokeLater(new Runnable() {
        public void run() {
          Messages.showDialog(myProject, "Reason:  " + connector.getErrorMessage(), "Connection Failed", new String[]{"Ok"}, 0, null);
        }
      });
      break;
    case INTERRUPTED:
      LOG.debug("'Test Connection' canceled");
      break;
    case SUCCEEDED:
      EventQueue.invokeLater(new Runnable() {
        public void run() {
          Messages.showDialog(myProject, "Connected successfully", "Connection OK", new String[]{"Ok"}, 0, null);
        }
      });
      break;
    default: //NOT_FINISHED:
      LOG.warn("Unexpected 'Test Connection' state: "
               + connector.getConnectionState().toString());
  }
}
 
Example 19
Source Project: consulo   File: CompilerTask.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void run(@Nonnull final ProgressIndicator indicator) {
  myIndicator = indicator;

  indicator.setIndeterminate(false);

  final Semaphore semaphore = ((CompilerManagerImpl)CompilerManager.getInstance(myProject)).getCompilationSemaphore();
  boolean acquired = false;
  try {

    try {
      while (!acquired) {
        acquired = semaphore.tryAcquire(300, TimeUnit.MILLISECONDS);
        if (!acquired && !myWaitForPreviousSession) {
          return;
        }
        if (indicator.isCanceled()) {
          // give up obtaining the semaphore,
          // let compile work begin in order to stop gracefuly on cancel event
          break;
        }
      }
    }
    catch (InterruptedException ignored) {
    }

    if (!isHeadless()) {
      addIndicatorDelegate();
    }
    myCompileWork.run();
  }
  finally {
    try {
      indicator.stop();
    }
    finally {
      if (acquired) {
        semaphore.release();
      }
    }
  }
}
 
Example 20
Source Project: consulo   File: UnindexedFilesUpdater.java    License: Apache License 2.0 2 votes vote down vote up
private void updateUnindexedFiles(ProgressIndicator indicator) {
  if (!IndexInfrastructure.hasIndices()) return;

  PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
  myPusher.pushAllPropertiesNow();
  boolean trackResponsiveness = !ApplicationManager.getApplication().isUnitTestMode();

  if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Pushing properties");

  indicator.setIndeterminate(true);
  indicator.setText(IdeBundle.message("progress.indexing.scanning"));

  myIndex.clearIndicesIfNecessary();

  CollectingContentIterator finder = myIndex.createContentIterator();
  snapshot = PerformanceWatcher.takeSnapshot();

  myIndex.iterateIndexableFilesConcurrently(finder, myProject, indicator);

  if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Indexable file iteration");

  List<VirtualFile> files = finder.getFiles();

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    // full VFS refresh makes sense only after it's loaded, i.e. after scanning files to index is finished
    scheduleInitialVfsRefresh();
  }

  if (files.isEmpty()) {
    return;
  }

  snapshot = PerformanceWatcher.takeSnapshot();

  if (trackResponsiveness) LOG.info("Unindexed files update started: " + files.size() + " files to update");

  indicator.setIndeterminate(false);
  indicator.setText(IdeBundle.message("progress.indexing.updating"));

  indexFiles(indicator, files);

  if (trackResponsiveness) snapshot.logResponsivenessSinceCreation("Unindexed files update");
}