Class SearchHistoryListView

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class SearchHistoryListView extends JList<String>
A reusable list view component for displaying search history entries with grouped time periods and custom styling. This component provides a popup-style interface for selecting previous search queries.

Features:

  • Groups entries by time periods (Today, This week, This month, > 30 days)
  • Custom cell renderer with header styling
  • Prevents selection of group headers
  • Configurable selection callback
  • Automatic sizing based on content

Usage example:

 SearchHistoryListView historyView = new SearchHistoryListView("search.session");
 historyView.setSelectionCallback(entry -> {
     searchField.setText(entry.queryText());
     // Apply other search parameters...
 });
 
 JPopupMenu popup = new JPopupMenu();
 popup.add(historyView.createScrollPane());
 popup.show(component, x, y);
 
See Also:
  • Constructor Details

    • SearchHistoryListView

      public SearchHistoryListView(String historyPrefix)
      Creates a new SearchHistoryListView with the specified history prefix and default maximum entries.
      Parameters:
      historyPrefix - the prefix for the search history context
    • SearchHistoryListView

      public SearchHistoryListView(String historyPrefix, int maxHistoryEntries)
      Creates a new SearchHistoryListView with the specified history prefix and maximum entries.
      Parameters:
      historyPrefix - the prefix for the search history context
      maxHistoryEntries - maximum number of history entries to display
  • Method Details

    • setSelectionCallback

      public void setSelectionCallback(Consumer<SearchHistoryEntry> selectionCallback)
      Sets the callback to be invoked when a history entry is selected.
      Parameters:
      selectionCallback - the callback to invoke with the selected entry
    • refresh

      public void refresh()
      Refreshes the history entries from storage and updates the display.
    • createScrollPane

      public JScrollPane createScrollPane()
      Creates a JScrollPane containing this list view with appropriate sizing.
      Returns:
      a configured JScrollPane containing this list