private static void selectItemByText(@NotNull final JList list, @NotNull final String text) { 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()); }
private void registerActions(final ListPopupImpl popup) { popup.registerAction("delete", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { JList list = popup.getList(); int selectedIndex = list.getSelectedIndex(); ListPopupModel model = (ListPopupModel) list.getModel(); PopupFactoryImpl.ActionItem selectedItem = (PopupFactoryImpl.ActionItem) model.get(selectedIndex); if (selectedItem != null && selectedItem.getAction() instanceof RunGoalAction) { RunGoalAction action = (RunGoalAction) selectedItem.getAction(); boolean deleted = ApplicationComponent.getInstance().getState().removeGoal(action.getGoal()); if (deleted) { model.deleteItem(selectedItem); if (selectedIndex == list.getModel().getSize()) { // is last list.setSelectedIndex(selectedIndex - 1); } else { list.setSelectedIndex(selectedIndex); } } } } }); }
/** Waits until an IDE popup is shown (and returns it */ public static JBList waitForPopup(@NotNull Robot robot) { return waitUntilFound(robot, null, new GenericTypeMatcher<JBList>(JBList.class) { @Override protected boolean isMatching(@NotNull JBList list) { ListModel model = list.getModel(); return model instanceof ListPopupModel; } }); }
@Nonnull 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; }