/** * 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); } }
/** Clears all the items in the combobox. */ public void clearItems() { unfilteredList.clear(); super.getItems().clear(); }
/** Clears the selection of the combobox. */ public void clearSelection() { super.getSelectionModel().clearSelection(); super.getEditor().setText(""); super.getEditor().clear(); }