Пример #1
0
  /**
   * Filters the list from "unfilteredList" based on the entered string and set the resultant list
   * to the combobox.
   *
   * @param newval
   */
  protected void filterBasedOnString(String newval) {
    if (newval == null || newval.equals("")) {
      super.getItems().setAll(unfilteredList);
    } else {
      int caretPosition = super.getEditor().getCaretPosition();
      super.getItems().clear();
      for (T item : unfilteredList) {
        String str = "";
        if (getConverter() == null) {
          str = item.toString().toLowerCase();
        } else {
          str = getConverter().toString(item).toLowerCase();
        }

        boolean containsParts = true;
        final String[] splitted = newval.toLowerCase().split("\\s+");
        for (final String splitPart : splitted) {
          if (!splitPart.isEmpty() && !str.contains(splitPart)) {
            containsParts = false;
          }
        }
        if (containsParts) {
          super.getItems().add(item);
        }
      }
      // if a value was selected and then removed the string is cleared which shouldn't happen
      super.getEditor().setText(newval);
      super.getEditor().positionCaret(caretPosition);
    }
  }
Пример #2
0
 /**
  * setting items to combobox the method is renamed from setItems() to setRecords() as setItems()
  * method is a final method in ComboBox class, so can not override it.
  *
  * @param list
  */
 public void setRecords(List<T> list) {
   unfilteredList.clear();
   unfilteredList.addAll(list);
   super.getItems().setAll(list);
 }