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();
}
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;
}
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;
}
}
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());
}
}
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;
}
Aggregations