Search in sources :

Example 26 with GuiTask

use of org.fest.swing.edt.GuiTask in project intellij-community by JetBrains.

the class RunConfigurationsDialogFixture method click.

private void click(final JBList popupList, String text) {
    JListFixture popupFixture = new JListFixture(robot(), popupList);
    popupFixture.replaceCellReader(new MakeStepsCellReader());
    final int index = popupFixture.item(text).index();
    // For some reason calling popupFixture.click(...) doesn't work, but this does:
    GuiActionRunner.execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            popupList.setSelectedIndex(index);
        }
    });
    robot().pressAndReleaseKey(KeyEvent.VK_ENTER);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) JListFixture(org.fest.swing.fixture.JListFixture)

Example 27 with GuiTask

use of org.fest.swing.edt.GuiTask in project intellij-community by JetBrains.

the class EditorFixture method open.

/**
   * Opens up a different file. This will run through the "Open File..." dialog to
   * find and select the given file.
   *
   * @param file the file to open
   * @param tab which tab to open initially, if there are multiple editors
   */
public EditorFixture open(@NotNull final VirtualFile file, @NotNull final Tab tab) {
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            // TODO: Use UI to navigate to the file instead
            Project project = myFrame.getProject();
            FileEditorManager manager = FileEditorManager.getInstance(project);
            if (tab == Tab.EDITOR) {
                manager.openTextEditor(new OpenFileDescriptor(project, file), true);
            } else {
                manager.openFile(file, true);
            }
        }
    });
    pause(new Condition("File " + quote(file.getPath()) + " to be opened") {

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

                @Override
                protected Boolean executeInEDT() throws Throwable {
                    FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getEditors(file);
                    if (editors.length == 0)
                        return false;
                    return editors[0].getComponent().isShowing();
                }
            });
        }
    }, SHORT_TIMEOUT);
    // TODO: Maybe find a better way to keep Documents in sync with their VirtualFiles.
    invokeActionViaKeystroke("Synchronize");
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) GuiQuery(org.fest.swing.edt.GuiQuery) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 28 with GuiTask

use of org.fest.swing.edt.GuiTask 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 29 with GuiTask

use of org.fest.swing.edt.GuiTask 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 30 with GuiTask

use of org.fest.swing.edt.GuiTask in project intellij-community by JetBrains.

the class GuiTestUtil method acceptAgreementIfNeeded.

private static void acceptAgreementIfNeeded(Robot robot) {
    final String policyAgreement = "Privacy Policy Agreement";
    Pair<PrivacyPolicy.Version, String> policy = PrivacyPolicy.getContent();
    boolean showPrivacyPolicyAgreement = !PrivacyPolicy.isVersionAccepted(policy.getFirst());
    if (!showPrivacyPolicyAgreement) {
        LOG.info(policyAgreement + " dialog should be skipped on this system.");
        return;
    }
    try {
        final DialogFixture privacyDialogFixture = findDialog(new GenericTypeMatcher<JDialog>(JDialog.class) {

            @Override
            protected boolean isMatching(@NotNull JDialog dialog) {
                if (dialog.getTitle() == null)
                    return false;
                return dialog.getTitle().contains(policyAgreement) && dialog.isShowing();
            }
        }).withTimeout(LONG_TIMEOUT.duration()).using(robot);
        String buttonText = "Accept";
        JButton acceptButton = privacyDialogFixture.button(new GenericTypeMatcher<JButton>(JButton.class) {

            @Override
            protected boolean isMatching(@NotNull JButton button) {
                if (button.getText() == null)
                    return false;
                return button.getText().equals(buttonText);
            }
        }).target();
        //we clicking this button to avoid NPE org.fest.util.Preconditions.checkNotNull(Preconditions.java:71)
        execute(new GuiTask() {

            @Override
            protected void executeInEDT() throws Throwable {
                EdtInvocationManager.getInstance().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        acceptButton.doClick();
                    }
                });
            }
        });
    } catch (WaitTimedOutError we) {
        LOG.warn("Timed out waiting for \"" + policyAgreement + "\" JDialog. Continue...");
    }
}
Also used : WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) NotNull(org.jetbrains.annotations.NotNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) GuiTask(org.fest.swing.edt.GuiTask)

Aggregations

GuiTask (org.fest.swing.edt.GuiTask)38 NotNull (org.jetbrains.annotations.NotNull)16 Condition (org.fest.swing.timing.Condition)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Project (com.intellij.openapi.project.Project)7 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)5 Module (com.intellij.openapi.module.Module)5 File (java.io.File)4 Test (org.junit.Test)4 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3 JBList (com.intellij.ui.components.JBList)3 Assert.assertNotNull (junit.framework.Assert.assertNotNull)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)2 ProjectView (com.intellij.ide.projectView.ProjectView)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2