Search in sources :

Example 1 with ComponentDriver

use of org.fest.swing.driver.ComponentDriver in project android by JetBrains.

the class NlComponentFixture method invokeContextMenuAction.

public void invokeContextMenuAction(String actionLabel) {
    rightClick();
    Robot robot = myRobot;
    JMenuItem found = robot.finder().find(myIdeFrame.target(), Matchers.byText(JMenuItem.class, actionLabel));
    new ComponentDriver(robot).click(found);
    robot.waitForIdle();
}
Also used : ComponentDriver(org.fest.swing.driver.ComponentDriver) Robot(org.fest.swing.core.Robot)

Example 2 with ComponentDriver

use of org.fest.swing.driver.ComponentDriver in project android by JetBrains.

the class EditorFixture method invokeAction.

/** Invokes {@code editorAction} via its (first) keyboard shortcut in the active keymap. */
public EditorFixture invokeAction(@NotNull EditorAction editorAction) {
    AnAction anAction = ActionManager.getInstance().getAction(editorAction.id);
    assertTrue(editorAction.id + " is not enabled", anAction.getTemplatePresentation().isEnabled());
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut shortcut = keymap.getShortcuts(editorAction.id)[0];
    if (shortcut instanceof KeyboardShortcut) {
        KeyboardShortcut cs = (KeyboardShortcut) shortcut;
        KeyStroke firstKeyStroke = cs.getFirstKeyStroke();
        Component component = getFocusedEditor();
        if (component != null) {
            ComponentDriver driver = new ComponentDriver(robot);
            driver.pressAndReleaseKey(component, firstKeyStroke.getKeyCode(), new int[] { firstKeyStroke.getModifiers() });
            KeyStroke secondKeyStroke = cs.getSecondKeyStroke();
            if (secondKeyStroke != null) {
                driver.pressAndReleaseKey(component, secondKeyStroke.getKeyCode(), new int[] { secondKeyStroke.getModifiers() });
            }
        } else {
            fail("Editor not focused for action");
        }
    } else {
        fail("Unsupported shortcut type " + shortcut.getClass().getName());
    }
    return this;
}
Also used : ComponentDriver(org.fest.swing.driver.ComponentDriver) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) ThemeEditorComponent(com.android.tools.idea.editors.theme.ThemeEditorComponent) AnAction(com.intellij.openapi.actionSystem.AnAction) Keymap(com.intellij.openapi.keymap.Keymap)

Example 3 with ComponentDriver

use of org.fest.swing.driver.ComponentDriver 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 4 with ComponentDriver

use of org.fest.swing.driver.ComponentDriver in project intellij-community by JetBrains.

the class EditorFixture method invokeActionViaKeystroke.

private void invokeActionViaKeystroke(@NotNull String actionId) {
    AnAction action = ActionManager.getInstance().getAction(actionId);
    assertNotNull(actionId, action);
    assertTrue(actionId + " is not enabled", action.getTemplatePresentation().isEnabled());
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] shortcuts = keymap.getShortcuts(actionId);
    assertNotNull(shortcuts);
    assertThat(shortcuts).isNotEmpty();
    Shortcut shortcut = shortcuts[0];
    if (shortcut instanceof KeyboardShortcut) {
        KeyboardShortcut cs = (KeyboardShortcut) shortcut;
        KeyStroke firstKeyStroke = cs.getFirstKeyStroke();
        Component component = getFocusedEditor();
        if (component != null) {
            ComponentDriver driver = new ComponentDriver(robot);
            System.out.println("Invoking editor action " + actionId + " via shortcut " + KeyEvent.getKeyModifiersText(firstKeyStroke.getModifiers()) + KeyEvent.getKeyText(firstKeyStroke.getKeyCode()));
            driver.pressAndReleaseKey(component, firstKeyStroke.getKeyCode(), new int[] { firstKeyStroke.getModifiers() });
            KeyStroke secondKeyStroke = cs.getSecondKeyStroke();
            if (secondKeyStroke != null) {
                System.out.println(" and " + KeyEvent.getKeyModifiersText(secondKeyStroke.getModifiers()) + KeyEvent.getKeyText(secondKeyStroke.getKeyCode()));
                driver.pressAndReleaseKey(component, secondKeyStroke.getKeyCode(), new int[] { secondKeyStroke.getModifiers() });
            }
        } else {
            fail("Editor not focused for action");
        }
    } else {
        fail("Unsupported shortcut type " + shortcut.getClass().getName());
    }
}
Also used : ComponentDriver(org.fest.swing.driver.ComponentDriver) Keymap(com.intellij.openapi.keymap.Keymap)

Example 5 with ComponentDriver

use of org.fest.swing.driver.ComponentDriver in project android by JetBrains.

the class EditorFixture method getFocusedEditor.

/**
   * Requests focus in the editor, waits and returns editor component
   */
@NotNull
private JComponent getFocusedEditor() {
    Editor editor = GuiQuery.getNonNull(() -> {
        Editor selectedTextEditor = FileEditorManager.getInstance(myFrame.getProject()).getSelectedTextEditor();
        checkState(selectedTextEditor != null, "no currently selected text editor");
        return selectedTextEditor;
    });
    JComponent contentComponent = editor.getContentComponent();
    new ComponentDriver(robot).focusAndWaitForFocusGain(contentComponent);
    return contentComponent;
}
Also used : ComponentDriver(org.fest.swing.driver.ComponentDriver) StringResourceEditor(com.android.tools.idea.editors.strings.StringResourceEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ComponentDriver (org.fest.swing.driver.ComponentDriver)7 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 Keymap (com.intellij.openapi.keymap.Keymap)2 StringResourceEditor (com.android.tools.idea.editors.strings.StringResourceEditor)1 ThemeEditorComponent (com.android.tools.idea.editors.theme.ThemeEditorComponent)1 NlEditor (com.android.tools.idea.uibuilder.editor.NlEditor)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 KeyboardShortcut (com.intellij.openapi.actionSystem.KeyboardShortcut)1 Shortcut (com.intellij.openapi.actionSystem.Shortcut)1 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 Robot (org.fest.swing.core.Robot)1 Condition (org.fest.swing.timing.Condition)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1