Search in sources :

Example 86 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class RollbackDeletionAction method processFiles.

protected List<VcsException> processFiles(final AbstractVcs vcs, final List<FilePath> files) {
    RollbackEnvironment environment = vcs.getRollbackEnvironment();
    if (environment == null)
        return Collections.emptyList();
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        indicator.setText(vcs.getDisplayName() + ": performing rollback...");
    }
    final List<VcsException> result = new ArrayList<>(0);
    try {
        environment.rollbackMissingFileDeletion(files, result, new RollbackProgressModifier(files.size(), indicator));
    } catch (ProcessCanceledException e) {
    // for files refresh
    }
    LocalFileSystem.getInstance().refreshIoFiles(ChangesUtil.filePathsToFiles(files));
    return result;
}
Also used : RollbackProgressModifier(com.intellij.openapi.vcs.changes.ui.RollbackProgressModifier) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) RollbackEnvironment(com.intellij.openapi.vcs.rollback.RollbackEnvironment) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 87 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class ApplierCompleter method wrapInReadActionAndIndicator.

private void wrapInReadActionAndIndicator(@NotNull final Runnable process) {
    Runnable toRun = runInReadAction ? () -> {
        if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(process)) {
            failedSubTasks.add(this);
            doComplete(throwable);
        }
    } : process;
    ProgressIndicator existing = ProgressManager.getInstance().getProgressIndicator();
    if (existing == progressIndicator) {
        // we are already wrapped in an indicator - most probably because we came here from helper which steals children tasks
        toRun.run();
    } else {
        ProgressManager.getInstance().executeProcessUnderProgress(toRun, progressIndicator);
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 88 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class JobLauncherImpl method invokeConcurrentlyUnderProgress.

@Override
public <T> boolean invokeConcurrentlyUnderProgress(@NotNull final List<T> things, ProgressIndicator progress, boolean runInReadAction, boolean failFastOnAcquireReadAction, @NotNull final Processor<? super T> thingProcessor) throws ProcessCanceledException {
    // supply our own indicator even if we haven't given one - to support cancellation
    // use StandardProgressIndicator by default to avoid assertion in SensitiveProgressWrapper() ctr later
    final ProgressIndicator wrapper = progress == null ? new StandardProgressIndicatorBase() : new SensitiveProgressWrapper(progress);
    Boolean result = processImmediatelyIfTooFew(things, wrapper, runInReadAction, thingProcessor);
    if (result != null)
        return result.booleanValue();
    HeavyProcessLatch.INSTANCE.stopThreadPrioritizing();
    List<ApplierCompleter<T>> failedSubTasks = Collections.synchronizedList(new ArrayList<>());
    ApplierCompleter<T> applier = new ApplierCompleter<>(null, runInReadAction, failFastOnAcquireReadAction, wrapper, things, thingProcessor, 0, things.size(), failedSubTasks, null);
    try {
        ForkJoinPool.commonPool().invoke(applier);
        if (applier.throwable != null)
            throw applier.throwable;
    } catch (ApplierCompleter.ComputationAbortedException e) {
        // one of the processors returned false
        return false;
    } catch (ApplicationUtil.CannotRunReadActionException e) {
        // failFastOnAcquireReadAction==true and one of the processors called runReadAction() during the pending write action
        throw e;
    } catch (ProcessCanceledException e) {
        // then task2 calls checkCancel() and get here
        return false;
    } catch (RuntimeException | Error e) {
        throw e;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    assert applier.isDone();
    return applier.completeTaskWhichFailToAcquireReadAction();
}
Also used : ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) StandardProgressIndicatorBase(com.intellij.openapi.progress.util.StandardProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 89 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class ToggleDumbModeAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    if (myDumb) {
        myDumb = false;
    } else {
        myDumb = true;
        final Project project = e.getProject();
        if (project == null)
            return;
        DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {

            @Override
            public void performInDumbMode(@NotNull ProgressIndicator indicator) {
                while (myDumb) {
                    indicator.checkCanceled();
                    TimeoutUtil.sleep(100);
                }
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbModeTask(com.intellij.openapi.project.DumbModeTask)

Example 90 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class MacMessagesTest method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    JDialog controlDialog = new JDialog();
    controlDialog.setTitle("Messages testing control panel");
    controlDialog.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
    controlDialog.setModal(false);
    controlDialog.setFocusableWindowState(false);
    controlDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Container cp = controlDialog.getContentPane();
    cp.setLayout(new FlowLayout());
    JButton showDialogWrapperButton = new JButton("Show a dialog wrapper");
    showDialogWrapperButton.setFocusable(false);
    FocusManagerImpl fmi = FocusManagerImpl.getInstance();
    final Project p = fmi.getLastFocusedFrame().getProject();
    showDialogWrapperButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            DialogWrapper dw = new SimpleDialogWrapper(p);
            dw.setTitle(dw.getWindow().getName());
            dw.show();
        }
    });
    JButton showMessageButton = new JButton("Show a message");
    showDialogWrapperButton.setFocusable(false);
    showMessageButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            showTestMessage(p);
        }
    });
    JButton showProgressIndicatorButton = new JButton("Show progress indicator");
    showProgressIndicatorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Task task = new Task.Modal(null, "Test task", true) {

                public void run(@NotNull final ProgressIndicator indicator) {
                    ApplicationManager.getApplication().invokeAndWait(() -> {
                        FocusManagerImpl fmi1 = FocusManagerImpl.getInstance();
                        final Project p1 = fmi1.getLastFocusedFrame().getProject();
                        showTestMessage(p1);
                    }, ModalityState.any());
                }

                @Override
                public void onCancel() {
                }
            };
            ProgressManager.getInstance().run(task);
        }
    });
    cp.add(showDialogWrapperButton);
    cp.add(showMessageButton);
    cp.add(showProgressIndicatorButton);
    controlDialog.pack();
    controlDialog.setVisible(true);
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Task(com.intellij.openapi.progress.Task) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) ActionListener(java.awt.event.ActionListener) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)352 Task (com.intellij.openapi.progress.Task)139 NotNull (org.jetbrains.annotations.NotNull)98 VirtualFile (com.intellij.openapi.vfs.VirtualFile)96 Project (com.intellij.openapi.project.Project)78 File (java.io.File)52 IOException (java.io.IOException)48 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)44 Nullable (org.jetbrains.annotations.Nullable)43 ProgressManager (com.intellij.openapi.progress.ProgressManager)35 List (java.util.List)30 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)28 Ref (com.intellij.openapi.util.Ref)27 VcsException (com.intellij.openapi.vcs.VcsException)25 ArrayList (java.util.ArrayList)23 ApplicationManager (com.intellij.openapi.application.ApplicationManager)22 Module (com.intellij.openapi.module.Module)21 Logger (com.intellij.openapi.diagnostic.Logger)20 java.util (java.util)20 Processor (com.intellij.util.Processor)18