Class ResultMatrix

  • All Implemented Interfaces:
    Serializable, AppPages, ComplexCalculationResult

    public class ResultMatrix
    extends Object
    implements ComplexCalculationResult, AppPages
    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
      • withTitle

        public ResultMatrix withTitle​(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
      • isPreferencesDisabled

        public boolean isPreferencesDisabled()
        Tells whether saving of matrix grid preferences is disabled.
        Returns:
        true if saving of grid preferences is disabled. Default is false
        Since:
        7.2 Bijou PR2
      • setDisablePreferences

        public void setDisablePreferences​(boolean disablePreferences)
        Allows to disable saving preferences of the matrix grid (columns, sorting, filtering). If not disabled, the preferences may be be saved with the global dashboard preferences or attached to a specific preferences name defined with setPreferenceName()/withPreferenceName()
        Parameters:
        disablePreferences - true means saving grid preferences is disabled. Default is false
        Since:
        7.2 Bijou PR2
      • withDisablePreferences

        public ResultMatrix withDisablePreferences​(boolean disablePreferences)
        Allows to disable saving preferences of the matrix grid (columns, sorting, filtering). If not disabled, the preferences may be be saved with the global dashboard preferences or attached to a specific preferences name defined with setPreferenceName()/withPreferenceName()
        Parameters:
        disablePreferences - true means saving grid preferences is disabled. Default is false
        Since:
        7.2 Bijou PR2
      • 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
      • withDisableSorting

        public ResultMatrix withDisableSorting​(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 -
      • withEscapeHTML

        public ResultMatrix withEscapeHTML​(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
      • withPreferenceName

        public ResultMatrix withPreferenceName​(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".
      • withColumnTranslation

        public ResultMatrix withColumnTranslation​(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
      • withColumn

        public ResultMatrix withColumn​(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
      • withColumn

        public ResultMatrix withColumn​(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
      • withColumns

        public ResultMatrix withColumns​(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
      • withRow

        public ResultMatrix withRow​(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
      • withRows

        public ResultMatrix withRows​(List<Map<String,​Object>> rows)
        Adds multiple data rows. The keys of the row-map should match the column names defined earlier
        Parameters:
        rows - Row as List of Maps
      • 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
      • withColumnFormat

        public ResultMatrix withColumnFormat​(String column,
                                             FieldFormatType fft)
        Sets a column format for a specified column
        Parameters:
        column - The column name
        fft - The format
      • withColumnFormats

        public ResultMatrix withColumnFormats​(Map<String,​FieldFormatType> columnFormats)
        Sets a column formats for multiple columns. Adds column if not existing yet
        Parameters:
        columnFormats - A key value map of column:format type
      • 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
      • withColumnTooltip

        public ResultMatrix withColumnTooltip​(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)
      • withEnableClientFilter

        public ResultMatrix withEnableClientFilter​(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
      • rowSelectionBackEndAction

        public ResultMatrix.ResultMatrixBackEndAction rowSelectionBackEndAction​(String id)

        Allows UI users to select multiple rows and adds an action button next to the ResultMatrix. Multiple such action buttons can be defined, identified by the provided id String.

        The action will be handled by a dedicated logic, which receives an InputMatrix parameter named after the provided id and featuring the row values of a subset of the columns.

        Example:

             def matrix = api.newMatrix("col1", "col2", "col3")
             matrix.addRow(1, "a", "f")
             matrix.addRow(2, "b", "g")
             matrix.rowSelectionBackEndAction("actionId")
                         .withLogicName("action_handler")
                         .withColumns("col2", "col3")
                         .withButtonLabel("Click here")
                         .withSuccessMessage("Success")
                         .withFailureMessage("Sorry")
             
         

        Note: This is available in Unity UI only. No backporting planned for the Classic UI.

        See ResultMatrix.ResultMatrixBackEndAction to explore the full list of methods allowing to configure an action.
        Parameters:
        id - a String identifying the action
        Returns:
        a customizable object representing an action button, which the UI will then render and make functional
        Since:
        7.0 Bijou
      • 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
      • addFormatsToResultMatrix

        public void addFormatsToResultMatrix()