Search in sources :

Example 26 with Condition

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

the class ProjectViewFixture method selectAndroidPane.

@NotNull
public PaneFixture selectAndroidPane() {
    activate();
    final ProjectView projectView = ProjectView.getInstance(myProject);
    pause(new Condition("Project view is initialized") {

        @Override
        public boolean test() {
            //noinspection ConstantConditions
            return field("isInitialized").ofType(boolean.class).in(projectView).get();
        }
    }, SHORT_TIMEOUT);
    final String id = "AndroidView";
    GuiActionRunner.execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            projectView.changeView(id);
        }
    });
    return new PaneFixture(projectView.getProjectViewPaneById(id));
}
Also used : Condition(org.fest.swing.timing.Condition) GuiTask(org.fest.swing.edt.GuiTask) ProjectView(com.intellij.ide.projectView.ProjectView) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with Condition

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

the class ProjectViewFixture method selectProjectPane.

@NotNull
public PaneFixture selectProjectPane() {
    activate();
    final ProjectView projectView = ProjectView.getInstance(myProject);
    pause(new Condition("Project view is initialized") {

        @Override
        public boolean test() {
            //noinspection ConstantConditions
            return field("isInitialized").ofType(boolean.class).in(projectView).get();
        }
    }, SHORT_TIMEOUT);
    final String id = "ProjectPane";
    GuiActionRunner.execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            projectView.changeView(id);
        }
    });
    return new PaneFixture(projectView.getProjectViewPaneById(id));
}
Also used : Condition(org.fest.swing.timing.Condition) GuiTask(org.fest.swing.edt.GuiTask) ProjectView(com.intellij.ide.projectView.ProjectView) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with Condition

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

the class EditorFixture method getFocusedEditor.

/**
   * Requests focus in the editor, waits and returns editor component
   */
@Nullable
private JComponent getFocusedEditor() {
    Editor editor = execute(new GuiQuery<Editor>() {

        @Override
        @Nullable
        protected Editor executeInEDT() throws Throwable {
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            // Must be called from the EDT
            return manager.getSelectedTextEditor();
        }
    });
    //wait when TextEditor ContentComponent will showing
    pause(new Condition("Waiting for showing focused textEditor") {

        @Override
        public boolean test() {
            return editor.getContentComponent().isShowing();
        }
    }, SHORT_TIMEOUT);
    if (editor != null) {
        JComponent contentComponent = editor.getContentComponent();
        new ComponentDriver(robot).focusAndWaitForFocusGain(contentComponent);
        assertSame(contentComponent, FocusManager.getCurrentManager().getFocusOwner());
        return contentComponent;
    } else {
        fail("Expected to find editor to focus, but there is no current editor");
        return null;
    }
}
Also used : Condition(org.fest.swing.timing.Condition) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ComponentDriver(org.fest.swing.driver.ComponentDriver) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with Condition

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

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