Class BindingContext


  • public class BindingContext
    extends Object
    A context used to bind Swing components to properties in a value container.
    Since:
    Ceres 0.6
    Version:
    $Revision$ $Date$
    • Constructor Detail

      • BindingContext

        public BindingContext()
        Constructor. Uses an empty, default property set and a default problem handler which will display an error dialog box on any binding errors.
      • BindingContext

        public BindingContext​(PropertySet propertySet)
        Constructor. Uses a default problem handler which will display an error dialog box on any binding errors.
        Parameters:
        propertySet - The property set.
      • BindingContext

        public BindingContext​(PropertySet propertySet,
                              BindingProblemListener problemHandler)
        Constructor.
        Parameters:
        propertySet - The property set.
        problemHandler - A problem handler, or null.
    • Method Detail

      • getPropertySet

        public PropertySet getPropertySet()
        Returns:
        The property set.
      • hasProblems

        public boolean hasProblems()
        Returns:
        true if this context has problems.
        Since:
        Ceres 0.10
      • getProblems

        public BindingProblem[] getProblems()
        Returns:
        The array of problems this context might have.
        Since:
        Ceres 0.10
      • addProblemListener

        public void addProblemListener​(BindingProblemListener listener)
        Adds a problem listener to this context.
        Parameters:
        listener - The listener.
        Since:
        Ceres 0.10
      • removeProblemListener

        public void removeProblemListener​(BindingProblemListener listener)
        Removes a problem listener from this context.
        Parameters:
        listener - The listener.
        Since:
        Ceres 0.10
      • getProblemListeners

        public BindingProblemListener[] getProblemListeners()
        Returns:
        The array of problem listeners.
        Since:
        Ceres 0.10
      • adjustComponents

        public void adjustComponents()
        Adjusts all associated GUI components so that they reflect the values of the associated value container.
        See Also:
        ComponentAdapter.adjustComponents()
      • getBinding

        public Binding getBinding​(String propertyName)
        Gets the binding for the given property name.
        Parameters:
        propertyName - The property name.
        Returns:
        The binding, or null if no such exists.
      • bind

        public Binding bind​(String propertyName,
                            JTextComponent component)
        Binds a property in the value container to a Swing JTextComponent component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JTextField component)
        Binds a property in the value container to a Swing JTextField component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JFormattedTextField component)
        Binds a property in the value container to a Swing JFormattedTextField component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JCheckBox component)
        Binds a property in the value container to a Swing JCheckBox component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JRadioButton component)
        Binds a property in the value container to a Swing JRadioButton component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JList component,
                            boolean selectionIsValue)
        Binds a property in the value container to a Swing JList component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        selectionIsValue - if true, the current list selection provides the value, if false, the list content is the value.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JSpinner component)
        Binds a property in the value container to a Swing JSpinner component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            JComboBox component)
        Binds a property in the value container to a Swing JComboBox component.
        Parameters:
        propertyName - The property name.
        component - The Swing component.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            ButtonGroup buttonGroup)
        Binds a property in the value container to a Swing ButtonGroup.
        Parameters:
        propertyName - The property name.
        buttonGroup - The button group.
        Returns:
        The resulting binding.
      • bind

        public Binding bind​(String propertyName,
                            ButtonGroup buttonGroup,
                            Map<AbstractButton,​Object> valueSet)
        Binds a property in the value container to a Swing ButtonGroup.
        Parameters:
        propertyName - The property name.
        buttonGroup - The button group.
        valueSet - The mapping from a button to the actual property value.
        Returns:
        The resulting binding.
      • preventPropertyChanges

        public void preventPropertyChanges​(JComponent component)
        Prevents component validation and property changes of the value container triggered by the given component.

        For example, if a text component loses keyboard focus because another component requests it, its text value will be converted, validated and the value container's property will be changed. For some focus targets, like a dialog's "Cancel" button, this is not desired.

        By default, component validation and property changes are permitted for most Swing components.

        Parameters:
        component - The component.
        Since:
        Ceres 0.10
        See Also:
        permitPropertyChanges(javax.swing.JComponent), getPropertySet()
      • bindEnabledState

        public Enablement bindEnabledState​(String targetPropertyName,
                                           boolean targetState,
                                           String sourcePropertyName,
                                           Object sourcePropertyValue)
        Sets the enabled state of the components associated with targetProperty. If the current value of sourceProperty equals sourcePropertyValue then the enabled state will be set to the value of enabled, otherwise it is the negated value of enabled. Neither the source property nor the target property need to have an active binding.
        Parameters:
        targetPropertyName - The name of the target property.
        targetState - The enabled state.
        sourcePropertyName - The name of the source property.
        sourcePropertyValue - The value of the source property.
      • bindEnabledState

        public Enablement bindEnabledState​(String targetPropertyName,
                                           boolean targetState,
                                           Enablement.Condition condition)
        Sets the enabled state of the components associated with targetProperty to targetState if a certain condition is met.
        Parameters:
        targetPropertyName - The name of the target property.
        targetState - The target enabled state.
        condition - The condition.
      • setComponentsEnabled

        public void setComponentsEnabled​(String propertyName,
                                         boolean enabled)