com.jgoodies.binding.binder
Class ValueModelBindingBuilderImpl

java.lang.Object
  extended by com.jgoodies.binding.binder.ValueModelBindingBuilderImpl
All Implemented Interfaces:
ValueModelBindingBuilder

public class ValueModelBindingBuilderImpl
extends Object
implements ValueModelBindingBuilder

A binding builder that holds a ValueModel that can be bound to a variety of components. Also provides methods that operate on the ValueModel (conversion) or create a SelectionInListBuilder that in turn can be bound to combo boxes, lists, and tables.

It is recommended to create this builder with an optional property name. If such a name is available, it is set a default validation message key for components that are bound with this builder.

Since:
2.3
Version:
$Revision: 1.14 $
Author:
Karsten Lentzsch

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.jgoodies.binding.binder.ValueModelBindingBuilder
ValueModelBindingBuilder.Commit
 
Constructor Summary
ValueModelBindingBuilderImpl(ValueModel valueModel)
          Creates a ValueModelBindingBuilderImpl for the given ValueModel.
ValueModelBindingBuilderImpl(ValueModel valueModel, String propertyName)
          Creates a ValueModelBindingBuilderImpl for the given ValueModel using the given bean property name.
 
Method Summary
<E> SelectionInListBindingBuilder
asSelectionIn(E[] array)
          Creates and returns a SelectionInListBindingBuilder on a SelectionInList with this builder's ValueModel as selection holder and the given array as list.
<E> SelectionInListBindingBuilder
asSelectionIn(List<E> list)
          Creates and returns a SelectionInListBindingBuilder on a SelectionInList with this builder's ValueModel as selection holder and the given list as list elements.
<E> SelectionInListBindingBuilder
asSelectionIn(ListModel listModel)
          Creates and returns a SelectionInListBindingBuilder on a SelectionInList with this builder's ValueModel as selection holder and the given ListModel as list data provider.
 ValueModelBindingBuilder converted(BindingConverter converter)
          Wraps this builder's ValueModel with a converting ValueModel and creates and returns another ValueModelBindingBuilder with the wrapped ValueModel.
 ValueModelBindingBuilder formatted(Format format)
          Wraps this builder's ValueModel with a string converter and creates and returns another ValueModelBindingBuilder with the wrapped ValueModel.
protected  String getPropertyName()
           
protected  ValueModel getValueModel()
           
protected  void setValidationMessageKey(JComponent comp)
          Sets this builder's property name - if any - as the component's validation message key.
 void to(AbstractButton toggleButton)
          Binds this builder's ValueModel to the given toggle button, for example a check box.
 void to(AbstractButton toggleButton, Object choice)
          Binds this builder's ValueModel to the given toggle button (radio button style) that is selected, if and only if the model's value equals the given choice.
 void to(AbstractButton toggleButton, Object selectedValue, Object deselectedValue)
          Binds this builder's ValueModel to the given toggle button, for example a check box.
 void to(JFormattedTextField formattedTextField)
          Binds this builder's ValueModel to the given formatted text field.
 void to(JLabel label)
          Binds this builder's ValueModel to the given text label.
 void to(JTextArea textArea)
          Binds this builder's ValueModel to the given text area and commits text changes on focus lost.
 void to(JTextArea textArea, ValueModelBindingBuilder.Commit commitType)
          Binds this builder's ValueModel to the given text area using the specified commit type.
 void to(JTextField textField)
          Binds this builder's ValueModel to the given text field and commits text changes on focus lost.
 void to(JTextField textField, ValueModelBindingBuilder.Commit commitType)
          Binds this builder's ValueModel to the given text field using the specified commit type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValueModelBindingBuilderImpl

public ValueModelBindingBuilderImpl(ValueModel valueModel)
Creates a ValueModelBindingBuilderImpl for the given ValueModel. It is recommended to favor the constructor ValueModelBindingBuilderImpl(ValueModel, String) where the property name is set.

Parameters:
valueModel - the ValueModel to be managed and bound
Throws:
NullPointerException - if valueModel is null

ValueModelBindingBuilderImpl

public ValueModelBindingBuilderImpl(ValueModel valueModel,
                                    String propertyName)
Creates a ValueModelBindingBuilderImpl for the given ValueModel using the given bean property name.

Parameters:
valueModel - the ValueModel to be managed and bound
propertyName - the bean property name that has been used to create the ValueModel from
Throws:
NullPointerException - if valueModel is null
IllegalArgumentException - if propertyName is empty or whitespace
Method Detail

converted

public ValueModelBindingBuilder converted(BindingConverter converter)
Description copied from interface: ValueModelBindingBuilder
Wraps this builder's ValueModel with a converting ValueModel and creates and returns another ValueModelBindingBuilder with the wrapped ValueModel.

Example:
binder.bindBeanProperty("price").converted(currencyConverter).to(priceField);

The ConverterFactory provides a bunch of prepared converters.

When binding non-String values to a text UI component, consider using a JFormattedTextField. Formatted text fields provide a powerful means to convert strings to objects and handle many cases that arise around invalid input.

Specified by:
converted in interface ValueModelBindingBuilder
Parameters:
converter - converts values from the source to the target and vice versa
Returns:
a ValueModelBindingBuilder on a converter that wraps this builder's ValueModel

formatted

public ValueModelBindingBuilder formatted(Format format)
Description copied from interface: ValueModelBindingBuilder
Wraps this builder's ValueModel with a string converter and creates and returns another ValueModelBindingBuilder with the wrapped ValueModel.

Example:
binder.bindBeanProperty("count").formatted(percentFormat).to(percentField);

Specified by:
formatted in interface ValueModelBindingBuilder
Parameters:
format - implements the String conversion via #format and #parse
Returns:
a ValueModelBindingBuilder on a converter that wraps this builder's String ValueModel

asSelectionIn

public <E> SelectionInListBindingBuilder asSelectionIn(E[] array)
Description copied from interface: ValueModelBindingBuilder
Creates and returns a SelectionInListBindingBuilder on a SelectionInList with this builder's ValueModel as selection holder and the given array as list.

Example:
binder.bindBeanProperty("country").asSelectionIn(COUNTRIES).to(countryCombo);

Specified by:
asSelectionIn in interface ValueModelBindingBuilder
Type Parameters:
E - the type of the list elements
Parameters:
array - the list data for the SelectionInList
Returns:
a SelectionInListBindingBuilder on a SelectionInList where this builder's ValueModel is the selection holder

asSelectionIn

public <E> SelectionInListBindingBuilder asSelectionIn(List<E> list)
Description copied from interface: ValueModelBindingBuilder
Creates and returns a SelectionInListBindingBuilder on a SelectionInList with this builder's ValueModel as selection holder and the given list as list elements.

Example:
binder.bindBeanProperty("country").asSelectionIn(COUNTRIES).to(countryCombo);

Specified by:
asSelectionIn in interface ValueModelBindingBuilder
Type Parameters:
E - the type of the list elements
Parameters:
list - the list data for the SelectionInList
Returns:
a SelectionInListBindingBuilder on a SelectionInList where this builder's ValueModel is the selection holder

asSelectionIn

public <E> SelectionInListBindingBuilder asSelectionIn(ListModel listModel)
Description copied from interface: ValueModelBindingBuilder
Creates and returns a SelectionInListBindingBuilder on a SelectionInList with this builder's ValueModel as selection holder and the given ListModel as list data provider.

Example:
binder.bindBeanProperty("country").asSelectionIn(COUNTRIES).to(countryCombo);

Specified by:
asSelectionIn in interface ValueModelBindingBuilder
Type Parameters:
E - the type of the list elements
Parameters:
listModel - the list data for the SelectionInList
Returns:
a SelectionInListBindingBuilder on a SelectionInList where this builder's ValueModel is the selection holder

to

public void to(AbstractButton toggleButton)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given toggle button, for example a check box.

Example:
binder.bindBeanProperty("classical").to(classicalBox);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
toggleButton - the button to be bound to this builder's ValueModel
See Also:
Bindings.bind(AbstractButton, com.jgoodies.binding.value.ValueModel)

to

public void to(AbstractButton toggleButton,
               Object selectedValue,
               Object deselectedValue)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given toggle button, for example a check box.

Example:
binder.bindBeanProperty("classical").to(classicalBox, CLASSICAL, PLAIN);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
toggleButton - the button to be bound to this builder's ValueModel
selectedValue - the model's value if the button is selected
deselectedValue - the model's value if the button is not selected
See Also:
Bindings.bind(AbstractButton, com.jgoodies.binding.value.ValueModel)

to

public void to(AbstractButton toggleButton,
               Object choice)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given toggle button (radio button style) that is selected, if and only if the model's value equals the given choice.

Example:
binder.bindBeanProperty("alignment").to(alignmentButton, Alignment.LEFT);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
toggleButton - the button to be bound to this builder's ValueModel
choice - the model value where radioButton shall be selected
See Also:
Bindings.bind(AbstractButton, com.jgoodies.binding.value.ValueModel, Object)

to

public void to(JFormattedTextField formattedTextField)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given formatted text field.

Example:
binder.bindBeanProperty("releaseDate").to(dateField);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
formattedTextField - the formatted text field to be bound to this builder's ValueModel
See Also:
Bindings.bind(JFormattedTextField, com.jgoodies.binding.value.ValueModel)

to

public void to(JLabel label)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given text label.

Example:
binder.binProperty("resultCount").converted(resultFormat).to(tableHeaderLabel);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
label - the label to be bound to this builder's ValueModel
See Also:
Bindings.bind(JLabel, com.jgoodies.binding.value.ValueModel)

to

public void to(JTextArea textArea)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given text area and commits text changes on focus lost.

Example:
binder.bindBeanProperty("comment").to(commentArea);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
textArea - the text area to be bound to this builder's ValueModel
See Also:
Bindings.bind(JTextArea, com.jgoodies.binding.value.ValueModel)

to

public void to(JTextArea textArea,
               ValueModelBindingBuilder.Commit commitType)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given text area using the specified commit type.

Examples:
binder.bindBeanProperty("comment").to(commentArea, Commit.ON_KEY_TYPED); binder.bindBeanProperty("comment").to(commentArea, Commit.ON_FOCUS_LOST);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
textArea - the text area to be bound to this builder's ValueModel
commitType - the commit type to be used, either Commit.ON_KEY_TYPED or Commit.ON_FOCUS_LOST
See Also:
Bindings.bind(JTextArea, com.jgoodies.binding.value.ValueModel)

to

public void to(JTextField textField)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given text field and commits text changes on focus lost.

Example:
binder.bindBeanProperty("title").to(titleField);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
textField - the text field to be bound to this builder's ValueModel
See Also:
Bindings.bind(JTextField, com.jgoodies.binding.value.ValueModel)

to

public void to(JTextField textField,
               ValueModelBindingBuilder.Commit commitType)
Description copied from interface: ValueModelBindingBuilder
Binds this builder's ValueModel to the given text field using the specified commit type.

Examples:
binder.bindBeanProperty("title").to(titleField, Commit.ON_KEY_TYPED); binder.bindBeanProperty("title").to(titleField, Commit.ON_FOCUS_LOST);

Specified by:
to in interface ValueModelBindingBuilder
Parameters:
textField - the text field to be bound to this builder's ValueModel
commitType - the commit type to be used, either Commit.ON_KEY_TYPED or Commit.ON_FOCUS_LOST
See Also:
Bindings.bind(JTextField, com.jgoodies.binding.value.ValueModel)

getValueModel

protected final ValueModel getValueModel()
Returns:
this builder's ValueModel

getPropertyName

protected final String getPropertyName()
Returns:
the property name - if any - that has been used to create this builder, e.g. in binder.bindBeanProperty("title").to(...)

setValidationMessageKey

protected final void setValidationMessageKey(JComponent comp)
Sets this builder's property name - if any - as the component's validation message key.

Parameters:
comp - the component where the validation message key shall be set


Copyright © 2002-2013 JGoodies Software GmbH. All Rights Reserved.