Java 类com.intellij.ui.popup.list.ListPopupModel 实例源码

项目:intellij-ce-playground    文件:ComboBoxActionFixture.java   
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());
}
项目:MavenHelper    文件:QuickRunMavenGoalAction.java   
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);
                    }
                }
            }
        }
    });
}
项目:intellij-ce-playground    文件:GuiTests.java   
/** 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;
    }
  });
}
项目:consulo    文件:BranchActionGroupPopup.java   
@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;
}