Class DefaultTableColumnModelExt

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.event.ListSelectionListener, javax.swing.table.TableColumnModel, TableColumnModelExt

    public class DefaultTableColumnModelExt
    extends javax.swing.table.DefaultTableColumnModel
    implements TableColumnModelExt
    A default implementation of TableColumnModelExt.

    TODO: explain sub-optimal notification on showing/hiding columns. (hot fixed issues #156, #157. To really do it need enhanced TableColumnModelEvent and -Listeners that are aware of the event.)

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<javax.swing.table.TableColumn> currentColumns
      contains a list of all column, in the order they would appear if all were visible.
      private java.util.List<javax.swing.table.TableColumn> initialColumns
      contains a list of all columns, in the order in which were added to the model.
      private boolean isVisibilityChange
      flag to distinguish a shown/hidden column from really added/removed columns during notification.
      private DefaultTableColumnModelExt.VisibilityListener visibilityListener
      Listener attached to TableColumnExt instances to listen for changes to their visibility status, and to hide/show the column as oppropriate
      • Fields inherited from class javax.swing.table.DefaultTableColumnModel

        changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultTableColumnModelExt()
      Creates a an empty DefaultTableColumnModelExt.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addColumn​(javax.swing.table.TableColumn aColumn)
      void addColumnModelListener​(javax.swing.event.TableColumnModelListener x)
      Adds a listener for table column model events.
      protected void fireColumnPropertyChange​(java.beans.PropertyChangeEvent evt)
      Notifies TableColumnModelExtListeners about property changes of contained columns.
      int getColumnCount​(boolean includeHidden)
      Returns the number of contained columns.
      TableColumnExt getColumnExt​(int columnIndex)
      Returns the TableColumnExt at view position columnIndex.
      TableColumnExt getColumnExt​(java.lang.Object identifier)
      Returns the first TableColumnExt with the given identifier.
      java.util.List<javax.swing.table.TableColumn> getColumns​(boolean includeHidden)
      Returns a List of contained TableColumns.
      protected javax.swing.event.EventListenerList getEventListenerList()
      Exposed for testing only - don't use! Will be removed again!
      TableColumnModelExtListener[] getTableColumnModelExtListeners()  
      boolean isAddedFromInvisibleEvent​(int newIndex)
      hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnAdded originated from moving a column from invisible to visible.
      boolean isRemovedToInvisibleEvent​(int oldIndex)
      hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnRemoved originated from moving a column from visible to invisible.
      void moveColumn​(int columnIndex, int newIndex)
      protected void moveToInvisible​(TableColumnExt col)
      Update internal state after the visibility of the column was changed to invisible.
      protected void moveToVisible​(TableColumnExt col)
      Update internal state after the visibility of the column was changed to visible.
      void propertyChange​(java.beans.PropertyChangeEvent evt)
      void removeColumn​(javax.swing.table.TableColumn column)
      void removeColumnModelListener​(javax.swing.event.TableColumnModelListener x)
      private void updateCurrentColumns​(int oldIndex, int newIndex)
      Adjusts the current column sequence when a visible column is moved.
      • Methods inherited from class javax.swing.table.DefaultTableColumnModel

        createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, recalcWidthCache, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.swing.table.TableColumnModel

        getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumns, getColumnSelectionAllowed, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, setColumnMargin, setColumnSelectionAllowed, setSelectionModel
    • Field Detail

      • isVisibilityChange

        private boolean isVisibilityChange
        flag to distinguish a shown/hidden column from really added/removed columns during notification. This is brittle!
      • initialColumns

        private java.util.List<javax.swing.table.TableColumn> initialColumns
        contains a list of all columns, in the order in which were added to the model.
      • currentColumns

        private java.util.List<javax.swing.table.TableColumn> currentColumns
        contains a list of all column, in the order they would appear if all were visible.
      • visibilityListener

        private DefaultTableColumnModelExt.VisibilityListener visibilityListener
        Listener attached to TableColumnExt instances to listen for changes to their visibility status, and to hide/show the column as oppropriate
    • Constructor Detail

      • DefaultTableColumnModelExt

        public DefaultTableColumnModelExt()
        Creates a an empty DefaultTableColumnModelExt.
    • Method Detail

      • getColumns

        public java.util.List<javax.swing.table.TableColumn> getColumns​(boolean includeHidden)
        Returns a List of contained TableColumns. Includes or excludes invisible columns, depending on whether the includeHidden is true or false, respectively. If false, an Iterator over the List is equivalent to the Enumeration returned by getColumns().

        NOTE: the order of columns in the List depends on whether or not the invisible columns are included, in the former case it's the insertion order in the latter it's the current order of the visible columns.

        Specified by:
        getColumns in interface TableColumnModelExt
        Parameters:
        includeHidden - a boolean to indicate whether invisible columns should be included
        Returns:
        a List of contained columns.
      • getColumnCount

        public int getColumnCount​(boolean includeHidden)
        Returns the number of contained columns. The count includes or excludes invisible columns, depending on whether the includeHidden is true or false, respectively. If false, this method returns the same count as getColumnCount().
        Specified by:
        getColumnCount in interface TableColumnModelExt
        Parameters:
        includeHidden - a boolean to indicate whether invisible columns should be included
        Returns:
        the number of contained columns, including or excluding the invisible as specified.
      • getColumnExt

        public TableColumnExt getColumnExt​(java.lang.Object identifier)
        Returns the first TableColumnExt with the given identifier. The return value is null if there is no contained column with identifier or if the column with identifier is not of type TableColumnExt. The returned column may be visible or hidden.
        Specified by:
        getColumnExt in interface TableColumnModelExt
        Parameters:
        identifier - the object used as column identifier
        Returns:
        first TableColumnExt with the given identifier or null if none is found
      • getColumnExt

        public TableColumnExt getColumnExt​(int columnIndex)
        Returns the TableColumnExt at view position columnIndex. The return value is null, if the column at position columnIndex is not of type TableColumnExt. The returned column is visible.
        Specified by:
        getColumnExt in interface TableColumnModelExt
        Parameters:
        columnIndex - the index of the column desired
        Returns:
        the TableColumnExt object that matches the column index
      • isRemovedToInvisibleEvent

        public boolean isRemovedToInvisibleEvent​(int oldIndex)
        hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnRemoved originated from moving a column from visible to invisible.
        Parameters:
        oldIndex - the fromIndex of the columnEvent
        Returns:
        true if the column was moved to invisible
      • isAddedFromInvisibleEvent

        public boolean isAddedFromInvisibleEvent​(int newIndex)
        hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnAdded originated from moving a column from invisible to visible.
        Parameters:
        newIndex - the toIndex of the columnEvent
        Returns:
        true if the column was moved to visible
      • removeColumn

        public void removeColumn​(javax.swing.table.TableColumn column)

        Overridden to update internals related to column visibility.

        Specified by:
        removeColumn in interface javax.swing.table.TableColumnModel
        Overrides:
        removeColumn in class javax.swing.table.DefaultTableColumnModel
      • addColumn

        public void addColumn​(javax.swing.table.TableColumn aColumn)

        Overridden to update internals related to column visibility.

        Specified by:
        addColumn in interface javax.swing.table.TableColumnModel
        Overrides:
        addColumn in class javax.swing.table.DefaultTableColumnModel
      • moveColumn

        public void moveColumn​(int columnIndex,
                               int newIndex)

        Overridden to update internals related to column visibility.

        Specified by:
        moveColumn in interface javax.swing.table.TableColumnModel
        Overrides:
        moveColumn in class javax.swing.table.DefaultTableColumnModel
      • updateCurrentColumns

        private void updateCurrentColumns​(int oldIndex,
                                          int newIndex)
        Adjusts the current column sequence when a visible column is moved.
        Parameters:
        oldIndex - the old visible position.
        newIndex - the new visible position.
      • moveToInvisible

        protected void moveToInvisible​(TableColumnExt col)
        Update internal state after the visibility of the column was changed to invisible. The given column is assumed to be contained in this model.
        Parameters:
        col - the column which was hidden.
      • moveToVisible

        protected void moveToVisible​(TableColumnExt col)
        Update internal state after the visibility of the column was changed to visible. The given column is assumed to be contained in this model.
        Parameters:
        col - the column which was made visible.
      • getEventListenerList

        protected javax.swing.event.EventListenerList getEventListenerList()
        Exposed for testing only - don't use! Will be removed again!
        Returns:
        super's listener list
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        Overrides:
        propertyChange in class javax.swing.table.DefaultTableColumnModel
      • fireColumnPropertyChange

        protected void fireColumnPropertyChange​(java.beans.PropertyChangeEvent evt)
        Notifies TableColumnModelExtListeners about property changes of contained columns. The event instance is the original as fired by the TableColumn.
        Parameters:
        evt - the event received
        See Also:
        EventListenerList
      • addColumnModelListener

        public void addColumnModelListener​(javax.swing.event.TableColumnModelListener x)
        Adds a listener for table column model events. This enhances super's behaviour in that it guarantees to notify listeners of type TableColumnModelListenerExt about property changes of contained columns.

        Overridden to install enhanced notification of listeners of type. TableColumnModelListenerExt about property changes of contained columns.

        Specified by:
        addColumnModelListener in interface javax.swing.table.TableColumnModel
        Specified by:
        addColumnModelListener in interface TableColumnModelExt
        Overrides:
        addColumnModelListener in class javax.swing.table.DefaultTableColumnModel
        Parameters:
        x - a TableColumnModelListener object
      • removeColumnModelListener

        public void removeColumnModelListener​(javax.swing.event.TableColumnModelListener x)

        Overridden to uninstall enhanced notification of listeners of type. TableColumnModelListenerExt about property changes of contained columns.

        Specified by:
        removeColumnModelListener in interface javax.swing.table.TableColumnModel
        Overrides:
        removeColumnModelListener in class javax.swing.table.DefaultTableColumnModel
      • getTableColumnModelExtListeners

        public TableColumnModelExtListener[] getTableColumnModelExtListeners()
        Returns:
        array of all registered listeners