Class EntityTablePanel

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

    public class EntityTablePanel
    extends JPanel
    The EntityTablePanel is a UI class based on the EntityTableModel class. It consists of a JTable as well as filtering/searching and summary panels. The default layout is as follows
      ____________________________________________________
     |                conditionPanel                      |
     |____________________________________________________|
     |                                                    |
     |                                                    |
     |                                                    |
     |                                                    |
     |                entityTable (FilteredTable)         |
     |                                                    |
     |                                                    |
     |                                                    |
     |                                                    |
     |____________________________________________________|
     |                summaryPanel                        |
     |____________________________________________________|
     |                southPanel                          |
     |____________________________________________________|
     
    The condition and summary panels can be hidden Note that initializePanel() must be called to initialize this panel before displaying it.
    See Also:
    EntityTableModel, Serialized Form
    • Field Detail

      • ALLOW_COLUMN_REORDERING

        public static final PropertyValue<Boolean> ALLOW_COLUMN_REORDERING
        Specifies whether columns can be rearranged in tables
        Value type: Boolean
        Default value: true
      • CONDITION_PANEL_VISIBLE

        public static final PropertyValue<Boolean> CONDITION_PANEL_VISIBLE
        Specifies whether table condition panels should be visible or not by default
        Value type: Boolean
        Default value: false
      • TABLE_AUTO_RESIZE_MODE

        public static final PropertyValue<Integer> TABLE_AUTO_RESIZE_MODE
        Specifies the default table column resize mode for tables in the application
        Value type: Integer (JTable.AUTO_RESIZE_*)
        Default value: JTable.AUTO_RESIZE_OFF
      • INCLUDE_ENTITY_MENU

        public static final PropertyValue<Boolean> INCLUDE_ENTITY_MENU
        Specifies whether to include a EntityPopupMenu on this table, triggered with CTRL-ALT-V.
        Value type: Boolean
        Default value: true
      • INCLUDE_CLEAR_CONTROL

        public static final PropertyValue<Boolean> INCLUDE_CLEAR_CONTROL
        Specifies whether to include a 'Clear' control in the popup menu.
        Value type: Boolean
        Default value: false
      • REFRESH_TOOLBAR_ALWAYS_VISIBLE

        public static final PropertyValue<Boolean> REFRESH_TOOLBAR_ALWAYS_VISIBLE
        Specifies whether the refresh button toolbar should always be visible or hidden when the condition panel is not visible
        Value type: Boolean
        Default value: false
    • Constructor Detail

      • EntityTablePanel

        public EntityTablePanel​(SwingEntityTableModel tableModel)
        Initializes a new EntityTablePanel instance
        Parameters:
        tableModel - the EntityTableModel instance
      • EntityTablePanel

        public EntityTablePanel​(SwingEntityTableModel tableModel,
                                AbstractEntityTableConditionPanel conditionPanel)
        Initializes a new EntityTablePanel instance
        Parameters:
        tableModel - the EntityTableModel instance
        conditionPanel - the condition panel, if any
    • Method Detail

      • updateUI

        public void updateUI()
        Overrides:
        updateUI in class JPanel
      • tableModel

        public final SwingEntityTableModel tableModel()
        Returns:
        the EntityTableModel used by this EntityTablePanel
      • excludeFromUpdateMenu

        public final void excludeFromUpdateMenu​(Attribute<?> attribute)
        Specifies that the given property should be excluded from the update selected entities menu.
        Parameters:
        attribute - the id of the property to exclude from the update menu
        Throws:
        IllegalStateException - in case the panel has already been initialized
      • addPopupControls

        public final void addPopupControls​(Controls additionalPopupControls)
        Parameters:
        additionalPopupControls - a set of controls to add to the table popup menu
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializePanel()
      • addToolBarControls

        public final void addToolBarControls​(Controls additionalToolBarControls)
        Parameters:
        additionalToolBarControls - a set of controls to add to the table toolbar menu
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializePanel()
      • setIncludeSouthPanel

        public final void setIncludeSouthPanel​(boolean includeSouthPanel)
        Parameters:
        includeSouthPanel - true if the south panel should be included
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializeSouthPanel(), initializePanel()
      • setIncludeConditionPanel

        public final void setIncludeConditionPanel​(boolean includeConditionPanel)
        Parameters:
        includeConditionPanel - true if the condition panel should be included
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializePanel()
      • setIncludePopupMenu

        public final void setIncludePopupMenu​(boolean includePopupMenu)
        Parameters:
        includePopupMenu - true if a popup menu should be included
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializePanel()
      • setIncludeClearControl

        public final void setIncludeClearControl​(boolean includeClearControl)
        Parameters:
        includeClearControl - true if a 'Clear' control should be included in the popup menu
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializePanel()
      • setIncludeSelectionModeControl

        public final void setIncludeSelectionModeControl​(boolean includeSelectionModeControl)
        Parameters:
        includeSelectionModeControl - true if a 'Single Selection' control should be included in the popup menu
        Throws:
        IllegalStateException - in case the panel has already been initialized
        See Also:
        initializePanel()
      • setColumnSelection

        public final void setColumnSelection​(EntityTablePanel.ColumnSelection columnSelection)
        Parameters:
        columnSelection - specifies how columns are selected
      • isRefreshToolbarAlwaysVisible

        public final boolean isRefreshToolbarAlwaysVisible()
        Returns:
        true if the refresh toolbar should always be visible
      • setRefreshToolbarAlwaysVisible

        public final void setRefreshToolbarAlwaysVisible​(boolean refreshToolbarAlwaysVisible)
        Parameters:
        refreshToolbarAlwaysVisible - true if the refresh toolbar should always be visible, instead of being hidden when the condition panel is not visible
      • isShowRefreshingProgressBar

        public final boolean isShowRefreshingProgressBar()
        Returns:
        true if a progress bar is shown while the model is refreshing
      • setShowRefreshingProgressBar

        public final void setShowRefreshingProgressBar​(boolean showRefreshingProgressBar)
        Parameters:
        showRefreshingProgressBar - true if an indeterminate progress bar should be shown while the model is refreshing
      • setConditionPanelVisible

        public final void setConditionPanelVisible​(boolean visible)
        Hides or shows the column condition panel for this EntityTablePanel
        Parameters:
        visible - if true the condition panel is shown, if false it is hidden
      • isConditionPanelVisible

        public final boolean isConditionPanelVisible()
        Returns:
        true if the condition panel is visible, false if it is hidden
      • setUpdateSelectedComponentFactory

        public final <T,​A extends Attribute<T>,​C extends JComponent> void setUpdateSelectedComponentFactory​(A attribute,
                                                                                                                        EntityComponentFactory<T,​A,​C> componentFactory)
        Sets the component factory for the given attribute, used when updating entities via updateSelectedEntities(Property).
        Type Parameters:
        T - the value type
        A - the attribute type
        C - the component type
        Parameters:
        attribute - the attribute
        componentFactory - the component factory
      • setTableCellEditorComponentFactory

        public final <T,​A extends Attribute<T>,​C extends JComponent> void setTableCellEditorComponentFactory​(A attribute,
                                                                                                                         EntityComponentFactory<T,​A,​C> componentFactory)
        Sets the table cell editor component factory for the given attribute.
        Type Parameters:
        T - the value type
        A - the attribute type
        C - the component type
        Parameters:
        attribute - the attribute
        componentFactory - the component factory
      • setSummaryPanelVisible

        public final void setSummaryPanelVisible​(boolean visible)
        Hides or shows the column summary panel for this EntityTablePanel, if no summary panel is available calling this method has no effect.
        Parameters:
        visible - if true then the summary panel is shown, if false it is hidden
      • isSummaryPanelVisible

        public final boolean isSummaryPanelVisible()
        Returns:
        true if the column summary panel is visible, false if it is hidden
      • setReferentialIntegrityErrorHandling

        public final void setReferentialIntegrityErrorHandling​(ReferentialIntegrityErrorHandling referentialIntegrityErrorHandling)
        Parameters:
        referentialIntegrityErrorHandling - the action to take on a referential integrity error during delete
      • containsControl

        public final boolean containsControl​(EntityTablePanel.ControlCode controlCode)
        Parameters:
        controlCode - the control code
        Returns:
        true if this table panel contains the given control
      • createViewDependenciesControl

        public final Control createViewDependenciesControl()
        Returns:
        a control for showing the dependencies dialog
      • createDeleteSelectedControl

        public final Control createDeleteSelectedControl()
        Returns:
        a control for deleting the selected entities
        Throws:
        IllegalStateException - in case the underlying model is read only or if deleting is not enabled
      • createPrintTableControl

        public final Control createPrintTableControl()
        Returns:
        a control for printing the table
      • createRefreshControl

        public final Control createRefreshControl()
        Returns:
        a Control for refreshing the underlying table data
      • createClearControl

        public final Control createClearControl()
        Returns:
        a Control for clearing the underlying table model, that is, removing all rows
      • viewSelectionDependencies

        public final void viewSelectionDependencies()
        Shows a dialog containing lists of entities depending on the selected entities via foreign key
      • delete

        public final void delete()
        Deletes the entities selected in the underlying table model
        See Also:
        confirmDelete()
      • onException

        public void onException​(Throwable exception)
        Handles the given exception, simply displays the error message to the user by default.
        Parameters:
        exception - the exception to handle
        See Also:
        displayException(Throwable)
      • displayException

        public final void displayException​(Throwable exception)
        Displays the exception in a dialog
        Parameters:
        exception - the exception to display
      • showDependenciesDialog

        public static void showDependenciesDialog​(Collection<Entity> entities,
                                                  EntityConnectionProvider connectionProvider,
                                                  JComponent dialogParent)
        Shows a dialog containing the entities depending on the given entities.
        Parameters:
        entities - the entities for which to display dependencies
        connectionProvider - the connection provider
        dialogParent - the dialog parent
      • showDependenciesDialog

        public static void showDependenciesDialog​(Collection<Entity> entities,
                                                  EntityConnectionProvider connectionProvider,
                                                  JComponent dialogParent,
                                                  String noDependenciesMessage)
        Shows a dialog containing the entities depending on the given entities.
        Parameters:
        entities - the entities for which to display dependencies
        connectionProvider - the connection provider
        dialogParent - the dialog parent
        noDependenciesMessage - the message to show in case of no dependencies
      • createReadOnlyEntityTablePanel

        public static EntityTablePanel createReadOnlyEntityTablePanel​(Collection<Entity> entities,
                                                                      EntityConnectionProvider connectionProvider)
        Creates a static read-only entity table panel showing the given entities
        Parameters:
        entities - the entities to show in the panel
        connectionProvider - the EntityConnectionProvider, in case the returned panel should require one
        Returns:
        a static EntityTablePanel showing the given entities
      • createEntityTablePanel

        public static EntityTablePanel createEntityTablePanel​(Collection<Entity> entities,
                                                              EntityConnectionProvider connectionProvider)
        Creates a static entity table panel showing the given entities, note that this table panel will provide a popup menu for updating and deleting the selected entities unless the underlying entities are read-only.
        Parameters:
        entities - the entities to show in the panel
        connectionProvider - the EntityConnectionProvider, in case the returned panel should require one
        Returns:
        a static EntityTablePanel showing the given entities
      • createEntityTablePanel

        public static EntityTablePanel createEntityTablePanel​(SwingEntityTableModel tableModel)
        Creates an entity table panel based on the given table model. If the table model is not read only, a popup menu for updating or deleting the selected entities is provided.
        Parameters:
        tableModel - the table model
        Returns:
        an entity table panel based on the given model
      • initializePanel

        public final EntityTablePanel initializePanel()
        Initializes the UI, while presenting a wait cursor to the user. Note that calling this method more than once has no effect.
        Returns:
        this EntityTablePanel instance
      • initializeSouthPanel

        protected JPanel initializeSouthPanel()
        Initializes the south panel, override and return null for no south panel. Not called if the south panel has been disabled via setIncludeSouthPanel(boolean).
        Returns:
        the south panel, or null if no south panel should be included
      • setupKeyboardActions

        protected void setupKeyboardActions()
        Sets up the default keyboard actions. CTRL-T transfers focus to the table in case one is available, CTR-S opens a select search condition panel dialog, in case one is available, CTR-F selects the table search field
      • setControl

        protected final void setControl​(EntityTablePanel.ControlCode controlCode,
                                        Control control)
        Associates control with controlCode
        Parameters:
        controlCode - the control code
        control - the control to associate with controlCode, null for none
        Throws:
        IllegalStateException - in case the panel has already been initialized
      • createToolBarControls

        protected Controls createToolBarControls​(List<Controls> additionalToolBarControls)
      • createPopupControls

        protected Controls createPopupControls​(List<Controls> additionalPopupControls)
        Creates a Controls instance containing the controls to include in the table popup menu. Returns null or an empty Controls instance to indicate that no popup menu should be included.
        Parameters:
        additionalPopupControls - any additional controls to include in the popup menu
        Returns:
        Controls on which to base the table popup menu, null or an empty Controls instance if no popup menu should be included
      • createPrintControls

        protected Controls createPrintControls()
      • confirmDelete

        protected boolean confirmDelete()
        Called before delete is performed, if true is returned the delete action is performed otherwise it is canceled
        Returns:
        true if the delete action should be performed
      • confirmDeleteMessages

        protected String[] confirmDeleteMessages()
        Returns:
        Strings to display in the confirm delete dialog, index 0 = message, index 1 = title
      • createTableCellRenderer

        protected <T> TableCellRenderer createTableCellRenderer​(Property<T> property)
        Creates a TableCellRenderer to use for the given property in this EntityTablePanel
        Type Parameters:
        T - the property type
        Parameters:
        property - the property
        Returns:
        the TableCellRenderer for the given property
      • createTableCellEditor

        protected <T> TableCellEditor createTableCellEditor​(Property<T> property)
        Creates a TableCellEditor for the given property, returns null if no editor is available
        Type Parameters:
        T - the property type
        Parameters:
        property - the property
        Returns:
        a TableCellEditor for the given property
      • layoutPanel

        protected void layoutPanel​(JPanel tablePanel,
                                   JPanel southPanel)
        This method simply adds tablePanel at location BorderLayout.CENTER and, if non-null, the given southPanel to the BorderLayout.SOUTH location. By overriding this method you can override the default layout.
        Parameters:
        tablePanel - the panel containing the table, condition and summary panel
        southPanel - the south toolbar panel, null if not required
        See Also:
        initializeSouthPanel()
      • createSouthToolBar

        protected JToolBar createSouthToolBar()
        Creates the south panel toolbar, by default based on createToolBarControls(List)
        Returns:
        the toolbar to add to the south panel, null if none should be included