Search in sources :

Example 1 with GuiTask

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

the class EditorFixture method moveToAndClick.

/**
   * Moves the caret to the given caret offset (0-based).
   *
   * @param offset the character offset.
   */
public EditorFixture moveToAndClick(final int offset, MouseButton button) {
    assertThat(offset).isGreaterThanOrEqualTo(0);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            Editor editor = manager.getSelectedTextEditor();
            assert editor != null;
            VisualPosition visualPosition = editor.offsetToVisualPosition(offset);
            Point point = editor.visualPositionToXY(visualPosition);
            Component editorComponent = robot.finder().find(editor.getComponent(), component -> component instanceof EditorComponentImpl);
            robot.click(editorComponent, point, button, 1);
        }
    });
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Condition(org.fest.swing.timing.Condition) GuiQuery(org.fest.swing.edt.GuiQuery) KeymapManager(com.intellij.openapi.keymap.KeymapManager) ComponentDriver(org.fest.swing.driver.ComponentDriver) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) com.intellij.openapi.editor(com.intellij.openapi.editor) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) MouseButton(org.fest.swing.core.MouseButton) GuiActionRunner.execute(org.fest.swing.edt.GuiActionRunner.execute) Strings.quote(org.fest.util.Strings.quote) Keymap(com.intellij.openapi.keymap.Keymap) ArrayList(java.util.ArrayList) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Reflection.method(org.fest.reflect.core.Reflection.method) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Project(com.intellij.openapi.project.Project) TextHitInfo(java.awt.font.TextHitInfo) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JBList(com.intellij.ui.components.JBList) FocusManager(javax.swing.FocusManager) GuiTestUtil(com.intellij.testGuiFramework.framework.GuiTestUtil) TextRange(com.intellij.openapi.util.TextRange) AttributedString(java.text.AttributedString) KeyEvent(java.awt.event.KeyEvent) FileEditor(com.intellij.openapi.fileEditor.FileEditor) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DialogFixture(org.fest.swing.fixture.DialogFixture) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) InputMethodEvent(java.awt.event.InputMethodEvent) AttributedCharacterIterator(java.text.AttributedCharacterIterator) GuiTask(org.fest.swing.edt.GuiTask) Pause.pause(org.fest.swing.timing.Pause.pause) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) Robot(org.fest.swing.core.Robot) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Example 2 with GuiTask

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

the class EditorFixture method moveToLine.

/**
   * Moves the caret to the start of the given line number (0-based).
   *
   * @param lineNumber the line number.
   */
@NotNull
public EditorFixture moveToLine(final int lineNumber) {
    assertThat(lineNumber).isGreaterThanOrEqualTo(0);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            // TODO: Do this via mouse clicks!
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            Editor editor = manager.getSelectedTextEditor();
            if (editor != null) {
                Document document = editor.getDocument();
                int offset = document.getLineStartOffset(lineNumber);
                editor.getCaretModel().moveToOffset(offset);
                editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
            }
        }
    });
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GuiTask

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

the class ComboBoxActionFixture method selectItemByText.

private static void selectItemByText(@NotNull final JList list, @NotNull final String text) {
    Pause.pause(new Condition("Wait until the list is populated.") {

        @Override
        public boolean test() {
            ListPopupModel popupModel = (ListPopupModel) list.getModel();
            for (int i = 0; i < popupModel.getSize(); ++i) {
                PopupFactoryImpl.ActionItem actionItem = (PopupFactoryImpl.ActionItem) popupModel.get(i);
                assertNotNull(actionItem);
                if (text.equals(actionItem.getText())) {
                    return true;
                }
            }
            return false;
        }
    }, GuiTestUtil.SHORT_TIMEOUT);
    final Integer appIndex = execute(new GuiQuery<Integer>() {

        @Override
        protected Integer executeInEDT() throws Throwable {
            ListPopupModel popupModel = (ListPopupModel) list.getModel();
            for (int i = 0; i < popupModel.getSize(); ++i) {
                PopupFactoryImpl.ActionItem actionItem = (PopupFactoryImpl.ActionItem) popupModel.get(i);
                assertNotNull(actionItem);
                if (text.equals(actionItem.getText())) {
                    return i;
                }
            }
            return -1;
        }
    });
    //noinspection ConstantConditions
    assertTrue(appIndex >= 0);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            list.setSelectedIndex(appIndex);
        }
    });
    assertEquals(text, ((PopupFactoryImpl.ActionItem) list.getSelectedValue()).getText());
}
Also used : Condition(org.fest.swing.timing.Condition) GuiTask(org.fest.swing.edt.GuiTask) PopupFactoryImpl(com.intellij.ui.popup.PopupFactoryImpl) ListPopupModel(com.intellij.ui.popup.list.ListPopupModel)

Example 4 with GuiTask

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

the class FrameworksTreeFixture method selectFramework.

@NotNull
public FrameworksTreeFixture selectFramework(String frameworkName) {
    myAdaptiveTree.getRoot();
    final Object parent = myAdaptiveTree.getRoot();
    for (int i = 0; i < myAdaptiveTree.getChildCount(parent); i++) {
        FrameworkSupportElement frameworkSupportElement = (FrameworkSupportElement) ((ComponentNode) myAdaptiveTree.getChild(parent, i)).getComponent();
        if (frameworkSupportElement.getText().equals(frameworkName)) {
            //scroll tree to path
            final TreePath treePath = myFrameworksTree.getPathForRow(i);
            GuiActionRunner.execute(new GuiTask() {

                @Override
                protected void executeInEDT() throws Throwable {
                    myFrameworksTree.scrollPathToVisible(treePath);
                }
            });
            final JCheckBox checkbox = frameworkSupportElement.getCheckbox();
            myRobot.click(checkbox);
            return this;
        }
    }
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) TreePath(javax.swing.tree.TreePath) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GuiTask

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

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