Class ResultMatrix

  • All Implemented Interfaces:
    Serializable, ComplexCalculationResult

    public class ResultMatrix
    extends Object
    implements ComplexCalculationResult, Serializable
    This class is used to transport a calculated matrix-style result It is basically a list of maps with the addition that the column names are clearly named and can have a format This means: - the UI knows exactly which columns to display (even if some maps do not have those as keys) - the entry maps can have more "columns" (or keys) than those that are displayed; maybe useful for calculation
    Author:
    cat
    See Also:
    Serialized Form
    • Constructor Detail

      • ResultMatrix

        public ResultMatrix()
      • ResultMatrix

        public ResultMatrix​(Map jsonMap)
      • ResultMatrix

        public ResultMatrix​(String... columns)
        Creates a new matrix object with an initial set of columns
        Parameters:
        columns - The initial set of column names
      • ResultMatrix

        public ResultMatrix​(Collection<String> columns)
        Creates a new matrix object with an initial set of columns
        Parameters:
        columns - Collection of column names
    • Method Detail

      • getTitle

        public String getTitle()
        Gets the current title
        Returns:
        The current title
      • setTitle

        public void setTitle​(String title)
        Sets the title that will be shown as window title of the result matrix in the client
        Parameters:
        title - The title
      • getPreferenceName

        public String getPreferenceName()
        Gets the preference name
        Returns:
        The preference name
      • isSortingDisabled

        public boolean isSortingDisabled()
        UI sorting of matrix grid
        Returns:
        true if sorting is disabled on all columns. Default is false
      • setDisableSorting

        public void setDisableSorting​(boolean disableSorting)
        Set sorting capability in UI grid
        Parameters:
        disableSorting - true: sorting is disabled in UI on all columns
      • isEscapeHTML

        public boolean isEscapeHTML()
        Is HTML escaping enabled?
        Returns:
        true if the matrix should display raw text as is (i.e. not try to interpret it as HTML)
      • setEscapeHTML

        public void setEscapeHTML​(boolean escapeHTML)
        Set HTML escaping flag. Default: false (i.e. values will be interpreted as HTML)
        Parameters:
        escapeHTML -
      • setPreferenceName

        public void setPreferenceName​(String preferenceName)
        Sets the so-called preference name. I.e. all result matrixes with the same preference name will share the same preference setting. The preference setting can be managed as usual in the client and can be set as global to predefine a good setting
        Parameters:
        preferenceName - The preference name
      • addColumnTranslation

        public void addColumnTranslation​(String column,
                                         Map<String,​String> translations)
        Adds translated labels for the given column.
        Parameters:
        column - The column name (as defined e.g. in the constructor)
        translations - A map with the translations. The key of the map is the locale, like "de".
      • getColumnTranslations

        public Map<String,​String> getColumnTranslations()
        Gets current column translations in raw format
        Returns:
      • addColumn

        public void addColumn​(String column)
        Adds a column to the existing set of columns
        Parameters:
        column - The columns name
      • addColumn

        public void addColumn​(String column,
                              String tooltip)
        Adds a column to the existing set of columns including a tooltip
        Parameters:
        column - The columns name
      • addColumns

        public void addColumns​(Collection<String> columns)
        Adds columns to the existing set of columns
        Parameters:
        columns - Collection of columns names
      • addRow

        public void addRow​(Map<String,​Object> row)
        Adds a data row. The keys of the row-map should match the column names defined earlier
        Parameters:
        row -
      • addRow

        public void addRow​(List<Object> row)
        Adds a data row. The order of the values is assumed to be the same as the matrix column order.
        Parameters:
        row - Row as List
      • addRow

        public void addRow​(Object... values)
        Adds a data row. The order of the values is assumed to be the same as the matrix column order.
        Parameters:
        values - Row as Array
      • getColumns

        public List<String> getColumns()
        Gets a list of defined columns
        Returns:
        The columns
      • getEntries

        public List<Map<String,​Object>> getEntries()
        Returns the current list entries as a list (=the rows) of maps (= the row content)
        Returns:
        List of maps
      • findRow

        public Map<String,​Object> findRow​(String key,
                                                Object value)
        Retrieves a particular row based on a value check
        Parameters:
        key - The column name to search on
        value - The value to match the row's column value to
        Returns:
        The row
      • transpose

        public ResultMatrix transpose​(String newHeaderColumnName)
        Transpose the matrix.

        Example:
         ProductGroup | AvgPrice | AvgMargin <- header row
         -----------------------------------
             Beef     |   4.1€   |   3.6%
             Pork     |   2.2€   |   1.1%
             Lamb     |   4.6€   |   5.2%
         
        Transposed matrix:
         transpose("ProductGroup")
         
         ProductGroup | Beef | Pork | Lamb <- header row
         ---------------------------------
           AvgPrice   | 4.1€ | 2.2€ | 4.6€
           AvgMargin  | 3.6% | 1.1% | 5.2%
         
        Parameters:
        newHeaderColumnName - Name of the column that will become the new header row
        Returns:
        The transposed ResultMatrix (new instance)
      • transpose

        public ResultMatrix transpose​(String newHeaderColumnName,
                                      String oldColLabelsInNewColumnName)
        Transpose the matrix.

        Example:
         ProductGroup | AvgPrice | AvgMargin  <- header row
         ------------------------------------
             Beef     |   4.1€   |   3.6%
             Pork     |   2.2€   |   1.1%
             Lamb     |   4.6€   |   5.2%
         
        Transposed matrix:
         transpose("ProductGroup", "PG Label")
         
          Beef | Pork | Lamb |   PG Label    <- header row
         -----------------------------------
          Beef | Pork | Lamb | ProductGroup
          4.1€ | 2.2€ | 4.6€ |   AvgPrice
          3.6% | 1.1% | 5.2% |   AvgMargin
         
        Parameters:
        newHeaderColumnName - Name of the column that will become the new header row
        oldColLabelsInNewColumnName - Name of the new column that will receive the old column headers as values (optional)
        Returns:
        The transposed ResultMatrix (new instance)
      • toMatrix2D

        public Matrix2D toMatrix2D()
      • setDefaultFormat

        public void setDefaultFormat​(FieldFormatType fft)
        Sets a default column format
        Parameters:
        fft -
      • getDefaultFormat

        public FieldFormatType getDefaultFormat()
        Gets the default format
        Returns:
        Default format
      • getColumnFormats

        public Map<String,​FieldFormatType> getColumnFormats()
        Gets individual column formats (if specified)
        Returns:
        A Map with column name and format
      • setColumnFormat

        public void setColumnFormat​(String column,
                                    FieldFormatType fft)
        Sets a column format for a specified column
        Parameters:
        column - The column name
        fft - The format
      • getColumnTooltips

        public Map<String,​String> getColumnTooltips()
        Gets the currently assigned column tooltips
        Returns:
      • setColumnTooltip

        public void setColumnTooltip​(String column,
                                     String tooltip)
        Adds a tooltip to a column
        Parameters:
        column - The column name
        tooltip - The tooltip text
      • isEnableClientFilter

        public boolean isEnableClientFilter()
      • setEnableClientFilter

        public void setEnableClientFilter​(boolean enableClientFilter)
      • styledCell

        public ResultMatrix.ResultMatrixStyledCell styledCell​(Object value)
        Creates a styled cell that can then be added as row value
        Parameters:
        value - The value of the cell
        Returns:
        The styled cell object that can then be further styled with e.g. the flow pattern .withXXX() methods
      • styledCell

        public ResultMatrix.ResultMatrixStyledCell styledCell​(Object value,
                                                              String textColor,
                                                              String bgColor)
        Creates a styled cell that can then be added as row value
        Parameters:
        value - The value of the cell
        textColor - The text color of the cell
        bgColor - The background color of the cell (HTML hex value)
        Returns:
        The styled cell object
      • styledCell

        public ResultMatrix.ResultMatrixStyledCell styledCell​(Object value,
                                                              String textColor,
                                                              String bgColor,
                                                              String weight)
        Creates a styled cell that can then be added as row value
        Parameters:
        value - The value of the cell
        textColor - The text color of the cell
        bgColor - The background color of the cell (HTML hex value)
        weight - The font weight
        Returns:
        The styled cell object
      • styledCell

        public ResultMatrix.ResultMatrixStyledCell styledCell​(Object value,
                                                              String textColor,
                                                              String bgColor,
                                                              String weight,
                                                              String alignment)
        Creates a styled cell that can then be added as row value
        Parameters:
        value - The value of the cell
        textColor - The text color of the cell
        bgColor - The background color of the cell (HTML hex value)
        weight - The font weight
        alignment - Cell alignement value (valid CSS)
        Returns:
        The styled cell object
      • imageCell

        public ResultMatrix.ResultMatrixImageCell imageCell​(Object value)
        Creates an image cell that can then be added as row value. Value should be a valid image URL
        Parameters:
        value - The image URL
        Returns:
        The image cell object
      • onRowSelection

        public ResultMatrix.ResultMatrixOnRowSelection onRowSelection()
        Configures a client-side UI event. Use case is usually a refresh of some sort when a result matrix row is selected Example code:
         matrix.onRowSelection().triggerEvent(api.dashboardWideEvent("CustomerIdChanged-ED")).withColValueAsEventDataAttr("CustomerID", "customerId")
         
        The embedded dashboard that receives the event could then look like:
          return api.dashboard("EmbeddedDashboard")
        
            // Here the user can assign values to the embedded
            // dashboard inputs common to all three modes
            .setParam("Customer Id", api.input("Customer Id"))
            .setParam("Year", api.input("Year"))
        
            // Show the dashboard embedded ...
            .showEmbedded()
            // ... and reevaluate it on "CustomerIdChanged-ED"
            // Note: "dashboardWideEvent()" fce makes the event local
            // to the containing dashboard instance
            .andRecalculateOn(api.dashboardWideEvent("CustomerIdChanged-ED"))
            // Pull the "customerId" attribute out of the event payload and expose it
            // as the "Customer Id" input to the embedded dashboard
            .withEventDataAttr("customerId").asParam("Customer Id")
         
        Returns:
        The selection event to further configure it in a flow pattern
      • getResultType

        public String getResultType()
        Specified by:
        getResultType in interface ComplexCalculationResult