Class Table


  • public class Table
    extends Element
    Type-safe fluent API for creating HTML tables from data inputs.

    Usage examples:

     Table table = new Table();
    
     (Populating a table with individual cell data)
     table
         .withCellClasses("cellClass")
         .row().header()
             .cell("Header A").withClass("abc")
             .cell("Header B")
         .row()
             .cell(val1)
             .cell(val2)
         .row()
             .cell(val3)
             .cell(val4);
    
     (Populating a table with list data)
     table
         .row(headers).header()
         .row(list1).withClass("firstRowClass")
         .row(list2);
    
     (Populating a table with lists of lists)
     List rowData = List.of(row1, row2, row3);
     table
         .row(headers).header()
         .rows(rowData);
    
    • Constructor Detail

      • Table

        public Table()
        Constructs a new table
      • Table

        public Table​(List<Object> rows,
                     CellOption... options)
              throws sailpoint.tools.GeneralException
        Creates a new Table and populates it with the given row data and options
        Parameters:
        rows - The row data to add
        options - The cell options
        Throws:
        sailpoint.tools.GeneralException - on failures applying the cell options
    • Method Detail

      • cell

        public Table cell​(Object value,
                          CellOption... options)
                   throws sailpoint.tools.GeneralException
        Adds a new cell to the current row with the given value content
        Parameters:
        value - The value to add
        Throws:
        sailpoint.tools.GeneralException
      • cell

        public Table cell​(Cell cell)
                   throws sailpoint.tools.GeneralException
        Adds a specified cell to the current row.

        The cell will be modified to add the ‘withCellClasses’ classes, if any have been specified.

        Parameters:
        cell - The cell to add
        Throws:
        sailpoint.tools.GeneralException
      • header

        public Table header()
        Sets the current row or cell to be a header.

        If the current object is a row, all cells in that row will be header cells.

      • header

        public Table header​(List<Object> values)
                     throws sailpoint.tools.GeneralException
        Creates a new header row and populates it with the given cell values
        Parameters:
        values - The values to add
        Throws:
        sailpoint.tools.GeneralException
      • htmlCell

        public Table htmlCell​(Object value)
                       throws sailpoint.tools.GeneralException
        Adds a new HTML cell to the current row
        Parameters:
        value - The HTML contents
        Throws:
        sailpoint.tools.GeneralException
      • render

        public String render()
        Renders the table as HTML
        Returns:
        The rendered HTML
      • row

        public Table row()
        Starts a new row in the table
      • row

        public Table row​(List<Object> values,
                         CellOption... options)
                  throws sailpoint.tools.GeneralException
        Creates a new (non-header) row and populates it with the given cell values.

        This will NOT put the builder into cell mode, so all style/class operators will apply to the row.

        If the value is a Cell object obtained via Cell.of(Object, CellOption...), it will be inserted as-is. Otherwise, the provided CellOptions will be applied to each cell as it is added.

        Parameters:
        values - The values to add
        options - Any cell options you wish to add to each cell
        Throws:
        sailpoint.tools.GeneralException
      • rows

        public Table rows​(List<Object> rowData,
                          CellOption... cellOptions)
                   throws sailpoint.tools.GeneralException
        Accepts a set of row data and adds it to the output table.

        The input should be a list of lists. Each item will be interpreted as input to row(List, CellOption...). All non-list inputs will be quietly ignored.

        The current row and cell will remain blank afterwards, so you cannot use builder syntax to modify the most recent cell or row.

        Parameters:
        rowData - The row data
        Throws:
        sailpoint.tools.GeneralException
      • setColumnCellOptions

        public Table setColumnCellOptions​(int column,
                                          CellOption... options)
                                   throws sailpoint.tools.GeneralException
        To be used after populating the table: applies the given CellOption modifications to the cells at the given column index in each row.

        If a given row does not have enough cells, nothing will happen for that row.

        Parameters:
        column - The column index
        options - The cell options to apply
        Throws:
        sailpoint.tools.GeneralException
      • setColumnStyle

        public Table setColumnStyle​(int column,
                                    String style)
        To be used after populating the table: sets the given style to the cells at the given column in each row.
        Parameters:
        column - The column index
        style - The style
      • setExtraColumnStyle

        public Table setExtraColumnStyle​(int column,
                                         String style)
        To be used after populating the table: appends the given style to the cells at the given column in each row.
        Parameters:
        column - The column index
        style - The style
      • setRowCellOptions

        public Table setRowCellOptions​(int row,
                                       CellOption... options)
                                throws sailpoint.tools.GeneralException
        To be used after populating the table: sets the given style to the given row, indexed starting from zero, including the header row.
        Parameters:
        row - The row index
        options - The options to apply to each cell in this row
        Throws:
        sailpoint.tools.GeneralException
      • setRowStyle

        public Table setRowStyle​(int row,
                                 String style)
        To be used after populating the table: sets the given style to the given row, indexed starting from zero, including the header row.
        Parameters:
        row - The row index
        style - The style
      • width

        public Table width​(int value)
        Sets the table width to the given value, in percent
        Parameters:
        value - The percentage
      • withCellClasses

        public Table withCellClasses​(String... classes)
        All future cells will have the given classes appended.

        Note that cells already in the table will not have the classes added. You should call this method before adding any cells.

      • withCellOptions

        public Table withCellOptions​(List<CellOption> options)
                              throws sailpoint.tools.GeneralException
        Applies the given set of cell options to the current object.

        If applied to a row, it will apply the options to all cells currently in the row and all cells added to the row in the future.

        If applied to a cell, it apply only to that cell.

        If applied to the table, it will apply to all cells in any row.

        Parameters:
        options - The options to apply to each relevant cell
        Throws:
        sailpoint.tools.GeneralException
      • withCellOptions

        public Table withCellOptions​(CellOption... options)
                              throws sailpoint.tools.GeneralException
        Applies the given set of cell options to either the current cell or the current row.

        If applied to a row, it will apply the options to all cells currently in the row and all cells added to the row in the future.

        Parameters:
        options - The options to apply to each relevant cell
        Throws:
        sailpoint.tools.GeneralException
      • withClass

        public Table withClass​(String... cssClasses)
        Adds the given CSS class to the current object
        Parameters:
        cssClasses - The CSS class (or space-separated classes)
      • withHeaderRow

        public Table withHeaderRow​(CellOption... options)
                            throws sailpoint.tools.GeneralException
        Resets the first row to be a header row, which will have its header flag set and any given options applied to all cells in the row.
        Parameters:
        options - An optional list of CellOptions to apply to each cell in the row
        Throws:
        sailpoint.tools.GeneralException - On any failures applying the CellOptions
      • withStyle

        public Table withStyle​(String style)
        Sets the style of the current item to the given value.

        If the current item is not a row or cell, silently does nothing.

        Parameters:
        style - The style