Java Code Examples for com.intellij.ui.components.JBList#getSelectedIndex()

The following examples show how to use com.intellij.ui.components.JBList#getSelectedIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentLocationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void removePlaces(@Nonnull Project project,
                                 @Nonnull ListWithFilter<RecentLocationItem> listWithFilter,
                                 @Nonnull JBList<RecentLocationItem> list,
                                 @Nonnull RecentLocationsDataModel data,
                                 boolean showChanged) {
  List<RecentLocationItem> selectedValue = list.getSelectedValuesList();
  if (selectedValue.isEmpty()) {
    return;
  }

  int index = list.getSelectedIndex();

  IdeDocumentHistory ideDocumentHistory = IdeDocumentHistory.getInstance(project);
  for (RecentLocationItem item : selectedValue) {
    if (showChanged) {
      ContainerUtil.filter(ideDocumentHistory.getChangePlaces(), info -> IdeDocumentHistoryImpl.isSame(info, item.getInfo())).forEach(info -> ideDocumentHistory.removeChangePlace(info));
    }
    else {
      ContainerUtil.filter(ideDocumentHistory.getBackPlaces(), info -> IdeDocumentHistoryImpl.isSame(info, item.getInfo())).forEach(info -> ideDocumentHistory.removeBackPlace(info));
    }
  }

  updateModel(listWithFilter, data, showChanged);

  if (list.getModel().getSize() > 0) ScrollingUtil.selectItem(list, index < list.getModel().getSize() ? index : index - 1);
}
 
Example 2
Source File: RunAnythingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void jumpNextGroup(boolean forward, JBList list) {
  final int index = list.getSelectedIndex();
  final RunAnythingSearchListModel model = getSearchingModel(list);
  if (model != null && index >= 0) {
    final int newIndex = forward ? model.next(index) : model.prev(index);
    list.setSelectedIndex(newIndex);
    int more = model.next(newIndex) - 1;
    if (more < newIndex) {
      more = list.getItemsCount() - 1;
    }
    ScrollingUtil.ensureIndexIsVisible(list, more, forward ? 1 : -1);
    ScrollingUtil.ensureIndexIsVisible(list, newIndex, forward ? 1 : -1);
  }
}
 
Example 3
Source File: NavBarPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void putInfo(@Nonnull Map<String, String> info) {
  StringBuilder result = new StringBuilder();
  for (int i = 0; i < myList.size(); i++) {
    NavBarItem each = myList.get(i);
    if (each.isSelected()) {
      result.append("[").append(each.getText()).append("]");
    }
    else {
      result.append(each.getText());
    }
    if (i < myList.size() - 1) {
      result.append(">");
    }
  }
  info.put("navBar", result.toString());

  if (isNodePopupActive()) {
    StringBuilder popupText = new StringBuilder();
    JBList list = myNodePopup.getList();
    for (int i = 0; i < list.getModel().getSize(); i++) {
      Object eachElement = list.getModel().getElementAt(i);
      String text = new NavBarItem(this, eachElement, myNodePopup, true).getText();
      int selectedIndex = list.getSelectedIndex();
      if (selectedIndex != -1 && eachElement.equals(list.getSelectedValue())) {
        popupText.append("[").append(text).append("]");
      }
      else {
        popupText.append(text);
      }
      if (i < list.getModel().getSize() - 1) {
        popupText.append(">");
      }
    }
    info.put("navBarPopup", popupText.toString());
  }
}
 
Example 4
Source File: ChooseOneOrAllRunnable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  if (myClasses.length == 1) {
    //TODO: cdr this place should produce at least warning
    // selected(myClasses[0]);
    selected((T[])ArrayUtil.toObjectArray(myClasses[0].getClass(), myClasses[0]));
  }
  else if (myClasses.length > 0) {
    PsiElementListCellRenderer<T> renderer = createRenderer();

    Arrays.sort(myClasses, renderer.getComparator());

    if (ApplicationManager.getApplication().isUnitTestMode()) {
      selected(myClasses);
      return;
    }
    Vector<Object> model = new Vector<Object>(Arrays.asList(myClasses));
    model.insertElementAt(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"), 0);

    myList = new JBList(model);
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(renderer);

    final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
    renderer.installSpeedSearch(builder);

    final Runnable callback = new Runnable() {
      @Override
      public void run() {
        int idx = myList.getSelectedIndex();
        if (idx < 0) return;
        if (idx > 0) {
          selected((T[])ArrayUtil.toObjectArray(myClasses[idx-1].getClass(), myClasses[idx-1]));
        }
        else {
          selected(myClasses);
        }
      }
    };

    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        builder.
          setTitle(myTitle).
          setItemChoosenCallback(callback).
          createPopup().
          showInBestPositionFor(myEditor);
      }
    });
  }
}