Search in sources :

Example 11 with ProgressManager

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

the class GuiTestUtil method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        final MyProjectManagerListener listener = new MyProjectManagerListener();
        //[ACCEPT IntelliJ IDEA Privacy Policy Agreement]
        acceptAgreementIfNeeded(robot);
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(LONG_TIMEOUT.duration()).using(robot);
        if (listener.myActive) {
            Pause.pause(new Condition("Project to be opened") {

                @Override
                public boolean test() {
                    boolean notified = listener.myNotified;
                    if (notified) {
                        ProgressManager progressManager = ProgressManager.getInstance();
                        boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                        if (isIdle) {
                            ProjectManager.getInstance().removeProjectManagerListener(listener);
                        }
                        return isIdle;
                    }
                    return false;
                }
            }, LONG_TIMEOUT);
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : Condition(org.fest.swing.timing.Condition) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 12 with ProgressManager

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

the class ImportIntoShelfAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true);
    FileChooser.chooseFiles(descriptor, project, null, new Consumer<List<VirtualFile>>() {

        @Override
        public void consume(final List<VirtualFile> files) {
            //gatherPatchFiles
            final ProgressManager pm = ProgressManager.getInstance();
            final ShelveChangesManager shelveChangesManager = ShelveChangesManager.getInstance(project);
            final List<VirtualFile> patchTypeFiles = new ArrayList<>();
            final boolean filesFound = pm.runProcessWithProgressSynchronously(new Runnable() {

                @Override
                public void run() {
                    patchTypeFiles.addAll(shelveChangesManager.gatherPatchFiles(files));
                }
            }, "Looking for patch files...", true, project);
            if (!filesFound || patchTypeFiles.isEmpty())
                return;
            if (!patchTypeFiles.equals(files)) {
                final String message = "Found " + (patchTypeFiles.size() == 1 ? "one patch file (" + patchTypeFiles.get(0).getPath() + ")." : (patchTypeFiles.size() + " patch files.")) + "\nContinue with import?";
                final int toImport = Messages.showYesNoDialog(project, message, "Import Patches", Messages.getQuestionIcon());
                if (Messages.NO == toImport)
                    return;
            }
            pm.runProcessWithProgressSynchronously(new Runnable() {

                @Override
                public void run() {
                    final List<VcsException> exceptions = new ArrayList<>();
                    final List<ShelvedChangeList> lists = shelveChangesManager.importChangeLists(patchTypeFiles, new Consumer<VcsException>() {

                        @Override
                        public void consume(VcsException e) {
                            exceptions.add(e);
                        }
                    });
                    if (!lists.isEmpty()) {
                        ShelvedChangesViewManager.getInstance(project).activateView(lists.get(lists.size() - 1));
                    }
                    if (!exceptions.isEmpty()) {
                        AbstractVcsHelper.getInstance(project).showErrors(exceptions, "Import patches into shelf");
                    }
                    if (lists.isEmpty() && exceptions.isEmpty()) {
                        VcsBalloonProblemNotifier.showOverChangesView(project, "No patches found", MessageType.WARNING);
                    }
                }
            }, "Import patches into shelf", true, project);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with ProgressManager

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

the class GitHandlerUtil method doSynchronously.

/**
   * Execute simple process synchronously with progress
   *
   * @param handler        a handler
   * @param operationTitle an operation title shown in progress dialog
   * @param operationName  an operation name shown in failure dialog
   * @return A stdout content or null if there was error (exit code != 0 or exception during start).
   */
@Nullable
public static String doSynchronously(final GitSimpleHandler handler, final String operationTitle, @NonNls final String operationName) {
    handler.addListener(new GitHandlerListenerBase(handler, operationName) {

        protected String getErrorText() {
            String text = handler.getStderr();
            if (text.length() == 0) {
                text = handler.getStdout();
            }
            return text;
        }
    });
    final ProgressManager manager = ProgressManager.getInstance();
    manager.runProcessWithProgressSynchronously(new Runnable() {

        public void run() {
            runInCurrentThread(handler, manager.getProgressIndicator(), true, operationTitle);
        }
    }, operationTitle, false, handler.project());
    if (!handler.isStarted() || handler.getExitCode() != 0) {
        return null;
    }
    return handler.getStdout();
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with ProgressManager

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

the class GitHandlerUtil method doSynchronously.

/**
   * Execute simple process synchronously with progress
   *
   * @param handler        a handler
   * @param operationTitle an operation title shown in progress dialog
   * @param operationName  an operation name shown in failure dialog
   * @return An exit code
   */
public static int doSynchronously(final GitLineHandler handler, final String operationTitle, @NonNls final String operationName) {
    final ProgressManager manager = ProgressManager.getInstance();
    manager.run(new Task.Modal(handler.project(), operationTitle, true) {

        public void run(@NotNull final ProgressIndicator indicator) {
            handler.addLineListener(new GitLineHandlerListenerProgress(indicator, handler, operationName, true));
            runInCurrentThread(handler, indicator, true, operationTitle);
        }
    });
    if (!handler.isStarted()) {
        return -1;
    }
    return handler.getExitCode();
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 15 with ProgressManager

use of com.intellij.openapi.progress.ProgressManager in project android by JetBrains.

the class GuiTests method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        MyProjectManagerListener listener = new MyProjectManagerListener();
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(TimeUnit.MINUTES.toMillis(2)).using(robot);
        // we attempt to clear here. All other events, including those posted by the Robot, will go through the IDE event queue.
        try {
            if (SYSTEM_EVENT_QUEUE.peekEvent() != null) {
                SYSTEM_EVENT_QUEUE.getNextEvent();
            }
        } catch (InterruptedException ex) {
        // Ignored.
        }
        if (listener.myActive) {
            Wait.seconds(1).expecting("project to be opened").until(() -> {
                boolean notified = listener.myNotified;
                if (notified) {
                    ProgressManager progressManager = ProgressManager.getInstance();
                    boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                    if (isIdle) {
                        ProjectManager.getInstance().removeProjectManagerListener(listener);
                    }
                    return isIdle;
                }
                return false;
            });
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Aggregations

ProgressManager (com.intellij.openapi.progress.ProgressManager)24 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)13 Task (com.intellij.openapi.progress.Task)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 VcsException (com.intellij.openapi.vcs.VcsException)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Robot (org.fest.swing.core.Robot)2 WindowFinder.findFrame (org.fest.swing.finder.WindowFinder.findFrame)2 Condition (org.fest.swing.timing.Condition)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 SensitiveProgressWrapper (com.intellij.concurrency.SensitiveProgressWrapper)1 ThreadDumper (com.intellij.diagnostic.ThreadDumper)1