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 (FilterTable)         |
 |                                                    |
 |                                                    |
 |                                                    |
 |                                                    |
 |____________________________________________________|
 |                summaryPanel                        |
 |____________________________________________________|
 |                southPanel                          |
 |____________________________________________________|
 
The condition and summary panels can be hidden Note that initialize() must be called to initialize this panel before displaying it.
See Also:
  • Constructor Details

    • EntityTablePanel

      public EntityTablePanel(is.codion.swing.framework.model.SwingEntityTableModel tableModel)
      Initializes a new EntityTablePanel instance
      Parameters:
      tableModel - the SwingEntityTableModel instance
    • EntityTablePanel

      public EntityTablePanel(is.codion.swing.framework.model.SwingEntityTableModel tableModel, Consumer<EntityTablePanel.Config> config)
      Initializes a new EntityTablePanel instance
      Parameters:
      tableModel - the SwingEntityTableModel instance
      config - provides access to the table panel configuration
    • EntityTablePanel

      public EntityTablePanel(is.codion.swing.framework.model.SwingEntityTableModel tableModel, EntityEditPanel editPanel)
      Initializes a new EntityTablePanel instance
      Parameters:
      tableModel - the SwingEntityTableModel instance
      editPanel - the edit panel
    • EntityTablePanel

      public EntityTablePanel(is.codion.swing.framework.model.SwingEntityTableModel tableModel, EntityEditPanel editPanel, Consumer<EntityTablePanel.Config> config)
      Initializes a new EntityTablePanel instance
      Parameters:
      tableModel - the SwingEntityTableModel instance
      editPanel - the edit panel
      config - provides access to the table panel configuration
  • Method Details

    • updateUI

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

      public final is.codion.swing.common.ui.component.table.FilterTable<is.codion.framework.domain.entity.Entity,is.codion.framework.domain.entity.attribute.Attribute<?>> table()
      Returns:
      the table
    • tableModel

      public final <T extends is.codion.swing.framework.model.SwingEntityTableModel> T tableModel()
      Type Parameters:
      T - the table model type
      Returns:
      the EntityTableModel used by this EntityTablePanel
    • conditionPanel

      public final <T extends is.codion.swing.common.ui.component.table.TableConditionPanel<is.codion.framework.domain.entity.attribute.Attribute<?>>> T conditionPanel()
      Type Parameters:
      T - the condition panel type
      Returns:
      the condition panel
      Throws:
      IllegalStateException - in case a condition panel is not available
      See Also:
    • summaryPanelVisible

      public final is.codion.common.state.State summaryPanelVisible()
      Returns:
      the state controlling whether the summary panel is visible
    • orderQueryBySortOrder

      public final is.codion.common.state.State orderQueryBySortOrder()
      Specifies whether the current sort order is used as a basis for the query order by clause. Note that this only applies to column attributes.
      Returns:
      the State controlling whether the current sort order should be used as a basis for the query order by clause
    • queryHiddenColumns

      public final is.codion.common.state.State queryHiddenColumns()
      Returns whether the values of hidden columns are included when querying data
      Returns:
      the State controlling whether the values of hidden columns are included when querying data
    • addPopupMenuControls

      public void addPopupMenuControls(is.codion.swing.common.ui.control.Controls additionalPopupMenuControls)
      Parameters:
      additionalPopupMenuControls - a set of controls to add to the table popup menu
      Throws:
      IllegalStateException - in case this panel has already been initialized
    • addToolBarControls

      public void addToolBarControls(is.codion.swing.common.ui.control.Controls additionalToolBarControls)
      Parameters:
      additionalToolBarControls - a set of controls to add to the table toolbar menu
      Throws:
      IllegalStateException - in case this panel has already been initialized
    • toString

      public final String toString()
      Overrides:
      toString in class Component
    • control

      public final is.codion.common.value.Value<is.codion.swing.common.ui.control.Control> control(EntityTablePanel.EntityTablePanelControl control)
      Returns a Value containing the control associated with control, an empty Value if no such control is available. Note that standard controls are populated during initialization, so until then, these values may be empty.
      Parameters:
      control - the control
      Returns:
      the Value containing the control associated with control
    • editSelected

      public final void editSelected()
      Displays a selection dialog for selecting an attribute to edit and retrieves a new value via input dialog and performs an update on the selected entities assigning the value to the attribute
      See Also:
    • editSelected

      public final void editSelected(is.codion.framework.domain.entity.attribute.Attribute<?> attributeToEdit)
      Retrieves a new value via input dialog and performs an update on the selected entities assigning the value to the attribute
      Parameters:
      attributeToEdit - the attribute which value to edit
      See Also:
    • viewDependencies

      public final void viewDependencies()
      Displays a dialog containing tables of entities depending on the selected entities via non-soft foreign keys
    • deleteSelectedWithConfirmation

      public final boolean deleteSelectedWithConfirmation()
      Deletes the entities selected in the underlying table model after asking for confirmation using the confirmer specified via EntityTablePanel.Config.deleteConfirmer(Confirmer)
      Returns:
      true if the delete operation was successful
      See Also:
    • deleteSelected

      public final boolean deleteSelected()
      Deletes the entities selected in the underlying table model without asking for confirmation.
      Returns:
      true if the delete operation was successful
    • savePreferences

      public void savePreferences()
      Saves user preferences
      See Also:
    • initialize

      public final EntityTablePanel initialize()
      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
    • setupControls

      protected void setupControls()
      Override to setup any custom controls. This default implementation is empty. This method is called after all standard controls have been initialized.
      See Also:
    • 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 EntityTablePanel.Config.includeSouthPanel(boolean).
      Returns:
      the south panel, or null if no south panel should be included
      See Also:
    • setupKeyboardActions

      protected void setupKeyboardActions()
    • configureToolBar

      protected final void configureToolBar(Consumer<is.codion.swing.common.ui.control.Controls.Config<EntityTablePanel.EntityTablePanelControl>> toolBarConfig)
      Configures the toolbar controls.
      Note that the Controls.Config instance has pre-configured defaults, which must be cleared in order to start with an empty configuration.
         configureToolBar(config -> config.clear()
                 .standard(EntityTablePanelControl.REFRESH)
                 .separator()
                 .control(createCustomControl())
                 .separator()
                 .defaults())
       
      Defaults:
      Parameters:
      toolBarConfig - provides access to the toolbar configuration
      See Also:
      • Controls.Config.clear()
    • configurePopupMenu

      protected final void configurePopupMenu(Consumer<is.codion.swing.common.ui.control.Controls.Config<EntityTablePanel.EntityTablePanelControl>> popupMenuConfig)
      Configures the popup menu controls.
      Note that the Controls.Config instance has pre-configured defaults, which must be cleared in order to start with an empty configuration.
         configurePopupMenu(config -> config.clear()
                 .standard(EntityTablePanelControl.REFRESH)
                 .separator()
                 .control(createCustomControl())
                 .separator()
                 .defaults())
       
      Defaults:
      Parameters:
      popupMenuConfig - provides access to the popup menu configuration
      See Also:
      • Controls.Config.clear()
    • editPanel

      protected final <T extends EntityEditPanel> T editPanel()
      Type Parameters:
      T - the edit panel type
      Returns:
      the edit panel
      Throws:
      IllegalStateException - in case no edit panel is available
    • createTableCellEditor

      protected TableCellEditor createTableCellEditor(is.codion.framework.domain.entity.attribute.Attribute<?> attribute)
      Creates a TableCellEditor for the given attribute, returns null if no editor is available, such as for non-editable attributes.
      Parameters:
      attribute - the attribute
      Returns:
      a TableCellEditor for the given attribute, null in case none is available
      See Also:
    • layoutPanel

      protected void layoutPanel(JComponent tableComponent, 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:
      tableComponent - the component containing the table, condition and summary panel
      southPanel - the south toolbar panel, null if not required
      See Also:
    • onException

      protected void onException(Exception exception)
      Propagates the exception to onValidationException(ValidationException) or onReferentialIntegrityException(ReferentialIntegrityException) depending on type, otherwise displays the exception.
      Parameters:
      exception - the exception to handle
      See Also:
    • onReferentialIntegrityException

      protected void onReferentialIntegrityException(is.codion.common.db.exception.ReferentialIntegrityException exception)
      Called when a ReferentialIntegrityException occurs during a delete operation on the selected entities. If the referential error handling is ReferentialIntegrityErrorHandling.DISPLAY_DEPENDENCIES, the dependencies of the entities involved are displayed to the user, otherwise onException(Exception) is called.
      Parameters:
      exception - the exception
      See Also:
    • onValidationException

      protected void onValidationException(is.codion.framework.domain.entity.exception.ValidationException exception)
      Displays the exception message.
      Parameters:
      exception - the exception
    • editDialogBuilder

      protected <T> EntityDialogs.EditAttributeDialogBuilder<T> editDialogBuilder(is.codion.framework.domain.entity.attribute.Attribute<T> attribute)
      Override to customize the edit dialog used when multiple entities are edited.
      Type Parameters:
      T - the attribute type
      Parameters:
      attribute - the attribute to edit
      Returns:
      a edit dialog builder
    • userPreferencesKey

      protected String userPreferencesKey()
      Returns the key used to identify user preferences for this table panel, that is column positions, widths and such. The default implementation is:
       
       return tableModel().getClass().getSimpleName() + "-" + entityType();
       
       
      Override in case this key is not unique within the application.
      Returns:
      the key used to identify user preferences for this table panel
    • displayException

      protected final void displayException(Exception exception)
      Displays the exception in a dialog, with the dialog owner as the current focus owner or this panel if none is available.
      Parameters:
      exception - the exception to display
    • confirmDelete

      protected final boolean confirmDelete()
      Returns:
      true if confirmed
      See Also: