Class ReportDataModel


  • public class ReportDataModel
    extends java.lang.Object
    Data model for use with the ReportDisplayPanel.

    The report is represented by a group of sections, each section being a group of data labels and their values. A report might be displayed as:

      SECTION 1
      --------
      Data Field 1                  Value 1
      Data Field 2                  Value 2
    
      SECTION 2
      --------
      Data Field 3                  Value 3
    
      ...
    

    The sections names should be strings, the data field names should be strings, and the data values can be any object that has a reasonable toString() representation.

    No effort is made by this class to make building the list of sections and data labels threadsafe. As such, the sections and data should be built prior to displaying the data in any UI. Updating data values will be run from the Swing thread so updating these values during display is safe.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SECTION_FIELD_DELIM  
    • Constructor Summary

      Constructors 
      Constructor Description
      ReportDataModel()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addData​(java.lang.String sectionName, java.lang.String dataField, java.lang.Object value)
      Add data to the given section.
      void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
      Add a PropertyChangeListener to this object.
      void addSection​(java.lang.String sectionName)
      Add a new, empty section to the report.
      void addSection​(java.lang.String sectionName, java.util.Map<java.lang.String,​java.lang.Object> dataInSection)
      Add a section to the report, providing data as the section is created.
      java.util.Set<java.lang.String> getDataFieldsInSection​(java.lang.String sectionName)
      Get the list of data fields in the provided section.
      java.lang.String getDataFieldValue​(java.lang.String sectionName, java.lang.String dataField)
      Get a String representation of the value of a data field.
      java.util.Set<java.lang.String> getSections()
      Get the list of sections in this report.
      void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
      Remove the provided listener from this object.
      void updateData​(java.lang.String sectionName, java.lang.String dataField, java.lang.Object newValue)
      Update an existing data field in the given section with a new value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SECTION_FIELD_DELIM

        public static final java.lang.String SECTION_FIELD_DELIM
        See Also:
        Constant Field Values
    • Constructor Detail

      • ReportDataModel

        public ReportDataModel()
    • Method Detail

      • addPropertyChangeListener

        public void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Add a PropertyChangeListener to this object. The listener will be updated when new sections are added and when data field values are updated. When a section is added, the Property Name will be the name of the section. When a data field value is updated the property name will be a string containing the Section Name and the Data Field Name connected with the SECTION_FIELD_DELIM (for example, "Section 1::Data Field 1".)
        Parameters:
        listener - A property change listener to be informed when section and data changes are made.
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Remove the provided listener from this object.
        Parameters:
        listener - The PropertyChangeListener to remove.
      • addSection

        public void addSection​(java.lang.String sectionName,
                               java.util.Map<java.lang.String,​java.lang.Object> dataInSection)
        Add a section to the report, providing data as the section is created. This method is not guaranteed to be threadsafe. It will inform listeners of the new section. If the section already exists it will be replaced with the provided data.
        Parameters:
        sectionName - The name of the section. This is for both identification and display purposes so make it meaningful for display and also unique.
        dataInSection - The data to display in the form of a Map. The keys to the map are the data field names and are used both for display and as ids, so make them meaningful and unique.
      • addSection

        public void addSection​(java.lang.String sectionName)
        Add a new, empty section to the report. This method is not guaranteed to be thread safe.
        Parameters:
        sectionName - The name of the new section. The name is both an id and displayed, so make it meaningful and unique. If the section already exists, it will be replaced and the data in it will be lost.
      • addData

        public void addData​(java.lang.String sectionName,
                            java.lang.String dataField,
                            java.lang.Object value)
        Add data to the given section. If the section doesn't already exist it will be added with the new data. If the data field already exists in the section, it will be replaced with the new value. This method is not guaranteed to be thread safe. It will not notify the UI of a new data field, though if it results in a new section, that section will be added to the UI with the new data field.
        Parameters:
        sectionName - The name of the section to add the data to.
        dataField - The name of the data to add - this will be used both for id and display so make it unique in the section and also meaningful to the user.
        value - The value of the data field - any object with a meaningful toString() method.
      • updateData

        public void updateData​(java.lang.String sectionName,
                               java.lang.String dataField,
                               java.lang.Object newValue)
        Update an existing data field in the given section with a new value. If the section doesn't exist an exception will be thrown. If the data field doesn't exist in the section then an exception will be thrown. Otherwise, the existing value for the data field will be replaced with the one provided here. This method will update listeners with new values and the changes should be reflected in the UI.
        Parameters:
        sectionName - The name of the section with the data field to update. It must already exist in the report.
        dataField - The name of the data field to update. It must exist in the section provided.
        newValue - The value to replace any value currently in the data field. Any object with a meaningful toString() method
      • getDataFieldValue

        public java.lang.String getDataFieldValue​(java.lang.String sectionName,
                                                  java.lang.String dataField)
        Get a String representation of the value of a data field. If either the section doesn't exist in the report or the data field is not found in the section provided then this will return an empty string.
        Parameters:
        sectionName - The name of the section where the data can be found
        dataField - The name of the field whose data is to be retrieved
        Returns:
        A string representation of the data field value, or an empty string if the data field can't be located.
      • getDataFieldsInSection

        public java.util.Set<java.lang.String> getDataFieldsInSection​(java.lang.String sectionName)
        Get the list of data fields in the provided section. If the section doesn't exist in this report an empty set will be provided.
        Parameters:
        sectionName - The name of the section whose data fields are to be retrieved.
        Returns:
        A Set of strings with the data field names, or an empty Set if the section doesn't exist.
      • getSections

        public java.util.Set<java.lang.String> getSections()
        Get the list of sections in this report.
        Returns:
        a Set of Strings with the names of all the sections in this report.