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

The following are Jave code examples for showing how to use setFraction() 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: logviewer   File: LogView.java   Source Code and License Vote up 6 votes
/**
 * Filters the console
 */
private synchronized void doFilter(ProgressIndicator progressIndicator) {
    final ConsoleView console = getConsole();
    String allLInes = getOriginalDocument().toString();
    final String[] lines = allLInes.split("\n");
    if (console != null) {
        console.clear();
    }
    myLogFilterModel.processingStarted();
    int size = lines.length;
    float current = 0;
    for (String line : lines) {
        printMessageToConsole(line);
        current++;
        progressIndicator.setFraction(current / size);
    }
    if (console != null) {
        ((ConsoleViewImpl) console).requestScrollingToEnd();
    }
}
 
Example 2
Project: NetSuite-Tools-For-WebStorm   File: CompareWithFileCabinetTask.java   Source Code and License Vote up 6 votes
private ArrayList<File> downloadFiles(ArrayList<String> fileIds, ProgressIndicator progressIndicator) {
    ArrayList<File> files = new ArrayList<File>();
    progressIndicator.setText("Downloading selected file(s) from NetSuite File Cabinet");

    double numberOfFilesToDownload = fileIds.size();
    double currentFileNumber = 1;

    for (String fileId : fileIds) {
        progressIndicator.setFraction(currentFileNumber/numberOfFilesToDownload);
        progressIndicator.setText("Downloading selected file(s) from NetSuite File Cabinet: " + decimalFormat.format((currentFileNumber/numberOfFilesToDownload) * 100) + "% Complete");
        try {
            File downloadedFile = nsClient.downloadFile(fileId);

            if (downloadedFile != null) {
                files.add(nsClient.downloadFile(fileId));
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Exception downloading file from NetSuite File Cabinet: " + ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }
        currentFileNumber++;
    }

    progressIndicator.setFraction(1);
    return files;
}
 
Example 3
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 4
Project: intellij-ce-playground   File: PerformFixesModalTask.java   Source Code and License Vote up 6 votes
@Override
public boolean iteration() {
  final CommonProblemDescriptor descriptor = myDescriptors[myCount++];
  ProgressIndicator indicator = myTask.getIndicator();
  if (indicator != null) {
    indicator.setFraction((double)myCount / myDescriptors.length);
    String presentableText = "usages";
    if (descriptor instanceof ProblemDescriptor) {
      final PsiElement psiElement = ((ProblemDescriptor)descriptor).getPsiElement();
      if (psiElement != null) {
        presentableText = SymbolPresentationUtil.getSymbolPresentableText(psiElement);
      }
    }
    indicator.setText("Processing " + presentableText);
  }
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      myDocumentManager.commitAllDocuments();
      applyFix(myProject, descriptor);
    }
  });
  return isDone();
}
 
Example 5
Project: intellij-ce-playground   File: CodeStyleSettingsCodeFragmentFilter.java   Source Code and License Vote up 6 votes
@Override
public boolean iteration() {
  popUntilCurrentTaskUnfinishedOrNull();

  if (myCurrentTask != null) {
    ProgressIndicator indicator = myProgressTask.getIndicator();
    if (indicator != null) {
      if (myProgressText != null) indicator.setText(myProgressText);
      if (myProgressText2 != null) indicator.setText2(myProgressText2);
      indicator.setFraction((double)myIterationsFinished++ / myTotalIterations);
    }
    myCurrentTask.iteration();
  }

  return true;
}
 
Example 6
Project: intellij-ce-playground   File: InstallComponentsPath.java   Source Code and License Vote up 6 votes
@NotNull
@Override
protected File perform(@NotNull ProgressIndicator indicator, @NotNull File file) throws WizardException {
  indicator.setText("Moving downloaded SDK");
  indicator.start();
  try {
    File root = getSdkRoot(file);
    if (!root.renameTo(myDestination)) {
      FileUtil.copyDir(root, myDestination);
      FileUtil.delete(root); // Failure to delete it is not critical, the source is in temp folder.
      // No need to abort installation.
    }
    return myDestination;
  }
  catch (IOException e) {
    throw new WizardException("Unable to move Android SDK", e);
  }
  finally {
    indicator.setFraction(1.0);
    indicator.stop();
  }
}
 
Example 7
Project: intellij-ce-playground   File: UpdateCopyrightAction.java   Source Code and License Vote up 5 votes
@Override
public boolean iteration() {
  final ProgressIndicator indicator = myProgressTask.getIndicator();
  if (indicator != null) {
    indicator.setFraction((double) myIdx/mySize);
  }
  myRunnables.next().run();
  myIdx++;
  return true;
}
 
Example 8
Project: intellij-ce-playground   File: AnnotateTask.java   Source Code and License Vote up 5 votes
@Override
public boolean iteration() {
  final ProgressIndicator indicator = myTask.getIndicator();
  if (indicator != null) {
    indicator.setFraction(((double)myCount) / myTotal);
  }

  NullityInferrer.apply(myProject, myNotNullManager, myInfos[myCount++]);

  return isDone();
}
 
Example 9
Project: intellij-ce-playground   File: HgAddCommand.java   Source Code and License Vote up 5 votes
private void execute(@NotNull Collection<VirtualFile> files, @Nullable ProgressIndicator indicator) {
  final Map<VirtualFile, Collection<VirtualFile>> sorted = HgUtil.sortByHgRoots(myProject, files);
  for (Map.Entry<VirtualFile, Collection<VirtualFile>> entry : sorted.entrySet()) {
    if (indicator != null) {
      if (indicator.isCanceled()) { return; }
      indicator.setFraction(0);
      indicator.setText2("Adding files to " + entry.getKey().getPresentableUrl());
    }
    addFiles(entry.getKey(), entry.getValue(), indicator);
  }
}
 
Example 10
Project: intellij-ce-playground   File: EditorsSplitters.java   Source Code and License Vote up 5 votes
private void initializeProgress() {
  ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null) {
    indicator.setText(IdeBundle.message("loading.editors"));
    indicator.setText2("");
    indicator.setIndeterminate(false);
    indicator.setFraction(0);

    myProgressMaximum = countFiles(mySplittersElement);
    myCurrentProgress = 0;
  }
}
 
Example 11
Project: intellij-ce-playground   File: GenerateBinaryStubsFix.java   Source Code and License Vote up 5 votes
private boolean generateSkeletonsForList(@NotNull final PySkeletonRefresher refresher,
                                         ProgressIndicator indicator,
                                         @Nullable final String currentBinaryFilesPath) throws InvalidSdkException {
  final PySkeletonGenerator generator = new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
  indicator.setIndeterminate(false);
  final String homePath = mySdk.getHomePath();
  if (homePath == null) return false;
  GeneralCommandLine cmd = PythonHelper.EXTRA_SYSPATH.newCommandLine(homePath, Lists.newArrayList(myQualifiedName));
  final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd,
                                                             new File(homePath).getParent(),
                                                             PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000
  );
  if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
    final String extraPath = runResult.getStdout();
    final PySkeletonGenerator.ListBinariesResult binaries = generator.listBinaries(mySdk, extraPath);
    final List<String> names = Lists.newArrayList(binaries.modules.keySet());
    Collections.sort(names);
    final int size = names.size();
    for (int i = 0; i != size; ++i) {
      final String name = names.get(i);
      indicator.setFraction((double)i / size);
      if (needBinaryList(name)) {
        indicator.setText2(name);
        final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
        final String modulePath = item != null ? item.getPath() : "";
        //noinspection unchecked
        refresher.generateSkeleton(name, modulePath, new ArrayList<String>(), Consumer.EMPTY_CONSUMER);
      }
    }
  }
  return true;
}
 
Example 12
Project: intellij-ce-playground   File: ShowImageDuplicatesAction.java   Source Code and License Vote up 5 votes
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 13
Project: intellij-ce-playground   File: FindDependencyUtil.java   Source Code and License Vote up 5 votes
private static int updateIndicator(final ProgressIndicator indicator, final int totalCount, int count, final PsiFile psiFile) {
  if (indicator != null) {
    if (indicator.isCanceled()) throw new ProcessCanceledException();
    indicator.setFraction(((double)++count) / totalCount);
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile != null) {
      indicator.setText(AnalysisScopeBundle.message("find.dependencies.progress.text", virtualFile.getPresentableUrl()));
    }
  }
  return count;
}
 
Example 14
Project: intellij-ce-playground   File: FileTreeModelBuilder.java   Source Code and License Vote up 5 votes
private static void update(ProgressIndicator indicator, boolean indeterminate, double fraction) {
  if (indicator instanceof PanelProgressIndicator) {
    ((PanelProgressIndicator)indicator).update(SCANNING_PACKAGES_MESSAGE, indeterminate, fraction);
  } else {
    if (fraction != -1) {
      indicator.setFraction(fraction);
    }
  }
}
 
Example 15
Project: educational-plugin   File: CCStepicConnector.java   Source Code and License Vote up 4 votes
private static void postCourse(final Project project, @NotNull Course course) {
  if (!checkIfAuthorized(project, "post course")) return;

  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null) {
    indicator.setText("Uploading course to " + EduStepicNames.STEPIC_URL);
    indicator.setIndeterminate(false);
  }
  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + "/courses");

  final StepicUser currentUser = EduStepicAuthorizedClient.getCurrentUser();
  if (currentUser != null) {
    final List<StepicUser> courseAuthors = course.getAuthors();
    for (int i = 0; i < courseAuthors.size(); i++) {
      if (courseAuthors.size() > i) {
        final StepicUser courseAuthor = courseAuthors.get(i);
        currentUser.setFirstName(courseAuthor.getFirstName());
        currentUser.setLastName(courseAuthor.getLastName());
      }
    }
    course.setAuthors(Collections.singletonList(currentUser));
  }

  String requestBody = new Gson().toJson(new StepicWrappers.CourseWrapper(course));
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

  try {
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
    if (client == null) {
      LOG.warn("Http client is null");
      return;
    }
    final CloseableHttpResponse response = client.execute(request);
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    final StatusLine line = response.getStatusLine();
    EntityUtils.consume(responseEntity);
    if (line.getStatusCode() != HttpStatus.SC_CREATED) {
      final String message = FAILED_TITLE + "course ";
      LOG.error(message + responseString);
      showErrorNotification(project, FAILED_TITLE, responseString);
      return;
    }
    final RemoteCourse postedCourse = new Gson().fromJson(responseString, StepicWrappers.CoursesContainer.class).courses.get(0);
    postedCourse.setLessons(course.getLessons(true));
    postedCourse.setAuthors(course.getAuthors());
    postedCourse.setCourseMode(CCUtils.COURSE_MODE);
    postedCourse.setLanguage(course.getLanguageID());
    final int sectionId = postModule(postedCourse.getId(), 1, String.valueOf(postedCourse.getName()), project);
    int position = 1;
    for (Lesson lesson : course.getLessons()) {
      if (indicator != null) {
        indicator.checkCanceled();
        indicator.setText2("Publishing lesson " + lesson.getIndex());
      }
      final int lessonId = postLesson(project, lesson);
      postUnit(lessonId, position, sectionId, project);
      if (indicator != null) {
        indicator.setFraction((double)lesson.getIndex()/course.getLessons().size());
        indicator.checkCanceled();
      }
      position += 1;
    }
    ApplicationManager.getApplication().runReadAction(() -> postAdditionalFiles(course, project, postedCourse.getId()));
    StudyTaskManager.getInstance(project).setCourse(postedCourse);
    showNotification(project, "Course published");
  }
  catch (IOException e) {
    LOG.error(e.getMessage());
  }
}
 
Example 16
Project: ApkMultiChannelPlugin   File: BuildHelper.java   Source Code and License Vote up 4 votes
private static void writeApkComment(ProgressIndicator progressIndicator, Options options,
                                    File apkFile, String outPath, String tempPath,
                                    String apkNameWithoutExtension) {
    try {
        if (ZipHelper.hasCommentSign(apkFile)) {
            String comment = ZipHelper.readZipComment(apkFile);
            NotificationHelper.error("the apk comment already exists, the comment is " + comment);
            return;
        }

        if (ApkHelper.isV2Signature(apkFile)) {
            log.info("the apk is v2 signature");
            String tempApkPath = createNotSignApk(apkFile, tempPath, apkNameWithoutExtension);

            //apkSigner is not support write zip comment
            options.signer = "jarsigner";
            CommandHelper.execSigner(options, tempApkPath);
            String zipalignApkPath = tempPath + File.separator + apkNameWithoutExtension + ".apk";
            CommandHelper.execZipalign(options, tempApkPath, zipalignApkPath);

            apkFile = new File(zipalignApkPath);
        }

        for (int i = 0, count = options.channels.size(); i < count; i++) {
            String channel = options.channels.get(i);
            progressIndicator.setText("Creating " + channel + " apk");
            progressIndicator.setText2(i + 1 + "/" + count);

            String newApkPath = outPath + File.separator + apkNameWithoutExtension + "-" + channel + ".apk";
            File newApkFile = new File(newApkPath);
            FileUtil.createIfDoesntExist(newApkFile);

            FileUtil.copy(apkFile, newApkFile);
            ZipHelper.writeComment(newApkFile, channel);
        }
    } catch (IOException | ApkFormatException | NoSuchAlgorithmException e) {
        e.printStackTrace();
        progressIndicator.setText("Build failed");
    } finally {
        ZipHelper.deleteTemp(tempPath);
    }

    progressIndicator.setFraction(1);
}
 
Example 17
Project: NetSuite-Tools-For-WebStorm   File: UploadTask.java   Source Code and License Vote up 4 votes
private void uploadFiles(VirtualFile[] fileChildren, ProgressIndicator progessIndicator) {
    VirtualFile[] files = this.files;

    if (fileChildren != null) {
        files = fileChildren;
    }

    if (files == null || files.length == 0) {
        return;
    }

    String projectRootDirectory = projectHelper.getProjectRootDirectory(project);

    /*
     * If uploading a directory of files, then recursively call uploadFiles with the children
     * files of the directory to upload them. Otherwise, for each file, attempt to get the NetSuite
     * parent folder ID of the file being uploaded (folders are created if they do not exist)
     * and upload the file into its parent directory.
     */
    for (VirtualFile file : files) {
        if (file.isDirectory()) {
            uploadFiles(file.getChildren(), progessIndicator);
        } else {
            saveDocument(file);
            String fileNetSuiteParentFolderId = getFileNetSuiteParentFolderId(file, projectRootDirectory);

            if (fileNetSuiteParentFolderId != null)
            {
                progessIndicator.setFraction(0);
                progessIndicator.setText("Uploading File: " + file.getName());
                try {
                    WriteResponse response = nsClient.uploadFile(file.getName(), file.getPath(), nsClient.searchFile(file.getName(), fileNetSuiteParentFolderId, projectSettingsController.getNsRootFolder()), fileNetSuiteParentFolderId, "");
                    if (!response.getStatus().isIsSuccess()) {
                        displayUploadResultBalloonMessage(file.getName(), false);
                        JOptionPane.showMessageDialog(null, "File: " + file.getName() + "\n" +
                                        "NetSuite File Cabinet Parent Folder ID: " + fileNetSuiteParentFolderId + "\n" +
                                        "Error Details: " + response.getStatus().getStatusDetail(response.getStatus().getStatusDetail().length - 1).getMessage(),
                                "FILE UPLOAD ERROR",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        progessIndicator.setFraction(1);
                        displayUploadResultBalloonMessage(file.getName(), true);
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "Error uploading file", "ERROR", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
}
 
Example 18
Project: ideaMantis   File: IdeaMantisIssues.java   Source Code and License Vote up 4 votes
private void loadList(DefaultTableModel tblIssueModel, ProgressManager manager) {
    pnlMain.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    Task task =
            new Task.Backgroundable(Helper.getProject(), "Load Issues...", true) {
                @Override
                public void run(@NotNull ProgressIndicator progressIndicator) {
                    try {
                        controlPagination();
                        if(!settings.validateSettings()) {
                            Helper.printNotification("Wrong settings!", "The connection-settings are incorrect!", NotificationType.WARNING);
                            state = false;
                            tblIssues.removeAll();
                            for (int i = tblIssueModel.getRowCount() - 1; i >= 0; i--) {
                                tblIssueModel.removeRow(i);
                            }
                        } else {

                            state = true;
                            tblIssues.removeAll();
                            for (int i = tblIssueModel.getRowCount() - 1; i >= 0; i--) {
                                tblIssueModel.removeRow(i);
                            }
                            tblIssues.setModel(tblIssueModel);
                            String filterID = "";
                            if(cmbFilters.getSelectedItem()!=null) {
                                if(!cmbFilters.getSelectedItem().toString().equals("")) {
                                    filterID = cmbFilters.getSelectedItem().toString().split(":")[0].trim();
                                }
                            }
                            List<MantisIssue> mantisIssues = new MantisSoapAPI(settings).getIssues(settings.getProjectID(), page, filterID);
                            progressIndicator.setFraction(0.0);
                            double factor = 100.0 / mantisIssues.size();
                            for(MantisIssue issue : mantisIssues) {
                                tblIssueModel.addRow(new Object[]{issue.getId(), issue.getSummary(), issue.getStatus()});
                                progressIndicator.setFraction(progressIndicator.getFraction() + factor);
                            }
                            tblIssues.setModel(tblIssueModel);
                            cmdIssueNew.setEnabled(true);
                        }
                    } catch (Exception ex) {
                        Helper.printException(ex);
                    } finally {
                        pnlMain.setCursor(Cursor.getDefaultCursor());
                    }
                }
            };
    manager.run(task);
}
 
Example 19
Project: intellij-ce-playground   File: ModuleManagerImpl.java   Source Code and License Vote up 4 votes
protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
  if (myModulePaths == null || myModulePaths.isEmpty()) {
    return;
  }
  ModuleGroupInterner groupInterner = new ModuleGroupInterner();

  final ProgressIndicator progressIndicator = myProject.isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator();
  if (progressIndicator != null) {
    progressIndicator.setText("Loading modules...");
    progressIndicator.setText2("");
  }
  myFailedModulePaths.clear();
  myFailedModulePaths.addAll(myModulePaths);
  final List<Module> modulesWithUnknownTypes = new ArrayList<Module>();
  List<ModuleLoadingErrorDescription> errors = new ArrayList<ModuleLoadingErrorDescription>();

  for (int i = 0; i < myModulePaths.size(); i++) {
    ModulePath modulePath = myModulePaths.get(i);
    if (progressIndicator != null) {
      progressIndicator.setFraction((double) i / myModulePaths.size());
    }
    try {
      final Module module = moduleModel.loadModuleInternal(modulePath.getPath());
      if (isUnknownModuleType(module)) {
        modulesWithUnknownTypes.add(module);
      }
      final String groupPathString = modulePath.getModuleGroup();
      if (groupPathString != null) {
        final String[] groupPath = groupPathString.split(MODULE_GROUP_SEPARATOR);

        groupInterner.setModuleGroupPath(moduleModel, module, groupPath); //model should be updated too
      }
      myFailedModulePaths.remove(modulePath);
    }
    catch (IOException e) {
      errors.add(ModuleLoadingErrorDescription.create(ProjectBundle.message("module.cannot.load.error", modulePath.getPath(), e.getMessage()),
                                                   modulePath, this));
    }
    catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) {
      errors.add(ModuleLoadingErrorDescription.create(moduleWithNameAlreadyExists.getMessage(), modulePath, this));
    }
  }

  onModuleLoadErrors(errors);

  showUnknownModuleTypeNotification(modulesWithUnknownTypes);

  if (progressIndicator != null) {
    progressIndicator.setIndeterminate(true);
  }
}
 
Example 20
Project: intellij-ce-playground   File: MavenRunner.java   Source Code and License Vote up 4 votes
public boolean runBatch(List<MavenRunnerParameters> commands,
                        @Nullable MavenGeneralSettings coreSettings,
                        @Nullable MavenRunnerSettings runnerSettings,
                        @Nullable final String action,
                        @Nullable ProgressIndicator indicator) {
  LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed());

  if (commands.isEmpty()) return true;

  MavenConsole console;

  AccessToken accessToken = ReadAction.start();
  try {
    if (myProject.isDisposed()) return false;
    console = createConsole();
  }
  finally {
    accessToken.finish();
  }

  try {
    int count = 0;
    for (MavenRunnerParameters command : commands) {
      if (indicator != null) {
        indicator.setFraction(((double)count++) / commands.size());
      }

      MavenExecutor executor;

      accessToken = ReadAction.start();
      try {
        if (myProject.isDisposed()) break;
        executor = createExecutor(command, coreSettings, runnerSettings, console);
      }
      finally {
        accessToken.finish();
      }

      executor.setAction(action);
      if (!executor.execute(indicator)) {
        updateTargetFolders();
        return false;
      }
    }

    updateTargetFolders();
  }
  finally {
    console.finish();
  }

  return true;
}
 
Example 21
Project: intellij-ce-playground   File: CacheUpdateRunner.java   Source Code and License Vote up 4 votes
public static void processFiles(final ProgressIndicator indicator,
                                boolean processInReadAction,
                                Collection<VirtualFile> files,
                                Project project, Consumer<FileContent> processor) {
  indicator.checkCanceled();
  final FileContentQueue queue = new FileContentQueue();
  final double total = files.size();
  queue.queue(files, indicator);

  Consumer<VirtualFile> progressUpdater = new Consumer<VirtualFile>() {
    // need set here to handle queue.pushbacks after checkCancelled() in order
    // not to count the same file several times
    final Set<VirtualFile> processed = new THashSet<VirtualFile>();
    private boolean fileNameWasShown;

    @Override
    public void consume(VirtualFile virtualFile) {
      indicator.checkCanceled();
      synchronized (processed) {
        boolean added = processed.add(virtualFile);
        indicator.setFraction(processed.size() / total);
        if (!added || (virtualFile.isValid() && virtualFile.getLength() > FILE_SIZE_TO_SHOW_THRESHOLD)) {
          indicator.setText2(virtualFile.getPresentableUrl());
          fileNameWasShown = true;
        } else if (fileNameWasShown) {
          indicator.setText2("");
          fileNameWasShown = false;
        }
      }
    }
  };

  while (!project.isDisposed()) {
    indicator.checkCanceled();
    // todo wait for the user...
    if (processSomeFilesWhileUserIsInactive(queue, progressUpdater, processInReadAction, project, processor)) {
      break;
    }
  }

  if (project.isDisposed()) {
    indicator.cancel();
    indicator.checkCanceled();
  }
}
 
Example 22
Project: intellij-ce-playground   File: ComponentManagerImpl.java   Source Code and License Vote up 4 votes
protected void setProgressDuringInit(@NotNull ProgressIndicator indicator) {
  indicator.setFraction(getPercentageOfComponentsLoaded());
}
 
Example 23
Project: intellij-ce-playground   File: AbstractLayoutCodeProcessor.java   Source Code and License Vote up 4 votes
private void updateIndicatorFraction(int processed) {
  ProgressIndicator indicator = myCompositeTask.getIndicator();
  if (indicator != null) {
    indicator.setFraction((double)processed / myTotalFiles);
  }
}