Class CColumnControlButton

  • All Implemented Interfaces:
    ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

    public class CColumnControlButton
    extends JButton
    Code and description adapted from SwingX ColumnControlButton class. A component to allow interactive customization of CTable's columns. It's main purpose is to allow toggling of table columns' visibility. Additionally, arbitrary configuration actions can be exposed.

    This component is installed in the CTable's trailing corner, if enabled:

    
     table.setColumnControlVisible(true);
     
    From the perspective of a CTable, the component's behaviour is opaque. Typically, the button's action is to popup a component for user interaction.

    This class is responsible for handling/providing/updating the lists of actions and to keep all action's state in synch with Table-/Column state. The visible behaviour of the popup is delegated to a ColumnControlPopup.

    See Also:
    CTable#setColumnControl, Serialized Form
    • Field Detail

      • COLUMN_CONTROL_MARKER

        public static final String COLUMN_CONTROL_MARKER
        Marker to auto-recognize actions which should be added to the popup.
        See Also:
        Constant Field Values
      • popup

        protected org.jdesktop.swingx.table.ColumnControlPopup popup
        exposed for testing.
    • Constructor Detail

      • CColumnControlButton

        public CColumnControlButton​(CTable table,
                                    Icon icon)
        Creates a column control button for the table. The button uses the given icon and has no text.
        Parameters:
        table - the JTable controlled by this component
        icon - the Icon to show
    • Method Detail

      • togglePopup

        public void togglePopup()
        Toggles the popup component's visibility. This method is called by this control's default action.

        Here: delegates to getControlPopup().

      • getColumnControlPopup

        protected org.jdesktop.swingx.table.ColumnControlPopup getColumnControlPopup()
        Returns to popup component for user interaction. Lazily creates the component if necessary.
        Returns:
        the ColumnControlPopup for showing the items, guaranteed to be not null.
        See Also:
        createColumnControlPopup()
      • createColumnControlPopup

        protected org.jdesktop.swingx.table.ColumnControlPopup createColumnControlPopup()
        Factory method to return a ColumnControlPopup. Subclasses can override to hook custom implementations.
        Returns:
        the ColumnControlPopup used.
      • updateFromColumnModelChange

        protected void updateFromColumnModelChange​(TableColumnModel oldModel)
        Adjusts internal state after table's column model property has changed. Handles cleanup of listeners to the old/new columnModel (Note, that it listens to the column model only if it can control column visibility). Updates content of popup.
        Parameters:
        oldModel - the old TableColumnModel we had been listening to.
      • updateFromTableEnabledChanged

        protected void updateFromTableEnabledChanged()
        Synchs this button's enabled with table's enabled.
      • populatePopup

        protected void populatePopup()
        Populates the popup from scratch. If applicable, creates and adds column visibility actions. Always adds additional actions.
      • clearAll

        protected void clearAll()
        removes all components from the popup, making sure to release all columnVisibility actions.
      • clearColumnVisibilityActions

        protected void clearColumnVisibilityActions()
        Releases actions and clears list of actions.
      • addVisibilityActionItems

        protected void addVisibilityActionItems()
        Adds visibility actions into the popup view. Here: delegates the list of actions to the DefaultColumnControlPopup.

        PRE: columnVisibilityActions populated before calling this.

      • addAdditionalActionItems

        protected void addAdditionalActionItems()
        Adds additional actions to the popup. Here: delegates the list of actions as returned by #getAdditionalActions() to the DefaultColumnControlPopup. Does nothing if #getColumnActions() is empty.
      • createVisibilityActions

        protected void createVisibilityActions()
        Creates and adds a ColumnVisiblityAction for every column that should be togglable via the column control.

        Here: all table columns contained in the TableColumnModel - visible and invisible columns - to createColumnVisibilityAction and adds all not null return values.

        PRE: canControl()

        See Also:
        createColumnVisibilityAction(javax.swing.table.TableColumn)
      • createColumnVisibilityAction

        protected CColumnControlButton.ColumnVisibilityAction createColumnVisibilityAction​(TableColumn column)
        Creates and returns a ColumnVisibilityAction for the given TableColumn. The return value might be null, f.i. if the column should not be allowed to be toggled.
        Parameters:
        column - the TableColumn to use for the action
        Returns:
        a ColumnVisibilityAction to use for the given column, may be null.
      • getColumnVisibilityActions

        protected List<CColumnControlButton.ColumnVisibilityAction> getColumnVisibilityActions()
        Lazyly creates and returns the List of visibility actions.
        Returns:
        the list of visibility actions, guaranteed to be != null.
      • getAdditionalActions

        protected List<Action> getAdditionalActions()
        creates and returns a list of additional Actions to add to the popup. Here: the actions are looked up in the table's actionMap according to the keys as returned from #getColumnControlActionKeys();
        Returns:
        a list containing all additional actions to include into the popup.
      • getColumnControlActionKeys

        protected List<String> getColumnControlActionKeys()
        Looks up and returns action keys to access actions in the table's actionMap which should be included into the popup. Here: all keys with isColumnControlActionKey(key). The list is sorted by those keys.
        Returns:
        the action keys of table's actionMap entries whose action should be included into the popup.
      • isColumnControlActionKey

        protected boolean isColumnControlActionKey​(Object actionKey)
        Here: true if a String key starts with #COLUMN_CONTROL_MARKER.
        Parameters:
        actionKey - a key in the table's actionMap.
        Returns:
        a boolean to indicate whether the given actionKey maps to an action which should be included into the popup.
      • getTablePropertyChangeListener

        protected PropertyChangeListener getTablePropertyChangeListener()
        Returns the listener to table's property changes. The listener is lazily created if necessary.
        Returns:
        the PropertyChangeListener for use with the table, guaranteed to be not null.
      • createTablePropertyChangeListener

        protected PropertyChangeListener createTablePropertyChangeListener()
        Creates the listener to table's property changes. Subclasses are free to roll their own.

        Implementation note: this listener reacts to table's enabled and columnModel properties and calls the respective updateFromXX methodes.

        Returns:
        the PropertyChangeListener for use with the table.
      • getColumnModelListener

        protected TableColumnModelListener getColumnModelListener()
        Returns the listener to table's column model. The listener is lazily created if necessary.
        Returns:
        the TableColumnModelListener for use with the table's column model, guaranteed to be not null.
      • createColumnModelListener

        protected TableColumnModelListener createColumnModelListener()
        Creates the listener to columnModel. Subclasses are free to roll their own.

        Implementation note: this listener reacts to "real" columnRemoved/-Added by populating the popups content from scratch.

        Returns:
        the TableColumnModelListener for use with the table's columnModel.