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

The following are Jave code examples for showing how to use popState() of the com.intellij.openapi.progress.ProgressIndicator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: intellij-ce-playground   File: ProjectImpl.java   Source Code and License Vote up 6 votes
@Override
public void init() {
  long start = System.currentTimeMillis();

  final ProgressIndicator progressIndicator = isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator();
  if (progressIndicator != null) {
    progressIndicator.pushState();
  }
  super.init(progressIndicator);
  if (progressIndicator != null) {
    progressIndicator.popState();
  }

  long time = System.currentTimeMillis() - start;
  LOG.info(getComponentConfigCount() + " project components initialized in " + time + " ms");

  getMessageBus().syncPublisher(ProjectLifecycleListener.TOPIC).projectComponentsInitialized(this);

  //noinspection SynchronizeOnThis
  synchronized (this) {
    myProjectManagerListener = new MyProjectManagerListener();
    myProjectManager.addProjectManagerListener(this, myProjectManagerListener);
  }
}
 
Example 2
Project: intellij-ce-playground   File: JarHandler.java   Source Code and License Vote up 6 votes
@NotNull
private File copyToMirror(@NotNull File original, @NotNull File mirror) {
  ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
  if (progress != null) {
    progress.pushState();
    progress.setText(VfsBundle.message("jar.copy.progress", original.getPath()));
    progress.setFraction(0);
  }

  try {
    FileUtil.copy(original, mirror);
  }
  catch (final IOException e) {
    reportIOErrorWithJars(original, mirror, e);
    return original;
  }

  if (progress != null) {
    progress.popState();
  }

  return mirror;
}
 
Example 3
Project: epigraph   File: SchemaTypeParentsSearcher.java   Source Code and License Vote up 6 votes
@Override
public void processQuery(@NotNull SchemaTypeParentsSearch.SearchParameters parameters, @NotNull Processor<SchemaTypeDef> consumer) {
  SchemaTypeDef baseType = parameters.schemaTypeDef;

  ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator();
  if (progress != null) {
    progress.pushState();

    String typeName = ApplicationManager.getApplication().runReadAction((Computable<String>) baseType::getName);
    progress.setText(typeName == null ?
        "Searching for parents" : "Searching for parents of " + typeName
    );
  }

  try {
    processParents(consumer, baseType, parameters);
  } finally {
    if (progress != null) progress.popState();
  }
}
 
Example 4
Project: epigraph   File: SchemaTypeInheritorsSearcher.java   Source Code and License Vote up 6 votes
@Override
public void processQuery(@NotNull SchemaTypeInheritorsSearch.SearchParameters parameters, @NotNull Processor<SchemaTypeDef> consumer) {
  SchemaTypeDef baseType = parameters.schemaTypeDef;

  ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator();
  if (progress != null) {
    progress.pushState();

    String typeName = ApplicationManager.getApplication().runReadAction((Computable<String>) baseType::getName);
    progress.setText(typeName == null ?
        "Searching for inheritors" : "Searching for inheritors of " + typeName
    );
  }

  try {
    processInheritors(consumer, baseType, parameters);
  } finally {
    if (progress != null) progress.popState();
  }
}
 
Example 5
Project: intellij-ce-playground   File: JavaClassInheritorsSearcher.java   Source Code and License Vote up 5 votes
@Override
public void processQuery(@NotNull ClassInheritorsSearch.SearchParameters parameters, @NotNull Processor<PsiClass> consumer) {
  final PsiClass baseClass = parameters.getClassToProcess();
  final SearchScope searchScope = parameters.getScope();

  LOG.assertTrue(searchScope != null);

  ProgressIndicator progress = ProgressIndicatorProvider.getGlobalProgressIndicator();
  if (progress != null) {
    progress.pushState();
    String className = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
      @Override
      public String compute() {
        return baseClass.getName();
      }
    });
    progress.setText(className != null ?
                     PsiBundle.message("psi.search.inheritors.of.class.progress", className) :
                     PsiBundle.message("psi.search.inheritors.progress"));
  }

  processInheritors(consumer, baseClass, searchScope, parameters);

  if (progress != null) {
    progress.popState();
  }
}
 
Example 6
Project: intellij-ce-playground   File: JavaFindUsagesHelper.java   Source Code and License Vote up 5 votes
private static boolean addClassesUsages(@NotNull PsiPackage aPackage,
                                        @NotNull final JavaPackageFindUsagesOptions options,
                                        @NotNull final Processor<UsageInfo> processor) {
  ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
  if (progress != null){
    progress.pushState();
  }

  List<PsiClass> classes = new ArrayList<PsiClass>();
  addClassesInPackage(aPackage, options.isIncludeSubpackages, classes);
  for (final PsiClass aClass : classes) {
    if (progress != null) {
      String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
        @Override
        public String compute() {
          return aClass.getName();
        }
      });
      progress.setText(FindBundle.message("find.searching.for.references.to.class.progress", name));
      progress.checkCanceled();
    }
    boolean success = ReferencesSearch.search(new ReferencesSearch.SearchParameters(aClass, options.searchScope, false, options.fastTrack)).forEach(new ReadActionProcessor<PsiReference>() {
      @Override
      public boolean processInReadAction(final PsiReference psiReference) {
        return addResult(psiReference, options, processor);
      }
    });
    if (!success) return false;
  }

  if (progress != null){
    progress.popState();
  }
  return true;
}
 
Example 7
Project: intellij-ce-playground   File: CompileDriver.java   Source Code and License Vote up 5 votes
private boolean executeCompileTasks(final CompileContext context, final boolean beforeTasks) {
  if (myProject.isDisposed()) {
    return false;
  }
  final CompilerManager manager = CompilerManager.getInstance(myProject);
  final ProgressIndicator progressIndicator = context.getProgressIndicator();
  progressIndicator.pushState();
  try {
    CompileTask[] tasks = beforeTasks ? manager.getBeforeTasks() : manager.getAfterTasks();
    if (tasks.length > 0) {
      progressIndicator.setText(beforeTasks
                                ? CompilerBundle.message("progress.executing.precompile.tasks")
                                : CompilerBundle.message("progress.executing.postcompile.tasks"));
      for (CompileTask task : tasks) {
        if (!task.execute(context)) {
          return false;
        }
      }
    }
  }
  finally {
    progressIndicator.popState();
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
    if (statusBar != null) {
      statusBar.setInfo("");
    }
    if (progressIndicator instanceof CompilerTask) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
          ((CompilerTask)progressIndicator).showCompilerContent();
        }
      });
    }
  }
  return true;
}
 
Example 8
Project: intellij-ce-playground   File: PsiSearchHelperImpl.java   Source Code and License Vote up 4 votes
private boolean processGlobalRequestsOptimized(@NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles,
                                               @NotNull ProgressIndicator progress,
                                               @NotNull final Map<RequestWithProcessor, Processor<PsiElement>> localProcessors) {
  if (singles.isEmpty()) {
    return true;
  }

  if (singles.size() == 1) {
    final Collection<? extends RequestWithProcessor> requests = singles.values();
    if (requests.size() == 1) {
      final RequestWithProcessor theOnly = requests.iterator().next();
      return processSingleRequest(theOnly.request, theOnly.refProcessor);
    }
  }

  progress.pushState();
  progress.setText(PsiBundle.message("psi.scanning.files.progress"));
  boolean result;

  try {
    // intersectionCandidateFiles holds files containing words from all requests in `singles` and words in corresponding container names
    final MultiMap<VirtualFile, RequestWithProcessor> intersectionCandidateFiles = createMultiMap();
    // restCandidateFiles holds files containing words from all requests in `singles` but EXCLUDING words in corresponding container names
    final MultiMap<VirtualFile, RequestWithProcessor> restCandidateFiles = createMultiMap();
    collectFiles(singles, progress, intersectionCandidateFiles, restCandidateFiles);

    if (intersectionCandidateFiles.isEmpty() && restCandidateFiles.isEmpty()) {
      return true;
    }

    final Set<String> allWords = new TreeSet<String>();
    for (RequestWithProcessor singleRequest : localProcessors.keySet()) {
      allWords.add(singleRequest.request.word);
    }
    progress.setText(PsiBundle.message("psi.search.for.word.progress", getPresentableWordsDescription(allWords)));

    if (intersectionCandidateFiles.isEmpty()) {
      result = processCandidates(localProcessors, restCandidateFiles, progress, restCandidateFiles.size(), 0);
    }
    else {
      int totalSize = restCandidateFiles.size() + intersectionCandidateFiles.size();
      result = processCandidates(localProcessors, intersectionCandidateFiles, progress, totalSize, 0);
      if (result) {
        result = processCandidates(localProcessors, restCandidateFiles, progress, totalSize, intersectionCandidateFiles.size());
      }
    }
  }
  finally {
    progress.popState();
  }

  return result;
}