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