Search in sources :

Example 31 with Condition

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

the class SelectSdkDialogFixture method selectPathToSdk.

public SelectSdkDialogFixture selectPathToSdk(@NotNull File pathToSdk) {
    final JTextField textField = myRobot.finder().findByType(JTextField.class);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            textField.setText(pathToSdk.getPath());
        }
    });
    final Tree tree = myRobot.finder().findByType(myDialog, Tree.class);
    final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree);
    pause(new Condition("Wait until path is updated") {

        @Override
        public boolean test() {
            //noinspection ConstantConditions
            return execute(new GuiQuery<Boolean>() {

                @Override
                protected Boolean executeInEDT() throws Throwable {
                    return (textField.getText().equals(pathToSdk.getPath()) && !builder.getUi().getUpdater().hasNodesToUpdate());
                }
            });
        }
    }, SHORT_TIMEOUT);
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) GuiQuery(org.fest.swing.edt.GuiQuery) Tree(com.intellij.ui.treeStructure.Tree)

Example 32 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 String displayName, @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 with display name " + displayName) {

        @Override
        public boolean test() {
            Content[] contents = getContents();
            for (Content content : contents) {
                if (displayName.equals(content.getDisplayName())) {
                    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 33 with Condition

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

the class ToolWindowFixture method activate.

public void activate() {
    if (isActive()) {
        return;
    }
    final Callback callback = new Callback();
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            myToolWindow.activate(callback);
        }
    });
    pause(new Condition("Wait for ToolWindow '" + myToolWindowId + "' to be activated") {

        @Override
        public boolean test() {
            return callback.finished;
        }
    }, GuiTestUtil.SHORT_TIMEOUT);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition)

Example 34 with Condition

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

the class GuiTestUtil method waitUntilFound.

/**
   * Waits for a first component which passes the given matcher under the given root to become visible.
   */
@NotNull
public static <T extends Component> T waitUntilFound(@NotNull final Robot robot, @Nullable final Container root, @NotNull final GenericTypeMatcher<T> matcher, @NotNull Timeout timeout) {
    final AtomicReference<T> reference = new AtomicReference<T>();
    Pause.pause(new Condition("Find component using " + matcher.toString()) {

        @Override
        public boolean test() {
            ComponentFinder finder = robot.finder();
            Collection<T> allFound = root != null ? finder.findAll(root, matcher) : finder.findAll(matcher);
            boolean found = allFound.size() == 1;
            if (found) {
                reference.set(getFirstItem(allFound));
            } else if (allFound.size() > 1) {
                // Only allow a single component to be found, otherwise you can get some really confusing
                // test failures; the matcher should pick a specific enough instance
                fail("Found more than one " + matcher.supportedType().getSimpleName() + " which matches the criteria: " + allFound);
            }
            return found;
        }
    }, timeout);
    return reference.get();
}
Also used : Condition(org.fest.swing.timing.Condition) Collection(java.util.Collection) AtomicReference(java.util.concurrent.atomic.AtomicReference) NotNull(org.jetbrains.annotations.NotNull) Assert.assertNotNull(org.junit.Assert.assertNotNull)

Example 35 with Condition

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

the class GuiTestUtil method findButton.

@NotNull
public static JButton findButton(@NotNull ContainerFixture<? extends Container> container, @NotNull final String text, Robot robot) {
    GenericTypeMatcher<JButton> matcher = new GenericTypeMatcher<JButton>(JButton.class) {

        @Override
        protected boolean isMatching(@NotNull JButton button) {
            String buttonText = button.getText();
            if (buttonText != null) {
                return buttonText.trim().equals(text) && button.isShowing();
            }
            return false;
        }
    };
    Pause.pause(new Condition("Finding for a button with text \"" + text + "\"") {

        @Override
        public boolean test() {
            Collection<JButton> buttons = robot.finder().findAll(matcher);
            return !buttons.isEmpty();
        }
    }, SHORT_TIMEOUT);
    return robot.finder().find(container.target(), matcher);
}
Also used : Condition(org.fest.swing.timing.Condition) Collection(java.util.Collection) NotNull(org.jetbrains.annotations.NotNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull) Assert.assertNotNull(org.junit.Assert.assertNotNull)

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