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 SummaryNested Classes Modifier and Type Class Description static classBindingContext.SilentProblemHandlerstatic classBindingContext.VerbousProblemHandler
 - 
Constructor SummaryConstructors Constructor Description BindingContext()Constructor.BindingContext(PropertySet propertySet)Constructor.BindingContext(PropertySet propertySet, BindingProblemListener problemHandler)Constructor.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProblemListener(BindingProblemListener listener)Adds a problem listener to this context.voidaddPropertyChangeListener(PropertyChangeListener l)Shortcut forgetPropertyContainer().addPropertyChangeListener(l.voidaddPropertyChangeListener(String name, PropertyChangeListener l)Shortcut forgetPropertyContainer().addPropertyChangeListener(name, l.voidadjustComponents()Adjusts all associated GUI components so that they reflect the values of the associated value container.Bindingbind(String propertyName, ComponentAdapter componentAdapter)Binds the property given by its name to the given component adapter.Bindingbind(String propertyName, ButtonGroup buttonGroup)Binds a property in the value container to a SwingButtonGroup.Bindingbind(String propertyName, ButtonGroup buttonGroup, Map<AbstractButton,Object> valueSet)Binds a property in the value container to a SwingButtonGroup.Bindingbind(String propertyName, JCheckBox component)Binds a property in the value container to a SwingJCheckBoxcomponent.Bindingbind(String propertyName, JComboBox component)Binds a property in the value container to a SwingJComboBoxcomponent.Bindingbind(String propertyName, JFormattedTextField component)Binds a property in the value container to a SwingJFormattedTextFieldcomponent.Bindingbind(String propertyName, JList component, boolean selectionIsValue)Binds a property in the value container to a SwingJListcomponent.Bindingbind(String propertyName, JRadioButton component)Binds a property in the value container to a SwingJRadioButtoncomponent.Bindingbind(String propertyName, JSpinner component)Binds a property in the value container to a SwingJSpinnercomponent.Bindingbind(String propertyName, JTextField component)Binds a property in the value container to a SwingJTextFieldcomponent.Bindingbind(String propertyName, JTextComponent component)Binds a property in the value container to a SwingJTextComponentcomponent.EnablementbindEnabledState(String targetPropertyName, boolean targetState, Enablement.Condition condition)Sets the enabled state of the components associated withtargetPropertytotargetStateif a certainconditionis met.EnablementbindEnabledState(String targetPropertyName, boolean targetState, String sourcePropertyName, Object sourcePropertyValue)Sets the enabled state of the components associated withtargetProperty.EnablementbindEnabledState(String targetPropertyName, String sourcePropertyName)Sets the enabled state of the components associated withtargetProperty.BindinggetBinding(String propertyName)Gets the binding for the given property name.BindingProblemListener[]getProblemListeners()BindingProblem[]getProblems()PropertySetgetPropertySet()booleanhasProblems()voidpermitPropertyChanges(JComponent component)Permits component validation and property changes of the value container triggered by the given component.voidpreventPropertyChanges(JComponent component)Prevents component validation and property changes of the value container triggered by the given component.voidremoveProblemListener(BindingProblemListener listener)Removes a problem listener from this context.voidremovePropertyChangeListener(PropertyChangeListener l)Shortcut forgetPropertyContainer().removePropertyChangeListener(l.voidremovePropertyChangeListener(String name, PropertyChangeListener l)voidsetComponentsEnabled(String propertyName, boolean enabled)voidunbind(Binding binding)Cancels the given binding by calling removing it from this context and finally callingcomponentAdapter.unbindComponents()componentAdapter.setBinding(null)
 
- 
- 
- 
Constructor Detail- 
BindingContextpublic BindingContext() Constructor. Uses an empty, default property set and a default problem handler which will display an error dialog box on any binding errors.
 - 
BindingContextpublic 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.
 
 - 
BindingContextpublic BindingContext(PropertySet propertySet, BindingProblemListener problemHandler) Constructor.- Parameters:
- propertySet- The property set.
- problemHandler- A problem handler, or- null.
 
 
- 
 - 
Method Detail- 
getPropertySetpublic PropertySet getPropertySet() - Returns:
- The property set.
 
 - 
hasProblemspublic boolean hasProblems() - Returns:
- trueif this context has problems.
- Since:
- Ceres 0.10
 
 - 
getProblemspublic BindingProblem[] getProblems() - Returns:
- The array of problems this context might have.
- Since:
- Ceres 0.10
 
 - 
addProblemListenerpublic void addProblemListener(BindingProblemListener listener) Adds a problem listener to this context.- Parameters:
- listener- The listener.
- Since:
- Ceres 0.10
 
 - 
removeProblemListenerpublic void removeProblemListener(BindingProblemListener listener) Removes a problem listener from this context.- Parameters:
- listener- The listener.
- Since:
- Ceres 0.10
 
 - 
getProblemListenerspublic BindingProblemListener[] getProblemListeners() - Returns:
- The array of problem listeners.
- Since:
- Ceres 0.10
 
 - 
adjustComponentspublic void adjustComponents() Adjusts all associated GUI components so that they reflect the values of the associated value container.- See Also:
- ComponentAdapter.adjustComponents()
 
 - 
getBindingpublic Binding getBinding(String propertyName) Gets the binding for the given property name.- Parameters:
- propertyName- The property name.
- Returns:
- The binding, or nullif no such exists.
 
 - 
bindpublic 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)
 
 - 
unbindpublic 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)
 
 - 
bindpublic Binding bind(String propertyName, JTextComponent component) Binds a property in the value container to a SwingJTextComponentcomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic Binding bind(String propertyName, JTextField component) Binds a property in the value container to a SwingJTextFieldcomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic Binding bind(String propertyName, JFormattedTextField component) Binds a property in the value container to a SwingJFormattedTextFieldcomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic Binding bind(String propertyName, JCheckBox component) Binds a property in the value container to a SwingJCheckBoxcomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic Binding bind(String propertyName, JRadioButton component) Binds a property in the value container to a SwingJRadioButtoncomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic Binding bind(String propertyName, JList component, boolean selectionIsValue) Binds a property in the value container to a SwingJListcomponent.- 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.
 
 - 
bindpublic Binding bind(String propertyName, JSpinner component) Binds a property in the value container to a SwingJSpinnercomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic Binding bind(String propertyName, JComboBox component) Binds a property in the value container to a SwingJComboBoxcomponent.- Parameters:
- propertyName- The property name.
- component- The Swing component.
- Returns:
- The resulting binding.
 
 - 
bindpublic 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.
 
 - 
bindpublic 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.
 
 - 
addPropertyChangeListenerpublic void addPropertyChangeListener(PropertyChangeListener l) Shortcut forgetPropertyContainer().addPropertyChangeListener(l.- Parameters:
- l- The property change listener.
 
 - 
addPropertyChangeListenerpublic void addPropertyChangeListener(String name, PropertyChangeListener l) Shortcut forgetPropertyContainer().addPropertyChangeListener(name, l.- Parameters:
- name- The property name.
- l- The property change listener.
 
 - 
removePropertyChangeListenerpublic void removePropertyChangeListener(PropertyChangeListener l) Shortcut forgetPropertyContainer().removePropertyChangeListener(l.- Parameters:
- l- The property change listener.
 
 - 
removePropertyChangeListenerpublic void removePropertyChangeListener(String name, PropertyChangeListener l) - Parameters:
- name- The property name.
- l- The property change listener.
 
 - 
permitPropertyChangespublic 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()
 
 - 
preventPropertyChangespublic 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()
 
 - 
bindEnabledStatepublic 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.
 
 - 
bindEnabledStatepublic Enablement bindEnabledState(String targetPropertyName, boolean targetState, String sourcePropertyName, Object sourcePropertyValue) Sets the enabled state of the components associated withtargetProperty. If the current value ofsourcePropertyequalssourcePropertyValuethen 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.
 
 - 
bindEnabledStatepublic Enablement bindEnabledState(String targetPropertyName, boolean targetState, Enablement.Condition condition) Sets the enabled state of the components associated withtargetPropertytotargetStateif a certainconditionis met.- Parameters:
- targetPropertyName- The name of the target property.
- targetState- The target enabled state.
- condition- The condition.
 
 - 
setComponentsEnabledpublic void setComponentsEnabled(String propertyName, boolean enabled) 
 
- 
 
-