use of com.intellij.ui.popup.list.ListPopupModel 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 com.intellij.ui.popup.list.ListPopupModel in project intellij-community by JetBrains.
the class GuiTestUtil method clickPopupMenuItemMatching.
public static void clickPopupMenuItemMatching(@NotNull Matcher<String> labelMatcher, @NotNull Component component, @NotNull Robot robot, @NotNull Timeout timeout) {
// IntelliJ doesn't seem to use a normal JPopupMenu, so this won't work:
// JPopupMenu menu = myRobot.findActivePopupMenu();
// Instead, it uses a JList (technically a JBList), which is placed somewhere
// under the root pane.
Container root = getRootContainer(component);
// First find the JBList which holds the popup. There could be other JBLists in the hierarchy,
// so limit it to one that is actually used as a popup, as identified by its model being a ListPopupModel:
assertNotNull(root);
JBList list = waitUntilFound(robot, null, new GenericTypeMatcher<JBList>(JBList.class) {
@Override
protected boolean isMatching(@NotNull JBList list) {
ListModel model = list.getModel();
return model instanceof ListPopupModel;
}
}, timeout);
// We can't use the normal JListFixture method to click by label since the ListModel items are
// ActionItems whose toString does not reflect the text, so search through the model items instead:
ListPopupModel model = (ListPopupModel) list.getModel();
List<String> items = new ArrayList<>();
for (int i = 0; i < model.getSize(); i++) {
Object elementAt = model.getElementAt(i);
if (elementAt instanceof PopupFactoryImpl.ActionItem) {
PopupFactoryImpl.ActionItem item = (PopupFactoryImpl.ActionItem) elementAt;
String s = item.getText();
if (labelMatcher.matches(s)) {
new JListFixture(robot, list).clickItem(i);
return;
}
items.add(s);
} else {
// For example package private class IntentionActionWithTextCaching used in quickfix popups
String s = elementAt.toString();
if (labelMatcher.matches(s)) {
new JListFixture(robot, list).clickItem(i);
return;
}
items.add(s);
}
}
if (items.isEmpty()) {
fail("Could not find any menu items in popup");
}
fail("Did not find menu item '" + labelMatcher + "' among " + StringUtil.join(items, ", "));
}
use of com.intellij.ui.popup.list.ListPopupModel in project intellij-community by JetBrains.
the class BranchActionGroupPopup method getMoreActions.
@NotNull
private List<MoreAction> getMoreActions() {
List<MoreAction> result = ContainerUtil.newArrayList();
ListPopupModel model = getListModel();
for (int i = 0; i < model.getSize(); i++) {
MoreAction moreAction = getSpecificAction(model.getElementAt(i), MoreAction.class);
if (moreAction != null) {
result.add(moreAction);
}
}
return result;
}
use of com.intellij.ui.popup.list.ListPopupModel in project android by JetBrains.
the class ComboBoxActionFixture method selectItemByText.
private void selectItemByText(@NotNull final String text) {
JList list = GuiTests.waitUntilFound(myRobot, Matchers.byType(JBListWithHintProvider.class));
Wait.seconds(1).expecting("the list to be populated").until(() -> {
ListPopupModel popupModel = (ListPopupModel) list.getModel();
for (int i = 0; i < popupModel.getSize(); ++i) {
PopupFactoryImpl.ActionItem actionItem = (PopupFactoryImpl.ActionItem) popupModel.get(i);
if (text.equals(actionItem.getText())) {
return true;
}
}
return false;
});
int appIndex = GuiQuery.getNonNull(() -> {
ListPopupModel popupModel = (ListPopupModel) list.getModel();
for (int i = 0; i < popupModel.getSize(); ++i) {
PopupFactoryImpl.ActionItem actionItem = (PopupFactoryImpl.ActionItem) popupModel.get(i);
if (text.equals(actionItem.getText())) {
return i;
}
}
return -1;
});
assertThat(appIndex).isAtLeast(0);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
list.setSelectedIndex(appIndex);
}
});
assertEquals(text, ((PopupFactoryImpl.ActionItem) list.getSelectedValue()).getText());
}
use of com.intellij.ui.popup.list.ListPopupModel in project android by JetBrains.
the class GuiTests method clickPopupMenuItemMatching.
public static void clickPopupMenuItemMatching(@NotNull Predicate<String> predicate, @NotNull Component component, @NotNull Robot robot) {
// IntelliJ doesn't seem to use a normal JPopupMenu, so this won't work:
// JPopupMenu menu = myRobot.findActivePopupMenu();
// Instead, it uses a JList (technically a JBList), which is placed somewhere
// under the root pane.
Container root = GuiQuery.getNonNull(() -> (Container) SwingUtilities.getRoot(component));
// First find the JBList which holds the popup. There could be other JBLists in the hierarchy,
// so limit it to one that is actually used as a popup, as identified by its model being a ListPopupModel:
JBList list = robot.finder().find(root, new GenericTypeMatcher<JBList>(JBList.class) {
@Override
protected boolean isMatching(@NotNull JBList list) {
ListModel model = list.getModel();
return model instanceof ListPopupModel;
}
});
// We can't use the normal JListFixture method to click by label since the ListModel items are
// ActionItems whose toString does not reflect the text, so search through the model items instead:
ListPopupModel model = (ListPopupModel) list.getModel();
java.util.List<String> items = Lists.newArrayList();
for (int i = 0; i < model.getSize(); i++) {
Object elementAt = model.getElementAt(i);
String s;
if (elementAt instanceof PopupFactoryImpl.ActionItem) {
s = ((PopupFactoryImpl.ActionItem) elementAt).getText();
} else {
// For example package private class IntentionActionWithTextCaching used in quickfix popups
s = elementAt.toString();
}
if (predicate.test(s)) {
new JListFixture(robot, list).clickItem(i);
robot.waitForIdle();
return;
}
items.add(s);
}
if (items.isEmpty()) {
fail("Could not find any menu items in popup");
}
fail("Did not find the correct menu item among " + on(", ").join(items));
}
Aggregations