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

The following are Jave code examples for showing how to use cancel() 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: GeneralHighlightingPass.java   Source Code and License Vote up 6 votes
private static void cancelAndRestartDaemonLater(@NotNull ProgressIndicator progress,
                                                @NotNull final Project project) throws ProcessCanceledException {
  progress.cancel();
  JobScheduler.getScheduler().schedule(new Runnable() {

    @Override
    public void run() {
      Application application = ApplicationManager.getApplication();
      if (!project.isDisposed() && !application.isDisposed() && !application.isUnitTestMode()) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            DaemonCodeAnalyzer.getInstance(project).restart();
          }
        }, project.getDisposed());
      }
    }
  }, RESTART_DAEMON_RANDOM.nextInt(100), TimeUnit.MILLISECONDS);
  throw new ProcessCanceledException();
}
 
Example 2
Project: intellij-ce-playground   File: SliceManager.java   Source Code and License Vote up 6 votes
public void runInterruptibly(@NotNull ProgressIndicator progress,
                             @NotNull Runnable onCancel,
                             @NotNull Runnable runnable) throws ProcessCanceledException {
  Disposable disposable = addPsiListener(progress);
  try {
    progress.checkCanceled();
    ProgressManager.getInstance().executeProcessUnderProgress(runnable, progress);
  }
  catch (ProcessCanceledException e) {
    progress.cancel();
    //reschedule for later
    onCancel.run();
    throw e;
  }
  finally {
    Disposer.dispose(disposable);
  }
}
 
Example 3
Project: StAnalysisRunner   File: AnalysisTask.java   Source Code and License Vote up 5 votes
@Override
public void run(@NotNull final ProgressIndicator progressIndicator) {
    isRunning = true;
    progressIndicator.setIndeterminate(true);

    try {
        runAnalysis(progressIndicator);
    } catch (final ProcessCanceledException canceledException) {
        progressIndicator.cancel();
    } catch (final Exception exception) {
        showErrorNotification("Exception: " + exception.getMessage());
    }
}
 
Example 4
Project: intellij-ce-playground   File: ShowImplementationsAction.java   Source Code and License Vote up 5 votes
private static boolean cancelTask(@Nullable ImplementationsUpdaterTask task) {
  if (task != null) {
    ProgressIndicator indicator = task.myIndicator;
    if (indicator != null) {
      indicator.cancel();
    }
    return task.setCanceled();
  }
  return false;
}
 
Example 5
Project: intellij-ce-playground   File: HierarchyBrowserBase.java   Source Code and License Vote up 5 votes
@Override
public final void actionPerformed(final AnActionEvent e) {
  final HierarchyTreeBuilder builder = getCurrentBuilder();
  final AbstractTreeUi treeUi = builder != null ? builder.getUi() : null;
  final ProgressIndicator progress = treeUi != null ? treeUi.getProgress() : null;
  if (progress != null) {
    progress.cancel();
  }
  myContent.getManager().removeContent(myContent, true);
}
 
Example 6
Project: intellij-ce-playground   File: FirstRunWizardHost.java   Source Code and License Vote up 5 votes
/**
 * Cancels the wizard.
 */
public void cancel() {
  ProgressIndicator indicator = myCurrentProgressIndicator.get();
  if (indicator == null) {
    myWizard.doCancelAction();
  }
  else {
    indicator.cancel();
    JButton button = myActionToButtonMap.get(myCancelAction);
    if (button != null) {
      button.setEnabled(false);
    }
  }
}
 
Example 7
Project: intellij-ce-playground   File: DialogWrapperHost.java   Source Code and License Vote up 5 votes
@Override
public final void doCancelAction() {
  ProgressIndicator indicator = myCurrentProgressIndicator.get();
  if (indicator != null) {
    indicator.cancel();
  } else {
    myWizard.doCancelAction();
  }
}
 
Example 8
Project: intellij-ce-playground   File: MavenProgressIndicator.java   Source Code and License Vote up 5 votes
public synchronized void setIndicator(ProgressIndicator i) {
  i.setText(myIndicator.getText());
  i.setText2(myIndicator.getText2());
  i.setFraction(myIndicator.getFraction());
  if (i.isCanceled()) i.cancel();
  myIndicator = i;
}
 
Example 9
Project: intellij-ce-playground   File: BackgroundTaskUtil.java   Source Code and License Vote up 4 votes
@CalledInAwt
@NotNull
public static ProgressIndicator executeOnPooledThread(@NotNull final Consumer<ProgressIndicator> task, @NotNull Disposable parent) {
  final ModalityState modalityState = ModalityState.current();
  final ProgressIndicator indicator = new EmptyProgressIndicator() {
    @NotNull
    @Override
    public ModalityState getModalityState() {
      return modalityState;
    }
  };
  indicator.start();

  final Disposable disposable = new Disposable() {
    @Override
    public void dispose() {
      if (indicator.isRunning()) indicator.cancel();
    }
  };
  Disposer.register(parent, disposable);

  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
        @Override
        public void run() {
          try {
            task.consume(indicator);
          }
          finally {
            indicator.stop();
            Disposer.dispose(disposable);
          }
        }
      }, indicator);
    }
  });

  return indicator;
}
 
Example 10
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 11
Project: intellij-ce-playground   File: SlicePanel.java   Source Code and License Vote up 4 votes
protected void close() {
  final ProgressIndicator progress = myBuilder.getUi().getProgress();
  if (progress != null) {
    progress.cancel();
  }
}
 
Example 12
Project: intellij-ce-playground   File: CommitablePanelUserActivityListener.java   Source Code and License Vote up 4 votes
private static void cancel() {
  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null) {
    indicator.cancel();
  }
}