Search in sources :

Example 11 with Condition

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

the class ToolWindowFixture method getContent.

@Nullable
protected Content getContent(@NotNull final TextMatcher displayNameMatcher, @NotNull Timeout timeout) {
    long now = System.currentTimeMillis();
    long budget = timeout.duration();
    activateAndWaitUntilIsVisible(Timeout.timeout(budget));
    long revisedNow = System.currentTimeMillis();
    budget -= (revisedNow - now);
    final Ref<Content> contentRef = new Ref<>();
    pause(new Condition("finding content matching " + displayNameMatcher.formattedValues()) {

        @Override
        public boolean test() {
            Content[] contents = getContents();
            for (Content content : contents) {
                String displayName = content.getDisplayName();
                if (displayNameMatcher.isMatching(displayName)) {
                    contentRef.set(content);
                    return true;
                }
            }
            return false;
        }
    }, Timeout.timeout(budget));
    return contentRef.get();
}
Also used : Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) Content(com.intellij.ui.content.Content) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with Condition

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

the class IdeFrameFixture method find.

@NotNull
public static IdeFrameFixture find(@NotNull final Robot robot, @Nullable final File projectPath, @Nullable final String projectName) {
    final GenericTypeMatcher<IdeFrameImpl> matcher = new GenericTypeMatcher<IdeFrameImpl>(IdeFrameImpl.class) {

        @Override
        protected boolean isMatching(@NotNull IdeFrameImpl frame) {
            Project project = frame.getProject();
            if (projectPath == null && project != null)
                return true;
            if (project != null && PathManager.getAbsolutePath(projectPath.getPath()).equals(PathManager.getAbsolutePath(project.getBasePath()))) {
                return projectName == null || projectName.equals(project.getName());
            }
            return false;
        }
    };
    Pause.pause(new Condition("IdeFrame " + (projectPath != null ? quote(projectPath.getPath()) : "") + " to show up") {

        @Override
        public boolean test() {
            Collection<IdeFrameImpl> frames = robot.finder().findAll(matcher);
            return !frames.isEmpty();
        }
    }, GuiTestUtil.LONG_TIMEOUT);
    IdeFrameImpl ideFrame = robot.finder().find(matcher);
    return new IdeFrameFixture(robot, ideFrame, new File(ideFrame.getProject().getBasePath()));
}
Also used : Condition(org.fest.swing.timing.Condition) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) Project(com.intellij.openapi.project.Project) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Condition

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

the class IdeFrameFixture method requireEditorNotification.

@NotNull
public EditorNotificationPanelFixture requireEditorNotification(@NotNull final String message) {
    final Ref<EditorNotificationPanel> notificationPanelRef = new Ref<EditorNotificationPanel>();
    pause(new Condition("Notification with message '" + message + "' shows up") {

        @Override
        public boolean test() {
            EditorNotificationPanel notificationPanel = findNotificationPanel(message);
            notificationPanelRef.set(notificationPanel);
            return notificationPanel != null;
        }
    });
    EditorNotificationPanel notificationPanel = notificationPanelRef.get();
    assertNotNull(notificationPanel);
    return new EditorNotificationPanelFixture(robot(), notificationPanel);
}
Also used : Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with Condition

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

the class IdeFrameFixture method closeProject.

public void closeProject() {
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            closeAndDispose(getProject());
            RecentProjectsManager.getInstance().updateLastProjectPath();
            WelcomeFrame.showIfNoProjectOpened();
        }
    });
    pause(new Condition("Waiting for 'Welcome' page to show up") {

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

Example 15 with Condition

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

the class JBPopupFixture method invokeAction.

public void invokeAction(String... actionPath) {
    boolean assertion = false;
    final MenuElement[] elements = myContextMenu.getSubElements();
    if (actionPath.length > 1) {
        //actionGroup
        for (MenuElement element : elements) {
            if (element instanceof ActionMenu) {
                final ActionMenu actionMenu = (ActionMenu) element;
                if (actionMenu.getText().toLowerCase().contains(actionPath[0].toLowerCase())) {
                    final Point locationOnScreen = myContextMenu.getLocationOnScreen();
                    final Rectangle bounds = actionMenu.getBounds();
                    final Point point = new Point(locationOnScreen.x + bounds.x + bounds.width / 2, locationOnScreen.y + bounds.y + bounds.height / 2);
                    robot().click(point, MouseButton.LEFT_BUTTON, 1);
                    //invoke action for a new JBPopupMenu
                    final String actionName = actionPath[1];
                    final JBPopupFixture fixture = new JBPopupFixture(waitUntilFoundMenu(actionName), myRobot);
                    fixture.invokeAction(ArrayUtil.remove(actionPath, 0));
                    return;
                }
            }
        }
    } else {
        //actionMenuItem
        for (MenuElement element : elements) {
            if (element instanceof ActionMenuItem) {
                final ActionMenuItem actionMenuItem = (ActionMenuItem) element;
                if (actionMenuItem.getText().toLowerCase().contains(actionPath[0].toLowerCase())) {
                    pause(new Condition("Waiting to showing JBPopupMenu on screen") {

                        @Override
                        public boolean test() {
                            try {
                                myContextMenu.getLocationOnScreen();
                                return true;
                            } catch (IllegalComponentStateException e) {
                                return false;
                            }
                        }
                    }, SHORT_TIMEOUT);
                    final Point locationOnScreen = myContextMenu.getLocationOnScreen();
                    final Rectangle bounds = actionMenuItem.getBounds();
                    final Point point = new Point(locationOnScreen.x + bounds.x + bounds.width / 2, locationOnScreen.y + bounds.y + bounds.height / 2);
                    robot().click(point, MouseButton.LEFT_BUTTON, 1);
                    return;
                }
            }
        }
    }
}
Also used : Condition(org.fest.swing.timing.Condition) ActionMenuItem(com.intellij.openapi.actionSystem.impl.ActionMenuItem) ActionMenu(com.intellij.openapi.actionSystem.impl.ActionMenu)

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