Class EntityDataModel<T>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<T>, javax.swing.table.TableModel

    public class EntityDataModel<T>
    extends javax.swing.table.AbstractTableModel
    implements javax.swing.table.TableModel, java.lang.Iterable<T>
    A data model for a tabular view of a list of persistent entities. The data supplied by this model can be filtered to display field values of basic type or single-valued or multi-valued relationships.
    The meta-information about the attributes of the entity are supplied by newly defined meta-model API of JPA 2.0 specification.
    Author:
    Pinaki Poddar
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ALL_ATTR
      Constant designates to include all fields.
      static int ASSOCIATION_ATTR
      Constant designates to include single-valued relation fields.
      static int BASIC_ATTR
      Constant designates to include non-relation fields.
      static int PLURAL_ATTR
      Constant designates to include multi-valued relation fields.
      static int ROW_COUNT
      Constant designates to show a row count field at the first column.
      • Fields inherited from class javax.swing.table.AbstractTableModel

        listenerList
    • Constructor Summary

      Constructors 
      Constructor Description
      EntityDataModel​(java.lang.Class<T> cls, java.util.List<T> data, jakarta.persistence.metamodel.Metamodel meta, int styleBits)
      Attributes of the entity are reordered with basic attributes, followed by singular association followed by the many-valued attributes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      jakarta.persistence.metamodel.Attribute<?,​?> getAttribute​(int columnIndex)
      Gets the attribute at a given column index.
      java.lang.Class<?> getColumnClass​(int columnIndex)  
      int getColumnCount()  
      java.lang.String getColumnName​(int columnIndex)  
      T getRow​(int row)
      Gets the entity represented in the given row.
      int getRowCount()  
      java.lang.Object getValueAt​(int rowIndex, int columnIndex)  
      boolean isCellEditable​(int rowIndex, int columnIndex)  
      java.util.Iterator<T> iterator()  
      void setValueAt​(java.lang.Object value, int rowIndex, int columnIndex)  
      void updateData​(java.util.List<T> newData)  
      • Methods inherited from class javax.swing.table.AbstractTableModel

        addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface javax.swing.table.TableModel

        addTableModelListener, removeTableModelListener
    • Field Detail

      • BASIC_ATTR

        public static int BASIC_ATTR
        Constant designates to include non-relation fields.
      • ASSOCIATION_ATTR

        public static int ASSOCIATION_ATTR
        Constant designates to include single-valued relation fields.
      • PLURAL_ATTR

        public static int PLURAL_ATTR
        Constant designates to include multi-valued relation fields.
      • ALL_ATTR

        public static int ALL_ATTR
        Constant designates to include all fields.
      • ROW_COUNT

        public static int ROW_COUNT
        Constant designates to show a row count field at the first column.
    • Constructor Detail

      • EntityDataModel

        public EntityDataModel​(java.lang.Class<T> cls,
                               java.util.List<T> data,
                               jakarta.persistence.metamodel.Metamodel meta,
                               int styleBits)
        Attributes of the entity are reordered with basic attributes, followed by singular association followed by the many-valued attributes.
    • Method Detail

      • getAttribute

        public jakarta.persistence.metamodel.Attribute<?,​?> getAttribute​(int columnIndex)
        Gets the attribute at a given column index. Can be null for 0-th index if row count is being shown.
      • getRow

        public T getRow​(int row)
        Gets the entity represented in the given row.
      • getColumnClass

        public java.lang.Class<?> getColumnClass​(int columnIndex)
        Specified by:
        getColumnClass in interface javax.swing.table.TableModel
        Overrides:
        getColumnClass in class javax.swing.table.AbstractTableModel
      • getColumnCount

        public int getColumnCount()
        Specified by:
        getColumnCount in interface javax.swing.table.TableModel
      • getColumnName

        public java.lang.String getColumnName​(int columnIndex)
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
        Overrides:
        getColumnName in class javax.swing.table.AbstractTableModel
      • getRowCount

        public int getRowCount()
        Specified by:
        getRowCount in interface javax.swing.table.TableModel
      • getValueAt

        public java.lang.Object getValueAt​(int rowIndex,
                                           int columnIndex)
        Specified by:
        getValueAt in interface javax.swing.table.TableModel
      • isCellEditable

        public boolean isCellEditable​(int rowIndex,
                                      int columnIndex)
        Specified by:
        isCellEditable in interface javax.swing.table.TableModel
        Overrides:
        isCellEditable in class javax.swing.table.AbstractTableModel
      • setValueAt

        public void setValueAt​(java.lang.Object value,
                               int rowIndex,
                               int columnIndex)
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
        Overrides:
        setValueAt in class javax.swing.table.AbstractTableModel
      • updateData

        public void updateData​(java.util.List<T> newData)
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>