Class DataTableManager<T>

  • Type Parameters:
    T - Type of data to display
    All Implemented Interfaces:
    java.io.Serializable

    public class DataTableManager<T>
    extends java.lang.Object
    implements java.io.Serializable
    Class to manage data tables with freemarker macros
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DataTableManager​(java.lang.String strSortUrl, java.lang.String strFilterUrl, int nDefautlItemsPerPage, boolean bEnablePaginator)
      Constructor of the DataTableManager class
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addActionColumn​(java.lang.String strColumnTitle)
      Add an column to this DataTableManager that will display actions on items.
      void addBooleanColumn​(java.lang.String strColumnTitle, java.lang.String strObjectName, java.lang.String strLabelTrue, java.lang.String strLabelFalse)
      Add a column to this DataTableManager
      void addColumn​(java.lang.String strColumnTitle, java.lang.String strObjectName, boolean bSortable)
      Add a column to this DataTableManager
      void addDropDownListFilter​(java.lang.String strParameterName, java.lang.String strFilterLabel, ReferenceList refList)
      Add a drop down list filter to the filter panel of this DataTableManager
      void addEmailColumn​(java.lang.String strColumnTitle, java.lang.String strObjectName, boolean bSortable)
      Add an email column to this DataTableManager.
      void addFilter​(DataTableFilterType filterType, java.lang.String strParameterName, java.lang.String strFilterLabel)
      Add a filter to the filter panel of this DataTableManager
      void addFreeColumn​(java.lang.String strColumnTitle, java.lang.String strFreemarkerMacroName)
      Add a free column to this DataTableManager.
      void addLabelColumn​(java.lang.String strColumnTitle, java.lang.String strObjectName, boolean bSortable)
      Add a label column to this DataTableManager.
      void clearItems()
      Clear the items stored by this DataTableManager so that the garbage collector can free the memory they use.
      void filterSortAndPaginate​(javax.servlet.http.HttpServletRequest request, java.util.List<T> items)
      Apply filters on an objects list, sort it and update pagination values.
      <K> K getAndUpdateFilter​(javax.servlet.http.HttpServletRequest request, K filterObject)
      Get filter properties updated with values in the request
      DataTablePaginationProperties getAndUpdatePaginator​(javax.servlet.http.HttpServletRequest request)
      Get the paginator updated with values in the request
      DataTableSort getAndUpdateSort​(javax.servlet.http.HttpServletRequest request)
      Get sort properties updated with values in the request
      boolean getEnablePaginator()
      Get the enable paginator boolean
      FilterPanel getFilterPanel()
      Get the filter panel of the DataTableManager
      java.lang.String getFilterPanelPrefix()
      Internal method.
      java.lang.String getId()
      Get the unique id of this data table manager
      java.util.List<T> getItems()
      Get the filtered, sorted and paginated items collection of this DataTableManager
      java.util.List<DataTableColumn> getListColumn()
      Get the list of columns of this DataTableManager
      java.util.Locale getLocale()
      Get the locale
      IPaginator<T> getPaginator()
      Internal method.
      java.lang.String getSortUrl()
      Get the sort url of this DataTableManager
      void setFilterPanel​(FilterPanel filterPanel)
      Set the filter panel of the DataTableManager
      void setItems​(java.util.List<T> items, int nTotalItemsNumber)
      Set the items to display.
      void setListColumn​(java.util.List<DataTableColumn> listColumn)
      Set the list of columns of this DataTableManager
      void setLocale​(java.util.Locale locale)
      Set the locale
      void setSortUrl​(java.lang.String strSortUrl)
      Set the sort url of this DataTableManager
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DataTableManager

        public DataTableManager​(java.lang.String strSortUrl,
                                java.lang.String strFilterUrl,
                                int nDefautlItemsPerPage,
                                boolean bEnablePaginator)
        Constructor of the DataTableManager class
        Parameters:
        strSortUrl - URL used by the paginator to sort data
        strFilterUrl - URL used to filter data
        nDefautlItemsPerPage - Default number of items to display per page
        bEnablePaginator - True to enable pagination, false to disable it
    • Method Detail

      • addColumn

        public void addColumn​(java.lang.String strColumnTitle,
                              java.lang.String strObjectName,
                              boolean bSortable)
        Add a column to this DataTableManager
        Parameters:
        strColumnTitle - I18n key of the title of the column
        strObjectName - Name of the property of objects that should be displayed in this column.
        For example, if a class "Data" contains a property named "title", then the value of the parameter strObjectName should be "title".
        bSortable - True if the column is sortable, false otherwise
      • addLabelColumn

        public void addLabelColumn​(java.lang.String strColumnTitle,
                                   java.lang.String strObjectName,
                                   boolean bSortable)
        Add a label column to this DataTableManager. Values of cells of this column will be interpreted as i18n keys.
        Parameters:
        strColumnTitle - I18n key of the title of the column
        strObjectName - Name of the property of objects that should be displayed in this column. This properties must be i18n keys.
        For example, if a class "Data" contains a property named "title", then the value of the parameter strObjectName should be "title".
        bSortable - True if the column is sortable, false otherwise
      • addActionColumn

        public void addActionColumn​(java.lang.String strColumnTitle)
        Add an column to this DataTableManager that will display actions on items. Actions are usually parameterized links. A DataTableManager can only have 1 action column. The content of the action column must be generated by a macro.this macro must have one parameter named "item", and its name must be given to the macro @tableData.
        Parameters:
        strColumnTitle - I18n key of the title of the column
      • addBooleanColumn

        public void addBooleanColumn​(java.lang.String strColumnTitle,
                                     java.lang.String strObjectName,
                                     java.lang.String strLabelTrue,
                                     java.lang.String strLabelFalse)
        Add a column to this DataTableManager
        Parameters:
        strColumnTitle - I18n key of the title of the column
        strObjectName - Name of the property of objects that should be displayed in this column.
        For example, if a class "Data" contains a property named "title", then the value of the parameter strObjectName should be "title".
        strLabelTrue - I18n key of the label to display when the value is true
        strLabelFalse - I18n key of the label to display when the value is false
      • addFreeColumn

        public void addFreeColumn​(java.lang.String strColumnTitle,
                                  java.lang.String strFreemarkerMacroName)
        Add a free column to this DataTableManager. The content of this column must be generated by a macro. The macro must have one parameter named "item".
        Parameters:
        strColumnTitle - I18n key of the title of the column
        strFreemarkerMacroName - Name of the freemarker macro that will display the content of the column.
        The macro must have a single parameter named item of type T that will contain the object associated with a row of the table.
      • addEmailColumn

        public void addEmailColumn​(java.lang.String strColumnTitle,
                                   java.lang.String strObjectName,
                                   boolean bSortable)
        Add an email column to this DataTableManager. Displayed cell will be a "mailto:" link.
        Parameters:
        strColumnTitle - I18n key of the title of the column
        strObjectName - Name of the property of objects that should be displayed in this column.
        For example, if a class "Data" contains a property named "title", then the value of the parameter strObjectName should be "title".
        bSortable - True if the column is sortable, false otherwise
      • addFilter

        public void addFilter​(DataTableFilterType filterType,
                              java.lang.String strParameterName,
                              java.lang.String strFilterLabel)
        Add a filter to the filter panel of this DataTableManager
        Parameters:
        filterType - data type of the filter. For drop down list, use addDropDownListFilter instead
        strParameterName - Name of the parameter of the object to filter.
        For example, if this filter should be applied on the parameter "title" of a class named "Data", then the value of the parameter strParameterName should be "title".
        strFilterLabel - Label describing the filter
      • addDropDownListFilter

        public void addDropDownListFilter​(java.lang.String strParameterName,
                                          java.lang.String strFilterLabel,
                                          ReferenceList refList)
        Add a drop down list filter to the filter panel of this DataTableManager
        Parameters:
        strParameterName - Name of the parameter of the object to filter.
        For example, if this filter should be applied on the parameter "title" of a class named "Data", then the value of the parameter strParameterName should be "title".
        strFilterLabel - Label describing the filter
        refList - Reference list containing data of the drop down list
      • filterSortAndPaginate

        public void filterSortAndPaginate​(javax.servlet.http.HttpServletRequest request,
                                          java.util.List<T> items)
        Apply filters on an objects list, sort it and update pagination values.
        Parameters:
        request - The request
        items - Collection of objects to filter, sort and paginate
      • getFilterPanel

        public FilterPanel getFilterPanel()
        Get the filter panel of the DataTableManager
        Returns:
        The filter panel of the DataTableManager
      • setFilterPanel

        public void setFilterPanel​(FilterPanel filterPanel)
        Set the filter panel of the DataTableManager
        Parameters:
        filterPanel - Filter panel
      • getListColumn

        public java.util.List<DataTableColumn> getListColumn()
        Get the list of columns of this DataTableManager
        Returns:
        The list of columns of this DataTableManager
      • setListColumn

        public void setListColumn​(java.util.List<DataTableColumn> listColumn)
        Set the list of columns of this DataTableManager
        Parameters:
        listColumn - The list of columns of this DataTableManager
      • getSortUrl

        public java.lang.String getSortUrl()
        Get the sort url of this DataTableManager
        Returns:
        The sort url of this DataTableManager
      • setSortUrl

        public void setSortUrl​(java.lang.String strSortUrl)
        Set the sort url of this DataTableManager
        Parameters:
        strSortUrl - The sort url of this DataTableManager
      • getItems

        public java.util.List<T> getItems()
        Get the filtered, sorted and paginated items collection of this DataTableManager
        Returns:
        The filtered, sorted and paginated items collection of this DataTableManager
      • setItems

        public void setItems​(java.util.List<T> items,
                             int nTotalItemsNumber)
        Set the items to display. The list of items must be fintered, sorted and paginated. Methods getAndUpdatePaginator, getAndUpdateSort and getAndUpdateFilter must have been called before the generation of the list of items.
        Parameters:
        items - The filtered sorted and paginated list of items to display
        nTotalItemsNumber - The total number of items
      • clearItems

        public void clearItems()
        Clear the items stored by this DataTableManager so that the garbage collector can free the memory they use.
      • getPaginator

        public IPaginator<T> getPaginator()
        Internal method. Get the paginator. Do not use this method, use getAndUpdatePaginator instead to get up to date values !
        Returns:
        The paginator
      • getEnablePaginator

        public boolean getEnablePaginator()
        Get the enable paginator boolean
        Returns:
        True if pagination is active, false otherwise
      • getLocale

        public java.util.Locale getLocale()
        Get the locale
        Returns:
        The locale
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Set the locale
        Parameters:
        locale - The locale
      • getId

        public java.lang.String getId()
        Get the unique id of this data table manager
        Returns:
        The unique id of this data table manager
      • getAndUpdatePaginator

        public DataTablePaginationProperties getAndUpdatePaginator​(javax.servlet.http.HttpServletRequest request)
        Get the paginator updated with values in the request
        Parameters:
        request - The request
        Returns:
        The paginator up to date
      • getAndUpdateSort

        public DataTableSort getAndUpdateSort​(javax.servlet.http.HttpServletRequest request)
        Get sort properties updated with values in the request
        Parameters:
        request - The request
        Returns:
        The sort properties up to date
      • getAndUpdateFilter

        public <K> K getAndUpdateFilter​(javax.servlet.http.HttpServletRequest request,
                                        K filterObject)
        Get filter properties updated with values in the request
        Type Parameters:
        K - Type of the filter to use. This type must have accessors for every declared filter.
        Parameters:
        request - The request
        filterObject - Filter to apply.
        Returns:
        The filter properties up to date
      • getFilterPanelPrefix

        public java.lang.String getFilterPanelPrefix()
        Internal method. Get the prefix of html attributes used by filters
        Returns:
        The prefix of html attributes used by filters