protected void onSpeedSearchPatternChanged() { myListModel.refilter(); if (myListModel.getSize() > 0) { if (!autoSelectUsingStatistics()) { int fullMatchIndex = myListModel.getClosestMatchIndex(); if (fullMatchIndex != -1) { myList.setSelectedIndex(fullMatchIndex); } if (myListModel.getSize() <= myList.getSelectedIndex() || !myListModel.isVisible(myList.getSelectedValue())) { myList.setSelectedIndex(0); } } } }
private boolean autoSelectUsingStatistics() { final String filter = getSpeedSearch().getFilter(); if (!StringUtil.isEmpty(filter)) { int maxUseCount = -1; int mostUsedValue = -1; int elementsCount = myListModel.getSize(); for (int i = 0; i < elementsCount; i++) { Object value = myListModel.getElementAt(i); final String text = getListStep().getTextFor(value); final int count = StatisticsManager.getInstance() .getUseCount( new StatisticsInfo("#list_popup:" + myStep.getTitle() + "#" + filter, text)); if (count > maxUseCount) { maxUseCount = count; mostUsedValue = i; } } if (mostUsedValue > 0) { ListScrollingUtil.selectItem(myList, mostUsedValue); return true; } } return false; }
private void selectFirstSelectableItem() { for (int i = 0; i < myListModel.getSize(); i++) { if (getListStep().isSelectable(myListModel.getElementAt(i))) { myList.setSelectedIndex(i); break; } } }
private int getSelectableCount() { int count = 0; for (int i = 0; i < myListModel.getSize(); i++) { final Object each = myListModel.getElementAt(i); if (getListStep().isSelectable(each)) { count++; } } return count; }
protected boolean beforeShow() { myList.addMouseMotionListener(myMouseMotionListener); myList.addMouseListener(myMouseListener); myList.setVisibleRowCount(Math.min(myMaxRowCount, myListModel.getSize())); boolean shouldShow = super.beforeShow(); if (myAutoHandleBeforeShow) { final boolean toDispose = tryToAutoSelect(true); shouldShow &= !toDispose; } return shouldShow; }
private boolean hasSingleSelectableItemWithSubmenu() { boolean oneSubmenuFound = false; int countSelectables = 0; for (int i = 0; i < myListModel.getSize(); i++) { Object elementAt = myListModel.getElementAt(i); if (getListStep().isSelectable(elementAt)) { countSelectables++; if (getStep().hasSubstep(elementAt)) { if (oneSubmenuFound) { return false; } oneSubmenuFound = true; } } } return oneSubmenuFound && countSelectables == 1; }
private boolean _handleSelect(final boolean handleFinalChoices, InputEvent e) { if (myList.getSelectedIndex() == -1) return false; if (getSpeedSearch().isHoldingFilter() && myList.getModel().getSize() == 0) return false; if (myList.getSelectedIndex() == getIndexForShowingChild()) { if (myChild != null && !myChild.isVisible()) setIndexForShowingChild(-1); return false; } final Object[] selectedValues = myList.getSelectedValues(); final ListPopupStep<Object> listStep = getListStep(); if (!listStep.isSelectable(selectedValues[0])) return false; if ((listStep instanceof MultiSelectionListPopupStep<?> && !((MultiSelectionListPopupStep<Object>) listStep) .hasSubstep(Arrays.asList(selectedValues)) || !listStep.hasSubstep(selectedValues[0])) && !handleFinalChoices) return false; disposeChildren(); if (myListModel.getSize() == 0) { setFinalRunnable(myStep.getFinalRunnable()); setOk(true); disposeAllParents(e); setIndexForShowingChild(-1); return true; } valuesSelected(selectedValues); final PopupStep nextStep = listStep instanceof MultiSelectionListPopupStep<?> ? ((MultiSelectionListPopupStep<Object>) listStep) .onChosen(Arrays.asList(selectedValues), handleFinalChoices) : listStep.onChosen(selectedValues[0], handleFinalChoices); return handleNextStep(nextStep, selectedValues.length == 1 ? selectedValues[0] : null, e); }