Class NavigationLetterStringConverter<T>

java.lang.Object
javafx.util.StringConverter<T>
org.tentackle.fx.NavigationLetterStringConverter<T>
Type Parameters:
T - the type to convert

public abstract class NavigationLetterStringConverter<T> extends javafx.util.StringConverter<T>
A StringConverter to navigate within a collection of objects.
Provides navigation with keystrokes that do not correspond to the text displayed in the UI.

Example:

   converter = new NavigationLetterStringConverter<SomeType>(someCollection) {
     @Override
     public String getNavigationLetters(SomeType object) {
       return StringHelper.filterUpperCase(object.getName());
     }
     @Override
     public String getName(SomeType object) {
       return object.getName();
     }
   };
   sortedObjects = converter.getSortedObjects();    // for ComboBox.getItems().setAll(sortedObjects)
   comboBox.setConverter(converter);
 
Notice that the ComboBox needs a cell-factory to show the object name, otherwise the navigation-letters will be shown instead of the object's name.

Notice further, that enhanced camelcase navigation is also available via the PrefixSelectionFeature.CAMEL_CASE property, which is usually much simpler and does not need a NavigationLetterStringConverter at all.

  • Constructor Details

    • NavigationLetterStringConverter

      public NavigationLetterStringConverter(Collection<T> objects)
      Creates a converter.
      Parameters:
      objects - the objects to navigate within
  • Method Details

    • getNavigationLetters

      public abstract String getNavigationLetters(T object)
      Extracts the navigation letters from an object.
      Parameters:
      object - the object
      Returns:
      the navigation letters
    • getName

      public abstract String getName(T object)
      Extracts the name from an object.
      Parameters:
      object - the object
      Returns:
      the object's name
    • getSortedObjects

      public Collection<T> getSortedObjects()
      Gets the objects sorted by navigation letters + name.
      Returns:
      the sorted objects
    • toString

      public String toString(T object)
      Specified by:
      toString in class javafx.util.StringConverter<T>
    • fromString

      public T fromString(String string)
      Specified by:
      fromString in class javafx.util.StringConverter<T>