Search in sources :

Example 16 with Condition

use of org.fest.swing.timing.Condition 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 17 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class NewProjectWizardFixture method selectSdkPath.

public NewProjectWizardFixture selectSdkPath(@NotNull File sdkPath, String sdkType) {
    final SelectSdkDialogFixture sdkDialogFixture = SelectSdkDialogFixture.find(robot(), sdkType);
    sdkDialogFixture.selectPathToSdk(sdkPath).clickOk();
    pause(new Condition("Waiting for the returning of focus to dialog: " + target().getTitle()) {

        @Override
        public boolean test() {
            return target().isFocused();
        }
    }, GuiTestUtil.SHORT_TIMEOUT);
    return this;
}
Also used : Condition(org.fest.swing.timing.Condition) SelectSdkDialogFixture(com.intellij.testGuiFramework.fixtures.SelectSdkDialogFixture)

Example 18 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class GuiTestBase method closeAllProjects.

@SuppressWarnings("UnusedDeclaration")
protected // Called by GuiTestRunner via reflection.
void closeAllProjects() {
    pause(new Condition("Close all projects") {

        @Override
        public boolean test() {
            final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            execute(new GuiTask() {

                @Override
                protected void executeInEDT() throws Throwable {
                    TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> {
                        for (Project project : openProjects) {
                            assertTrue("Failed to close project " + quote(project.getName()), closeAndDispose(project));
                        }
                    });
                }
            });
            return ProjectManager.getInstance().getOpenProjects().length == 0;
        }
    }, SHORT_TIMEOUT);
    //noinspection ConstantConditions
    boolean welcomeFrameShown = execute(new GuiQuery<Boolean>() {

        @Override
        protected Boolean executeInEDT() throws Throwable {
            Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            if (openProjects.length == 0) {
                WelcomeFrame.showNow();
                WindowManagerImpl windowManager = (WindowManagerImpl) WindowManager.getInstance();
                windowManager.disposeRootFrame();
                return true;
            }
            return false;
        }
    });
    if (welcomeFrameShown) {
        pause(new Condition("'Welcome' frame to show up") {

            @Override
            public boolean test() {
                for (Frame frame : Frame.getFrames()) {
                    if (frame == WelcomeFrame.getInstance() && frame.isShowing()) {
                        return true;
                    }
                }
                return false;
            }
        }, SHORT_TIMEOUT);
    }
}
Also used : Condition(org.fest.swing.timing.Condition) GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) WelcomeFrame(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame) WindowManagerImpl(com.intellij.openapi.wm.impl.WindowManagerImpl)

Example 19 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class NewProjectWizardFixture method setProjectName.

@NotNull
public NewProjectWizardFixture setProjectName(@NotNull String projectName) {
    String labelText = GuiTestUtil.adduction(IdeBundle.message("label.project.name"));
    pause(new Condition("Waiting for the sliding to project name settings") {

        @Override
        public boolean test() {
            final Component label;
            try {
                label = robot().finder().findByLabel(labelText);
            } catch (ComponentLookupException componentLookupException) {
                return false;
            }
            return true;
        }
    }, GuiTestUtil.SHORT_TIMEOUT);
    final JTextComponentFixture textField = findTextField(labelText);
    robot().click(textField.target());
    textField.setText(projectName);
    return this;
}
Also used : Condition(org.fest.swing.timing.Condition) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class JBListPopupFixture method findListPopup.

public static JBListPopupFixture findListPopup(Robot robot) {
    pause(new Condition("Find JBList popup") {

        @Override
        public boolean test() {
            final JBList jblist = getList(robot);
            return jblist != null;
        }
    }, SHORT_TIMEOUT);
    final JBList jblist = getList(robot);
    Assert.assertNotNull(jblist);
    return new JBListPopupFixture(jblist, robot);
}
Also used : Condition(org.fest.swing.timing.Condition) JBList(com.intellij.ui.components.JBList)

Aggregations

Condition (org.fest.swing.timing.Condition)36 NotNull (org.jetbrains.annotations.NotNull)17 Ref (com.intellij.openapi.util.Ref)9 GuiTask (org.fest.swing.edt.GuiTask)8 Collection (java.util.Collection)7 Assert.assertNotNull (junit.framework.Assert.assertNotNull)6 GenericTypeMatcher (org.fest.swing.core.GenericTypeMatcher)5 GuiQuery (org.fest.swing.edt.GuiQuery)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 ComponentLookupException (org.fest.swing.exception.ComponentLookupException)4 Nullable (org.jetbrains.annotations.Nullable)4 Project (com.intellij.openapi.project.Project)3 Content (com.intellij.ui.content.Content)3 ProjectView (com.intellij.ide.projectView.ProjectView)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2