Package com.bc.ceres.swing.binding
Class BindingContext
java.lang.Object
com.bc.ceres.swing.binding.BindingContext
A context used to bind Swing components to properties in a value container.
- Since:
- Ceres 0.6
- Version:
- $Revision$ $Date$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.BindingContext
(PropertySet propertySet) Constructor.BindingContext
(PropertySet propertySet, BindingProblemListener problemHandler) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addProblemListener
(BindingProblemListener listener) Adds a problem listener to this context.void
Shortcut forgetPropertyContainer().addPropertyChangeListener(l
.void
Shortcut forgetPropertyContainer().addPropertyChangeListener(name, l
.void
Adjusts all associated GUI components so that they reflect the values of the associated value container.bind
(String propertyName, ComponentAdapter componentAdapter) Binds the property given by its name to the given component adapter.bind
(String propertyName, ButtonGroup buttonGroup) Binds a property in the value container to a SwingButtonGroup
.bind
(String propertyName, ButtonGroup buttonGroup, Map<AbstractButton, Object> valueSet) Binds a property in the value container to a SwingButtonGroup
.Binds a property in the value container to a SwingJCheckBox
component.Binds a property in the value container to a SwingJComboBox
component.bind
(String propertyName, JFormattedTextField component) Binds a property in the value container to a SwingJFormattedTextField
component.Binds a property in the value container to a SwingJList
component.bind
(String propertyName, JRadioButton component) Binds a property in the value container to a SwingJRadioButton
component.Binds a property in the value container to a SwingJSpinner
component.bind
(String propertyName, JTextField component) Binds a property in the value container to a SwingJTextField
component.bind
(String propertyName, JTextComponent component) Binds a property in the value container to a SwingJTextComponent
component.bindEnabledState
(String targetPropertyName, boolean targetState, Enablement.Condition condition) Sets the enabled state of the components associated withtargetProperty
totargetState
if a certaincondition
is met.bindEnabledState
(String targetPropertyName, boolean targetState, String sourcePropertyName, Object sourcePropertyValue) Sets the enabled state of the components associated withtargetProperty
.bindEnabledState
(String targetPropertyName, String sourcePropertyName) Sets the enabled state of the components associated withtargetProperty
.getBinding
(String propertyName) Gets the binding for the given property name.boolean
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
Shortcut forgetPropertyContainer().removePropertyChangeListener(l
.void
void
setComponentsEnabled
(String propertyName, boolean enabled) void
Cancels the given binding by calling removing it from this context and finally callingcomponentAdapter.unbindComponents()
componentAdapter.setBinding(null)
-
Constructor Details
-
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
Constructor. Uses a default problem handler which will display an error dialog box on any binding errors.- Parameters:
propertySet
- The property set.
-
BindingContext
Constructor.- Parameters:
propertySet
- The property set.problemHandler
- A problem handler, ornull
.
-
-
Method Details
-
getPropertySet
- Returns:
- The property set.
-
hasProblems
public boolean hasProblems()- Returns:
true
if this context has problems.- Since:
- Ceres 0.10
-
getProblems
- Returns:
- The array of problems this context might have.
- Since:
- Ceres 0.10
-
addProblemListener
Adds a problem listener to this context.- Parameters:
listener
- The listener.- Since:
- Ceres 0.10
-
removeProblemListener
Removes a problem listener from this context.- Parameters:
listener
- The listener.- Since:
- Ceres 0.10
-
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:
-
getBinding
Gets the binding for the given property name.- Parameters:
propertyName
- The property name.- Returns:
- The binding, or
null
if no such exists.
-
bind
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
Cancels the given binding by calling removing it from this context and finally calling- Parameters:
binding
- The binding.- See Also:
-
bind
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
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
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
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
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
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
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
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
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
Shortcut forgetPropertyContainer().addPropertyChangeListener(l
.- Parameters:
l
- The property change listener.
-
addPropertyChangeListener
Shortcut forgetPropertyContainer().addPropertyChangeListener(name, l
.- Parameters:
name
- The property name.l
- The property change listener.
-
removePropertyChangeListener
Shortcut forgetPropertyContainer().removePropertyChangeListener(l
.- Parameters:
l
- The property change listener.
-
removePropertyChangeListener
- Parameters:
name
- The property name.l
- The property change listener.
-
permitPropertyChanges
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
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:
-
bindEnabledState
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
-