Class TableSearchable

java.lang.Object
org.jdesktop.swingx.search.AbstractSearchable
org.jdesktop.swingx.search.TableSearchable
All Implemented Interfaces:
Searchable

public class TableSearchable extends AbstractSearchable
An Searchable implementation for use in JXTable.
Author:
Jeanette Winzenburg, EUG https://github.com/homebeaver (use in JXTreeTable)
  • Field Details

    • table

      protected JXTable table
      The target JXTable.
  • Constructor Details

    • TableSearchable

      public TableSearchable(JXTable table)
      Instantiates a TableSearchable with the given table as target.
      Parameters:
      table - the JXTable to search.
  • Method Details

    • findMatchAndUpdateState

      protected void findMatchAndUpdateState(Pattern pattern, int startRow, boolean backwards)
      Loops through the searchable until a match is found or the end is reached. Updates internal search state.

      This implementation loops through the cells in a row to find a match.

      Specified by:
      findMatchAndUpdateState in class AbstractSearchable
      Parameters:
      pattern - Pattern that we will try to locate
      startRow - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
      backwards - true if we should perform search towards the beginning
    • findExtendedMatch

      protected AbstractSearchable.SearchResult findExtendedMatch(Pattern pattern, int row)
      Matches the cell at row/lastFoundColumn against the pattern. Called if sameRowIndex && !hasEqualRegEx. PRE: lastFoundColumn valid.

      Implemented to search for an extension in the cell given by row and foundColumn.

      Specified by:
      findExtendedMatch in class AbstractSearchable
      Parameters:
      pattern - Pattern that we will try to match
      row - position at which we will get the value to match with the provided Pattern
      Returns:
      result of the match; AbstractSearchable.SearchResult
    • findMatchAt

      protected AbstractSearchable.SearchResult findMatchAt(Pattern pattern, int row, int column)
      Matches the cell content at row/col against the given Pattern. Returns an appropriate SearchResult if matching or null if no matching
      Parameters:
      pattern - Pattern that we will try to locate
      row - a valid row index in view coordinates
      column - a valid column index in view coordinates
      Returns:
      an appropriate SearchResult if matching or null
    • adjustStartPosition

      protected int adjustStartPosition(int startIndex, boolean backwards)
      Called if startIndex is different from last search and make sure a backwards/forwards search starts at last/first row, respectively.

      Overridden to adjust the column index to -1.

      Overrides:
      adjustStartPosition in class AbstractSearchable
      Parameters:
      startIndex - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
      backwards - true if we should perform search from towards the beginning
      Returns:
      adjusted startIndex
    • moveStartPosition

      protected int moveStartPosition(int startRow, boolean backwards)
      Moves the internal start position for matching as appropriate and returns the new startIndex to use. Called if search was messaged with the same startIndex as previously.

      This implementation returns a by 1 decremented/incremented startIndex depending on backwards true/false, respectively.

      Overridden to loop through all columns in a row.

      Overrides:
      moveStartPosition in class AbstractSearchable
      Parameters:
      startRow - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
      backwards - true if we should perform search towards the beginning
      Returns:
      adjusted startIndex
    • isEqualStartIndex

      protected boolean isEqualStartIndex(int startIndex)
      Checks if the startIndex should be considered as the same as in the previous search.

      Overridden to check the column index of last find.

      Overrides:
      isEqualStartIndex in class AbstractSearchable
      Parameters:
      startIndex - startIndex that we will compare with the index stored by the previous search request
      Returns:
      true if the startIndex should be re-matched, false if not.
    • getSize

      protected int getSize()
      Returns the size of this searchable.
      Specified by:
      getSize in class AbstractSearchable
      Returns:
      size of this searchable
    • getTarget

      public JXTable getTarget()
      It's the responsibility of subclasses to covariant override.
      Specified by:
      getTarget in class AbstractSearchable
      Returns:
      the target component
    • moveMatchByHighlighter

      protected void moveMatchByHighlighter()
      Configures the match highlighter to the current match. Ensures that the matched cell is visible, if there is a match. PRE: markByHighlighter
    • convertColumnIndexToModel

      protected int convertColumnIndexToModel(int viewColumn)
      Converts and returns the given column index from view coordinates to model coordinates.

      This implementation returns the view coordinate, that is assumes that both coordinate systems are the same.

      Overridden to convert the column index in the table's view coordinate system to model coordinate.

      PENDING JW: this is only necessary because the SearchPredicate wants its highlight column in model coordinates. But code comments in the SearchPredicate seem to indicate that we probably want to revise that (legacy?).

      Overrides:
      convertColumnIndexToModel in class AbstractSearchable
      Parameters:
      viewColumn - the column index in view coordinates, must be a valid index in that system.
      Returns:
      the column index in model coordinates.
    • moveMatchBySelection

      protected void moveMatchBySelection()
      Moves the row selection to the matching cell and ensures its visibility, if any. Does nothing if there is no match.
    • moveMatchMarker

      protected void moveMatchMarker()
      Moves the match marker according to current found state.

      Specified by:
      moveMatchMarker in class AbstractSearchable
    • removeHighlighter

      protected void removeHighlighter(Highlighter searchHighlighter)
      Removes the highlighter.

      Specified by:
      removeHighlighter in class AbstractSearchable
      Parameters:
      searchHighlighter - the Highlighter to remove.
    • getHighlighters

      protected Highlighter[] getHighlighters()
      Returns the highlighters registered on the search target.

      Specified by:
      getHighlighters in class AbstractSearchable
      Returns:
      all registered highlighters
    • addHighlighter

      protected void addHighlighter(Highlighter highlighter)
      Adds the highlighter to the target.

      Specified by:
      addHighlighter in class AbstractSearchable
      Parameters:
      highlighter - the Highlighter to add.