Class EntityEditComponentPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
EntityEditPanel

public class EntityEditComponentPanel extends JPanel
A base class for entity edit panels, managing the components used for editing entities.
See Also:
  • Field Details

  • Constructor Details

    • EntityEditComponentPanel

      protected EntityEditComponentPanel(SwingEntityEditModel editModel)
      Instantiates a new EntityEditComponentPanel
      Parameters:
      editModel - the edit model
  • Method Details

    • editModel

      public final <T extends SwingEntityEditModel> T editModel()
      Type Parameters:
      T - the edit model type
      Returns:
      the edit model this panel is based on
    • requestInitialFocus

      public final void requestInitialFocus()
      Sets the initial focus, if an initial focus component or component attribute has been set that component receives the focus, if not, or if that component is not focusable, this panel receives the focus. Note that if this panel is not visible then calling this method has no effect.
      See Also:
    • requestComponentFocus

      public final void requestComponentFocus(Attribute<?> attribute)
      Request focus for the component associated with the given attribute. If no component is associated with the attribute calling this method has no effect. Uses JComponent.requestFocusInWindow().
      Parameters:
      attribute - the attribute of the component to select
    • selectInputComponent

      public final void selectInputComponent()
      Displays a dialog allowing the user the select an input component which should receive the keyboard focus. If only one input component is available then that component is selected automatically. If no component is available, f.ex. when the panel is not visible, this method does nothing.
      See Also:
    • selectableComponents

      protected final ValueSet<Attribute<?>> selectableComponents()
      Specifies the attributes that should be included when presenting a component selection list. Remove an attribute to exclude it from component selection.
      Returns:
      the ValueSet specifying attributes that should be included in component selection
      See Also:
    • onException

      protected void onException(Exception exception)
      Handles the given exception, simply displays the error message to the user by default. Note that this method does nothing in case of a CancelException.
      Parameters:
      exception - the exception to handle
      See Also:
    • component

      protected final Value<JComponent> component(Attribute<?> attribute)
      Parameters:
      attribute - the attribute
      Returns:
      the Value containing the component associated with the given attribute
    • initialFocusComponent

      protected final Value<JComponent> initialFocusComponent()
      Sets the component that should receive the focus when the UI is cleared or activated. Takes precedence over the one set via initialFocusAttribute()
      Returns:
      the Value controlling the initial focus component
    • initialFocusAttribute

      protected final Value<Attribute<?>> initialFocusAttribute()
      Sets the component associated with the given attribute as the component that should receive the initial focus in this edit panel. This is overridden by initialFocusComponent().
      Returns:
      the Value controlling the initial focus attribute
      See Also:
    • afterInsertFocusComponent

      protected final Value<JComponent> afterInsertFocusComponent()
      Sets the component that should receive the focus after an insert has been performed. Takes precedence over the one set via afterInsertFocusAttribute()
      Returns:
      the Value controlling the after insert focus component
    • afterInsertFocusAttribute

      protected final Value<Attribute<?>> afterInsertFocusAttribute()
      Sets the component associated with the given attribute as the component that should receive the focus after an insert is performed in this edit panel. This is overridden by afterInsertFocusComponent().
      Returns:
      the Value controlling the after insert focus attribute
      See Also:
    • displayException

      protected final void displayException(Exception exception)
      Displays the exception in a dialog
      Parameters:
      exception - the exception to display
    • defaults

      protected final EntityEditComponentPanel.Defaults defaults()
      Returns:
      the EntityEditComponentPanel.Defaults instance for this edit component panel
    • modifiedIndicator

      protected final State modifiedIndicator()
      If set to true then component labels will indicate that the value is modified. This applies to all components created by this edit component panel as well as components set via component(Attribute) as long as the component has a JLabel associated with its 'labeledBy' client property. Note that changing this has no effect on components that have already been created.
      Returns:
      the State controlling whether components display an indicator if the value is modified
      See Also:
    • transferFocusOnEnter

      protected final State transferFocusOnEnter()
      If set to true then components created subsequently will transfer focus on enter, otherwise not. Note that changing this has no effect on components that have already been created.
      Returns:
      the State controlling whether components transfer focus on enter
      See Also:
    • addInputPanel

      protected final void addInputPanel(Attribute<?> attribute)
      Adds a panel for the given attribute to this panel
      Parameters:
      attribute - the attribute
      See Also:
    • addInputPanel

      protected final void addInputPanel(Attribute<?> attribute, Object constraints)
      Adds a panel for the given attribute to this panel using the given layout constraints
      Parameters:
      attribute - the attribute
      constraints - the layout constraints
      See Also:
    • addInputPanel

      protected final void addInputPanel(Attribute<?> attribute, JComponent inputComponent)
      Adds a panel for the given attribute to this panel
      Parameters:
      attribute - the attribute
      inputComponent - a component bound to attribute
      See Also:
    • addInputPanel

      protected final void addInputPanel(Attribute<?> attribute, JComponent inputComponent, Object constraints)
      Adds a panel for the given attribute to this panel using the given layout constraints
      Parameters:
      attribute - the attribute
      inputComponent - a component bound to attribute
      constraints - the layout constraints
      See Also:
    • createInputPanel

      protected final JPanel createInputPanel(Attribute<?> attribute)
      Creates a panel containing a label and the component associated with the given attribute. The label text is the caption defined for attribute. The default layout of the resulting panel is with the label on top and inputComponent below.
      Parameters:
      attribute - the attribute from which definition to retrieve the label caption
      Returns:
      a panel containing a label and a component
      Throws:
      IllegalArgumentException - in case no component has been associated with the given attribute
    • createInputPanel

      protected final JPanel createInputPanel(Attribute<?> attribute, JComponent inputComponent)
      Creates a panel containing a label and the component associated with the given attribute. The label text is the caption defined for attribute. The default layout of the resulting panel is with the label on top and inputComponent below.
      Parameters:
      attribute - the attribute from which definition to retrieve the label caption
      inputComponent - a component bound to the value of attribute
      Returns:
      a panel containing a label and a component
    • createInputPanel

      protected final JPanel createInputPanel(Attribute<?> attribute, JComponent inputComponent, String labelBorderLayoutConstraints)
      Creates a panel containing a label and the component associated with the given attribute. The label text is the caption defined for on attribute.
      Parameters:
      attribute - the attribute from which definition to retrieve the label caption
      inputComponent - a component bound to the value of attribute
      labelBorderLayoutConstraints - BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST or BorderLayout.WEST
      Returns:
      a panel containing a label and a component
    • createInputPanel

      protected final JPanel createInputPanel(Attribute<?> attribute, JComponent inputComponent, String labelBorderLayoutConstraints, int labelAlignment)
      Creates a panel containing a label and the given component. The label text is the caption of attribute.
      Parameters:
      attribute - the attribute from which definition to retrieve the label caption
      inputComponent - a component bound to the value of attribute
      labelBorderLayoutConstraints - BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST or BorderLayout.WEST
      labelAlignment - the label alignment
      Returns:
      a panel containing a label and a component
    • createInputPanel

      protected final JPanel createInputPanel(JComponent labelComponent, JComponent inputComponent)
      Creates a panel containing a label component and the inputComponent with the label component positioned above the input component.
      Parameters:
      labelComponent - the label component
      inputComponent - a input component
      Returns:
      a panel containing a label and a component
    • createInputPanel

      protected final JPanel createInputPanel(JComponent labelComponent, JComponent inputComponent, String labelBorderLayoutConstraints)
      Creates a panel with a BorderLayout, with the inputComponent at BorderLayout.CENTER and the labelComponent at a specified location.
      Parameters:
      labelComponent - the label component
      inputComponent - a input component
      labelBorderLayoutConstraints - BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST or BorderLayout.WEST
      Returns:
      a panel containing a label and a component
    • createTextArea

      protected final TextAreaBuilder createTextArea(Attribute<String> attribute)
      Creates a builder for text areas.
      Parameters:
      attribute - the attribute for which to build a text area
      Returns:
      a text area builder
    • createTextFieldPanel

      protected final TextFieldPanel.Builder createTextFieldPanel(Attribute<String> attribute)
      Creates a builder for text field panels.
      Parameters:
      attribute - the attribute for which to build a text field panel
      Returns:
      a text field panel builder
    • createTemporalFieldPanel

      protected final <T extends Temporal> TemporalFieldPanel.Builder<T> createTemporalFieldPanel(Attribute<T> attribute)
      Creates a builder for temporal field panels.
      Type Parameters:
      T - the temporal type
      Parameters:
      attribute - the attribute for which to build a temporal field panel
      Returns:
      a text area builder
    • createTextField

      protected final <T, C extends JTextField, B extends TextFieldBuilder<T, C, B>> TextFieldBuilder<T,C,B> createTextField(Attribute<T> attribute)
      Creates a builder for text fields.
      Type Parameters:
      T - the value type
      C - the text field type
      B - the builder type
      Parameters:
      attribute - the attribute for which to build a text field
      Returns:
      a text field builder
    • createTemporalField

      protected final <T extends Temporal> TemporalField.Builder<T> createTemporalField(Attribute<T> attribute)
      Creates a builder for temporal fields.
      Type Parameters:
      T - the temporal type
      Parameters:
      attribute - the attribute for which to build a temporal field
      Returns:
      an offset date time field builder
    • createSlider

      protected final SliderBuilder createSlider(Attribute<Integer> attribute)
      Creates a builder for a slider
      Parameters:
      attribute - the attribute
      Returns:
      a slider builder
    • createIntegerSpinner

      protected final NumberSpinnerBuilder<Integer> createIntegerSpinner(Attribute<Integer> attribute)
      Creates a builder for a spinner
      Parameters:
      attribute - the attribute
      Returns:
      a spinner builder
    • createDoubleSpinner

      protected final NumberSpinnerBuilder<Double> createDoubleSpinner(Attribute<Double> attribute)
      Creates a builder for a spinner
      Parameters:
      attribute - the attribute
      Returns:
      a spinner builder
    • createListSpinner

      protected final <T> ListSpinnerBuilder<T> createListSpinner(Attribute<T> attribute, SpinnerListModel spinnerListModel)
      Creates a builder for a list spinner
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      spinnerListModel - the spinner model
      Returns:
      a spinner builder
    • createItemSpinner

      protected final <T> ItemSpinnerBuilder<T> createItemSpinner(Attribute<T> attribute)
      Creates a builder for a list spinner
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      a spinner builder
    • createIntegerField

      protected final NumberField.Builder<Integer> createIntegerField(Attribute<Integer> attribute)
      Creates a builder for integer fields.
      Parameters:
      attribute - the attribute for which to build a text field
      Returns:
      a integer field builder
    • createLongField

      protected final NumberField.Builder<Long> createLongField(Attribute<Long> attribute)
      Creates a builder for long fields.
      Parameters:
      attribute - the attribute for which to build a text field
      Returns:
      a long field builder
    • createDoubleField

      protected final NumberField.Builder<Double> createDoubleField(Attribute<Double> attribute)
      Creates a builder for double fields.
      Parameters:
      attribute - the attribute for which to build a text field
      Returns:
      a double field builder
    • createBigDecimalField

      protected final NumberField.Builder<BigDecimal> createBigDecimalField(Attribute<BigDecimal> attribute)
      Creates a builder for big decimal fields.
      Parameters:
      attribute - the attribute for which to build a text field
      Returns:
      a big decimal field builder
    • createMaskedTextField

      protected final MaskedTextFieldBuilder createMaskedTextField(Attribute<String> attribute)
      Creates a builder for formatted text fields.
      Parameters:
      attribute - the attribute for which to build a formatted text field
      Returns:
      a formatted text field builder
    • createCheckBox

      protected final CheckBoxBuilder createCheckBox(Attribute<Boolean> attribute)
      Creates a builder for check boxes. If CheckBoxBuilder.nullable(boolean) is set to true, a NullableCheckBox is built.
      Parameters:
      attribute - the attribute for which to build a check-box
      Returns:
      a check-box builder
    • createBooleanComboBox

      protected final ItemComboBoxBuilder<Boolean> createBooleanComboBox(Attribute<Boolean> attribute)
      Creates a builder for boolean combo boxes.
      Parameters:
      attribute - the attribute for which to build boolean combo box
      Returns:
      a boolean combo box builder
    • createComboBox

      protected final <T, C extends JComboBox<T>, B extends ComboBoxBuilder<T, C, B>> ComboBoxBuilder<T,C,B> createComboBox(Attribute<T> attribute, ComboBoxModel<T> comboBoxModel)
      Creates a builder for combo boxes.
      Type Parameters:
      T - the value type
      C - the component type
      B - the builder type
      Parameters:
      attribute - the attribute for which to build combo box
      comboBoxModel - the combo box model
      Returns:
      a combo box builder
    • createItemComboBox

      protected final <T> ItemComboBoxBuilder<T> createItemComboBox(Attribute<T> attribute)
      Creates a builder for value item list combo boxes.
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute for which to build a value list combo box
      Returns:
      a value item list combo box builder
    • createComboBox

      protected final <T, C extends JComboBox<T>, B extends ComboBoxBuilder<T, C, B>> ComboBoxBuilder<T,C,B> createComboBox(Column<T> column)
      Creates a builder for a combo boxe, containing the values of the given column.
      Type Parameters:
      T - the value type
      C - the component type
      B - the builder type
      Parameters:
      column - the column for which to build a combo box
      Returns:
      a combo box builder
    • createForeignKeyComboBox

      protected final EntityComboBox.Builder createForeignKeyComboBox(ForeignKey foreignKey)
      Creates a builder for foreign key combo boxes.
      Parameters:
      foreignKey - the foreign key for which to build a combo box
      Returns:
      a foreign key combo box builder
    • createForeignKeyComboBoxPanel

      protected final EntityComboBoxPanel.Builder createForeignKeyComboBoxPanel(ForeignKey foreignKey, Supplier<EntityEditPanel> editPanel)
      Creates a builder for a foreign key combo box panel with optional buttons for adding and editing items.
      Parameters:
      foreignKey - the foreign key
      editPanel - supplies the edit panel to use for the add and/or edit buttons
      Returns:
      a foreign key combo box panel builder
    • createForeignKeySearchField

      protected final EntitySearchField.Builder createForeignKeySearchField(ForeignKey foreignKey)
      Creates a builder for foreign key search fields.
      Parameters:
      foreignKey - the foreign key for which to build a search field
      Returns:
      a foreign key search field builder
    • createForeignKeySearchFieldPanel

      protected final EntitySearchFieldPanel.Builder createForeignKeySearchFieldPanel(ForeignKey foreignKey)
      Creates a builder for a foreign key search field panel with an optional button for performing a search.
      Parameters:
      foreignKey - the foreign key
      Returns:
      a foreign key combo box panel builder
    • createForeignKeySearchFieldPanel

      protected final EntitySearchFieldPanel.Builder createForeignKeySearchFieldPanel(ForeignKey foreignKey, Supplier<EntityEditPanel> editPanel)
      Creates a builder for a foreign key search field panel with optional buttons for adding and editing items.
      Parameters:
      foreignKey - the foreign key
      editPanel - the edit panel supplier to use for the add and/or edit buttons
      Returns:
      a foreign key combo box panel builder
    • createForeignKeyTextField

      protected final <B extends TextFieldBuilder<Entity, JTextField, B>> TextFieldBuilder<Entity,JTextField,B> createForeignKeyTextField(ForeignKey foreignKey)
      Creates a builder for a read-only, non-focusable foreign key text field.
      Type Parameters:
      B - the builder type
      Parameters:
      foreignKey - the foreign key for which to build a text field
      Returns:
      a foreign key text field builder
    • createList

      protected final <T> EntityComponents.EntityListBuilderFactory<T> createList(ListModel<T> listModel)
      Creates a list builder factory
      Type Parameters:
      T - the value type
      Parameters:
      listModel - the list model to base the list on
      Returns:
      a list builder factory
    • createForeignKeyLabel

      protected final LabelBuilder<Entity> createForeignKeyLabel(ForeignKey foreignKey)
      Creates a builder for a read-only foreign key label.
      Parameters:
      foreignKey - the foreign key for which to build a label
      Returns:
      a foreign key label builder
    • createLabel

      protected final <T> LabelBuilder<T> createLabel(Attribute<T> attribute)
      Creates a builder for a label using the caption and mnemonic associated with attribute. If an input component exists for the given attribute the label is associated with it via JLabel.setLabelFor(Component).
      Type Parameters:
      T - the attribute type
      Parameters:
      attribute - the attribute from which to retrieve the caption
      Returns:
      a label builder for the given attribute
    • getInitialFocusComponent

      protected JComponent getInitialFocusComponent()
      Returns:
      the component that should receive the initial focus when the UI is initialized
    • getAfterInsertFocusComponent

      protected JComponent getAfterInsertFocusComponent()
      Returns:
      the component that should receive the focus when the UI is initialized after insert
    • requestAfterInsertFocus

      protected final void requestAfterInsertFocus()
      Request focus after an insert operation
      See Also:
    • requestAfterUpdateFocus

      protected final void requestAfterUpdateFocus()
      Request focus after an update operation
    • addValidator

      protected final <T> void addValidator(Attribute<T> attribute, JTextComponent textComponent)
      Adds a validator to the given text component
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute of the value to validate
      textComponent - the text component
    • addValidator

      protected final <T> void addValidator(Attribute<T> attribute, JComboBox<?> comboBox)
      Adds a validator to the given combo box
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute of the value to validate
      comboBox - the combo box