Package com.bc.ceres.swing.binding
Class BindingContext
- java.lang.Object
-
- com.bc.ceres.swing.binding.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$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BindingContext.SilentProblemHandler
static class
BindingContext.VerbousProblemHandler
-
Constructor Summary
Constructors Constructor Description BindingContext()
Constructor.BindingContext(PropertySet propertySet)
Constructor.BindingContext(PropertySet propertySet, BindingProblemListener problemHandler)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProblemListener(BindingProblemListener listener)
Adds a problem listener to this context.void
addPropertyChangeListener(PropertyChangeListener l)
Shortcut forgetPropertyContainer().addPropertyChangeListener(l
.void
addPropertyChangeListener(String name, PropertyChangeListener l)
Shortcut forgetPropertyContainer().addPropertyChangeListener(name, l
.void
adjustComponents()
Adjusts all associated GUI components so that they reflect the values of the associated value container.Binding
bind(String propertyName, ComponentAdapter componentAdapter)
Binds the property given by its name to the given component adapter.Binding
bind(String propertyName, ButtonGroup buttonGroup)
Binds a property in the value container to a SwingButtonGroup
.Binding
bind(String propertyName, ButtonGroup buttonGroup, Map<AbstractButton,Object> valueSet)
Binds a property in the value container to a SwingButtonGroup
.Binding
bind(String propertyName, JCheckBox component)
Binds a property in the value container to a SwingJCheckBox
component.Binding
bind(String propertyName, JComboBox component)
Binds a property in the value container to a SwingJComboBox
component.Binding
bind(String propertyName, JFormattedTextField component)
Binds a property in the value container to a SwingJFormattedTextField
component.Binding
bind(String propertyName, JList component, boolean selectionIsValue)
Binds a property in the value container to a SwingJList
component.Binding
bind(String propertyName, JRadioButton component)
Binds a property in the value container to a SwingJRadioButton
component.Binding
bind(String propertyName, JSpinner component)
Binds a property in the value container to a SwingJSpinner
component.Binding
bind(String propertyName, JTextField component)
Binds a property in the value container to a SwingJTextField
component.Binding
bind(String propertyName, JTextComponent component)
Binds a property in the value container to a SwingJTextComponent
component.Enablement
bindEnabledState(String targetPropertyName, boolean targetState, Enablement.Condition condition)
Sets the enabled state of the components associated withtargetProperty
totargetState
if a certaincondition
is met.Enablement
bindEnabledState(String targetPropertyName, boolean targetState, String sourcePropertyName, Object sourcePropertyValue)
Sets the enabled state of the components associated withtargetProperty
.Enablement
bindEnabledState(String targetPropertyName, String sourcePropertyName)
Sets the enabled state of the components associated withtargetProperty
.Binding
getBinding(String propertyName)
Gets the binding for the given property name.BindingProblemListener[]
getProblemListeners()
BindingProblem[]
getProblems()
PropertySet
getPropertySet()
boolean
hasProblems()
void
permitPropertyChanges(JComponent component)
Permits component validation and property changes of the value container triggered by the given component.void
preventPropertyChanges(JComponent component)
Prevents component validation and property changes of the value container triggered by the given component.void
removeProblemListener(BindingProblemListener listener)
Removes a problem listener from this context.void
removePropertyChangeListener(PropertyChangeListener l)
Shortcut forgetPropertyContainer().removePropertyChangeListener(l
.void
removePropertyChangeListener(String name, PropertyChangeListener l)
void
setComponentsEnabled(String propertyName, boolean enabled)
void
unbind(Binding binding)
Cancels the given binding by calling removing it from this context and finally callingcomponentAdapter.unbindComponents()
componentAdapter.setBinding(null)
-
-
-
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, ornull
.
-
-
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, ComponentAdapter componentAdapter)
Binds the property given by its name to the given component adapter.The method creates a new binding, adds it to this context and calls the follwing methods on the given component adapter:
- Parameters:
propertyName
- The property name.componentAdapter
- The component adapter.- Returns:
- The resulting binding.
- See Also:
unbind(Binding)
-
unbind
public void unbind(Binding binding)
Cancels the given binding by calling removing it from this context and finally calling- Parameters:
binding
- The binding.- See Also:
bind(String, ComponentAdapter)
-
bind
public Binding bind(String propertyName, JTextComponent component)
Binds a property in the value container to a SwingJTextComponent
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 SwingJTextField
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 SwingJFormattedTextField
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 SwingJCheckBox
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 SwingJRadioButton
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 SwingJList
component.- Parameters:
propertyName
- The property name.component
- The Swing component.selectionIsValue
- iftrue
, the current list selection provides the value, iffalse
, 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 SwingJSpinner
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 SwingJComboBox
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 SwingButtonGroup
.- 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 SwingButtonGroup
.- Parameters:
propertyName
- The property name.buttonGroup
- The button group.valueSet
- The mapping from a button to the actual property value.- Returns:
- The resulting binding.
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener l)
Shortcut forgetPropertyContainer().addPropertyChangeListener(l
.- Parameters:
l
- The property change listener.
-
addPropertyChangeListener
public void addPropertyChangeListener(String name, PropertyChangeListener l)
Shortcut forgetPropertyContainer().addPropertyChangeListener(name, l
.- Parameters:
name
- The property name.l
- The property change listener.
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Shortcut forgetPropertyContainer().removePropertyChangeListener(l
.- Parameters:
l
- The property change listener.
-
removePropertyChangeListener
public void removePropertyChangeListener(String name, PropertyChangeListener l)
- Parameters:
name
- The property name.l
- The property change listener.
-
permitPropertyChanges
public void permitPropertyChanges(JComponent component)
Permits component validation and property changes of the value container triggered by the given component.- Parameters:
component
- The component.- Since:
- Ceres 0.10
- See Also:
preventPropertyChanges(javax.swing.JComponent)
,getPropertySet()
-
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, String sourcePropertyName)
Sets the enabled state of the components associated withtargetProperty
. Enablement of the target property matches that of the source property.- Parameters:
targetPropertyName
- The name of the target property.sourcePropertyName
- The name of the source property.
-
bindEnabledState
public Enablement bindEnabledState(String targetPropertyName, boolean targetState, String sourcePropertyName, Object sourcePropertyValue)
Sets the enabled state of the components associated withtargetProperty
. If the current value ofsourceProperty
equalssourcePropertyValue
then the enabled state will be set to the value ofenabled
, otherwise it is the negated value ofenabled
. 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 withtargetProperty
totargetState
if a certaincondition
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)
-
-