Class SortableAndSearchableTable

    • Constructor Detail

      • SortableAndSearchableTable

        public SortableAndSearchableTable()
        Constructs a default SortedBaseTable that is initialized with a default data model, a default column model, and a default selection model.
      • SortableAndSearchableTable

        public SortableAndSearchableTable​(int numRows,
                                          int numColumns)
        Constructs a SortedBaseTable with numRows and numColumns of empty cells using DefaultTableModel. The columns will have names of the form "A", "B", "C", etc.
        Parameters:
        numRows - the number of rows the table holds
        numColumns - the number of columns the table holds
      • SortableAndSearchableTable

        public SortableAndSearchableTable​(Object[][] rowData,
                                          Object[] columnNames)
        Constructs a SortedBaseTable to display the values in the two dimensional array, rowData, with column names, columnNames. rowData is an array of rows, so the value of the cell at row 1, column 5 can be obtained with the following code:

         rowData[1][5]; 

        All rows must be of the same length as columnNames.

        Parameters:
        rowData - the data for the new table
        columnNames - names of each column
      • SortableAndSearchableTable

        public SortableAndSearchableTable​(Vector rowData,
                                          Vector columnNames)
        Constructs a SortedBaseTable to display the values in the Vector of Vectors, rowData, with column names, columnNames. The Vectors contained in rowData should contain the values for that row. In other words, the value of the cell at row 1, column 5 can be obtained with the following code:

        ((Vector)rowData.elementAt(1)).elementAt(5);

        Parameters:
        rowData - the data for the new table
        columnNames - names of each column
      • SortableAndSearchableTable

        public SortableAndSearchableTable​(TableModel dm)
        Constructs a SortedBaseTable that is initialized with dm as the data model, a default column model, and a default selection model.
        Parameters:
        dm - the data model for the table
      • SortableAndSearchableTable

        public SortableAndSearchableTable​(TableModel dm,
                                          TableColumnModel cm)
        Constructs a SortedBaseTable that is initialized with dm as the data model, cm as the column model, and a default selection model.
        Parameters:
        dm - the data model for the table
        cm - the column model for the table
      • SortableAndSearchableTable

        public SortableAndSearchableTable​(TableModel dm,
                                          TableColumnModel cm,
                                          ListSelectionModel sm)
        Constructs a SortedBaseTable that is initialized with dm as the data model, cm as the column model, and sm as the selection model. If any of the parameters are null this method will initialize the table with the corresponding default model. The autoCreateColumnsFromModel flag is set to false if cm is non-null, otherwise it is set to true and the column model is populated with suitable TableColumns for the columns in dm.
        Parameters:
        dm - the data model for the table
        cm - the column model for the table
        sm - the row selection model for the table
    • Method Detail

      • initialSortNewTableModel

        protected boolean initialSortNewTableModel()
        Returns the initial setting of whether to sort new models. Default implementation returns "false".
        Returns:
        true if new models need to be sorted
      • initialSortCaseSensitive

        protected boolean initialSortCaseSensitive()
        Returns whether the initial sort is case-sensitive.
        Returns:
        true if case-sensitive
      • setSortNewTableModel

        public void setSortNewTableModel​(boolean value)
        Sets whether to sort new models.
        Parameters:
        value - if true then new models get sorted
      • getSortNewTableModel

        public boolean getSortNewTableModel()
        Returns whether to sort new models. Default implementation is initialized with "false".
        Returns:
        true if new models get sorted
      • initGUI

        protected void initGUI()
        Initializes some GUI-related things.
        Overrides:
        initGUI in class BaseTable
      • finishInit

        protected void finishInit()
        Finishes the initialization.
        Overrides:
        finishInit in class BaseTable
      • getTableModelClass

        protected Class getTableModelClass()
        Returns the class of the table model that the models need to be derived from. The default implementation just returns TableModel.class
        Returns:
        the class the models must be derived from
      • backupModelSettings

        protected Hashtable<String,​Object> backupModelSettings​(TableModel model)
        Backs up the settings from the old model.
        Parameters:
        model - the old model (the model stored within the SortedModel)
        Returns:
        the backed up settings
      • restoreModelSettings

        protected void restoreModelSettings​(TableModel model,
                                            Hashtable<String,​Object> settings)
        Restores the settings previously backed up.
        Parameters:
        model - the new model (the model stored within the SortedModel)
        settings - the old settings, null if no settings were available
      • setUnsortedModel

        public void setUnsortedModel​(TableModel value)
        Sets the base model to use. Discards any sorting.
        Specified by:
        setUnsortedModel in interface SortableTable
        Parameters:
        value - the base model
      • setUnsortedModel

        public void setUnsortedModel​(TableModel value,
                                     boolean restoreSorting)
        Sets the base model to use.
        Parameters:
        value - the base model
        restoreSorting - whether to restore the sorting
      • getActualRow

        public int getActualRow​(int visibleRow)
        Returns the actual underlying row the given visible one represents. Useful for retrieving "non-visual" data that is also stored in a TableModel.
        Specified by:
        getActualRow in interface SearchableTable
        Parameters:
        visibleRow - the displayed row to retrieve the original row for
        Returns:
        the original row
      • getDisplayRow

        public int getDisplayRow​(int internalRow)
        Returns the "visible" row derived from row in the actual table model.
        Parameters:
        internalRow - the row in the actual model
        Returns:
        the row in the sorted model, -1 in case of an error
      • isSorted

        public boolean isSorted()
        returns whether the table was sorted.
        Specified by:
        isSorted in interface SortableTable
        Returns:
        true if the table was sorted
      • getSortColumn

        public int getSortColumn()
        Returns the sort column.
        Specified by:
        getSortColumn in interface SortableTable
        Returns:
        the sort column
      • setCaseSensitive

        public void setCaseSensitive​(boolean value)
        Sets whether the sorting is case-sensitive.
        Parameters:
        value - true if case-sensitive
      • isCaseSensitive

        public boolean isCaseSensitive()
        Returns whether the sorting is case-sensitive.
        Returns:
        true if case-sensitive
      • sort

        public void sort​(int columnIndex)
        sorts the table over the given column (ascending).
        Specified by:
        sort in interface SortableTable
        Parameters:
        columnIndex - the column to sort over
      • sort

        public void sort​(int columnIndex,
                         boolean ascending)
        sorts the table over the given column, either ascending or descending.
        Specified by:
        sort in interface SortableTable
        Parameters:
        columnIndex - the column to sort over
        ascending - ascending if true, otherwise descending
      • getActualRowCount

        public int getActualRowCount()
        Returns the actual row count in the model.
        Specified by:
        getActualRowCount in interface SearchableTable
        Returns:
        the row count in the underlying data
      • search

        public void search​(String searchString,
                           boolean regexp)
        Performs a search for the given string. Limits the display of rows to ones containing the search string.
        Specified by:
        search in interface SearchableTable
        Parameters:
        searchString - the string to search for
        regexp - whether to perform regular expression matching or just plain string comparison
      • getSeachString

        public String getSeachString()
        Returns the current search string.
        Specified by:
        getSeachString in interface SearchableTable
        Returns:
        the search string, null if not filtered
      • isRegExpSearch

        public boolean isRegExpSearch()
        Returns whether the last search was a regular expression based one.
        Specified by:
        isRegExpSearch in interface SearchableTable
        Returns:
        true if last search was a reg exp one
      • setColumnFilter

        public void setColumnFilter​(int column,
                                    String filter,
                                    boolean isRegExp)
        Sets the filter for the column.
        Specified by:
        setColumnFilter in interface TableWithColumnFilters
        Parameters:
        column - the column to filter
        filter - the filter string
        isRegExp - whether the filter is a regular expression
      • getColumnFilter

        public String getColumnFilter​(int column)
        Returns the filter for the column.
        Specified by:
        getColumnFilter in interface TableWithColumnFilters
        Parameters:
        column - the column to query
        Returns:
        the filter, null if none present
      • isColumnFilterRegExp

        public boolean isColumnFilterRegExp​(int column)
        Returns the whether the filter for the column is a regular expression.
        Specified by:
        isColumnFilterRegExp in interface TableWithColumnFilters
        Parameters:
        column - the column to query
        Returns:
        true if filter set and regular expression
      • isColumnFiltered

        public boolean isColumnFiltered​(int column)
        Returns the whether there is a filter active for the column.
        Specified by:
        isColumnFiltered in interface TableWithColumnFilters
        Parameters:
        column - the column to query
        Returns:
        true if a filter is active
      • isAnyColumnFiltered

        public boolean isAnyColumnFiltered()
        Returns whether there is at least one filter active.
        Specified by:
        isAnyColumnFiltered in interface TableWithColumnFilters
        Returns:
        true if at least one filter is active
      • removeColumnFilter

        public void removeColumnFilter​(int column)
        Removes any filter for the column.
        Specified by:
        removeColumnFilter in interface TableWithColumnFilters
        Parameters:
        column - the column to update