de.kleopatra.view.binding
Class BeanBinding

java.lang.Object
  extended byde.kleopatra.view.binding.BeanBinding

public class BeanBinding
extends java.lang.Object

Helper to manage data binding.

Finds and binds input widgets of source container to properties of a bean-like target. Name of widgets is used as identifier of the widget.

Has state: exactly one container and exactly one target! Internally delegates into both directions:

Conventions for bindXXInput methods: PENDING: As an alternativ to the explicit bindXXInput, binding can be done by providing a collection of BindingMetaData. Not yet complete...

PENDING: better support external triggers?

PENDING: think about using PresentationModel?

Version:
$Revision: 1.8 $ - $Date: 2004/10/04 11:56:04 $
Author:
(C) Jeanette Winzenburg, Berlin

Field Summary
protected  BeanAdapter beanAdapter
          adapter vending valueModels bound to target properties.
protected  Trigger externalTrigger
          externally accessible trigger.
protected  javax.swing.JComponent input
          the common parent for all widgets to bind.
protected  Trigger internalTrigger
          used for internally created buffered adapters.
protected  boolean observeChanges
          flag to control listening to the adapted bean
 
Constructor Summary
BeanBinding(javax.swing.JComponent input, boolean observeChanges)
          Prepares binding between children of input container with listening option.
BeanBinding(javax.swing.JComponent input, java.lang.Object target)
          Prepares binding between children of input container and target bean without listening to changes of target bean.
BeanBinding(javax.swing.JComponent input, java.lang.Object target, boolean observeChanges)
          Prepares binding between children of input container and target bean with listening option.
 
Method Summary
 void addInversToggleDependents(java.lang.String componentName, java.util.List dependents)
           
protected  void addToggleDependents(EnableMultiplexer multiplexer, java.util.List dependents)
           
 void addToggleDependents(java.lang.String componentName, java.util.List dependents)
          adds a collection of components to be (dis)abled in synch with the selection state of the AbstractButton componentName.
protected  void bind(BindingMetaData metaData)
          PRE: isBindable()
 void bind(java.util.Collection bindingMetaData)
          tries to bind components to all given bindingMetaData.
 void bindBooleanInput(java.lang.String componentName)
           
 void bindBooleanInput(java.lang.String componentName, java.lang.String propertyName)
          binds an AbstractButton to a two-state property.
 void bindComboBoxInput(java.lang.String componentName, java.lang.Object model)
           
 void bindComboBoxInput(java.lang.String componentName, java.lang.Object model, boolean editable)
           
 void bindComboBoxInput(java.lang.String componentName, java.lang.String propertyName, java.lang.Object model)
           
 void bindComboBoxInput(java.lang.String componentName, java.lang.String propertyName, java.lang.Object model, boolean editable)
          binds the selection of a comboBox to a property.
 void bindFormattedTextInput(java.lang.String componentName)
           
 void bindFormattedTextInput(java.lang.String componentName, java.lang.String propertyName)
           
 void bindListAndSelection(java.lang.String componentName, java.lang.String listPropertyName, java.lang.String selectionPropertyName)
          binds a list with both data and (single) selection.
 void bindListAndSelectionInput(java.lang.String componentName, java.lang.String listPropertyName, java.lang.String selectionPropertyName)
          binds a list with both data and (single) selection.
 void bindListInput(java.lang.String componentName, java.lang.String selectionPropertyName, java.lang.String listPropertyName)
          binds a list with both (single) selection and data.
 void bindRadioGroup(java.util.List componentIDs, java.lang.String propertyName, java.util.List optionValues)
          binds the selection in a group of RadioButtons to a property.
 void bindRadioGroup(java.lang.String propertyName, java.util.List componentIDs, java.util.List optionValues)
          binds the selection in a group of RadioButtons to a property.
 void bindSpinnerInput(java.lang.String componentName)
           
 void bindSpinnerInput(java.lang.String componentName, javax.swing.SpinnerModel model)
           
 void bindSpinnerInput(java.lang.String componentName, java.lang.String propertyName)
           
 void bindSpinnerInput(java.lang.String componentName, java.lang.String propertyName, javax.swing.SpinnerModel spinnerModel)
          binds a spinner's value to the property.
 void bindTextAreaInput(java.lang.String componentName)
           
 void bindTextAreaInput(java.lang.String componentName, boolean editable)
           
 void bindTextAreaInput(java.lang.String componentName, java.lang.String propertyName)
           
 void bindTextAreaInput(java.lang.String componentName, java.lang.String propertyName, boolean editable)
          binds a TextArea to a property.
 void bindTextInput(java.lang.String componentName)
           
 void bindTextInput(java.lang.String componentName, boolean editable)
           
 void bindTextInput(java.lang.String componentName, java.lang.String propertyName)
           
 void bindTextInput(java.lang.String componentName, java.lang.String propertyName, boolean editable)
          binds a TextField to a property.
protected  void checkBindable()
          should not happen...
 void commit()
           
protected  BeanAdapter createBeanAdapter()
           
protected  java.util.List createList()
           
protected  java.util.Map createMap()
           
 javax.swing.JComponent findComponent(java.lang.String name)
           
 void flush()
           
protected  BeanAdapter getBeanAdapter()
           
protected  BindingHandler getBindingHandler(BindingMetaData metaData)
           
protected  Trigger getExternalTrigger()
          returns the external trigger.
 javax.swing.JComponent getInputContainer()
          returns a common ancestor of bound components.
 java.lang.Object getTarget()
          returns the bound target.
protected  ValueModel getValueModel(java.lang.String propertyName)
          returns an adapter from the beanAdapter.
protected  void internalCommit()
          will trigger a commit from internal events.
protected  void internalFlush()
           
protected  boolean isBindable()
          not really needed if null check in constructor
 boolean isBufferEnabled()
           
 void setBufferEnabled(boolean externalTriggering)
          flag to enable buffering of ValueModels.
 void setEnabled(java.lang.String componentName, boolean enabled)
           
 void setTarget(java.lang.Object newTarget)
          set the target to bind.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalTrigger

protected Trigger internalTrigger
used for internally created buffered adapters.


externalTrigger

protected Trigger externalTrigger
externally accessible trigger.


beanAdapter

protected BeanAdapter beanAdapter
adapter vending valueModels bound to target properties.


observeChanges

protected boolean observeChanges
flag to control listening to the adapted bean


input

protected javax.swing.JComponent input
the common parent for all widgets to bind.

Constructor Detail

BeanBinding

public BeanBinding(javax.swing.JComponent input,
                   boolean observeChanges)
Prepares binding between children of input container with listening option. The initial target bean is null.

Parameters:
input - - the parent container of the widgets to bind. Must not be null.
observeChanges - - flag to indicate if the adapter should listen to changes of the target bean.

BeanBinding

public BeanBinding(javax.swing.JComponent input,
                   java.lang.Object target)
Prepares binding between children of input container and target bean without listening to changes of target bean.

Parameters:
input - - the parent container of the widgets to bind. Must not be null.
target - - the target bean to bind

BeanBinding

public BeanBinding(javax.swing.JComponent input,
                   java.lang.Object target,
                   boolean observeChanges)
Prepares binding between children of input container and target bean with listening option.

Parameters:
input - - the parent container of the widgets to bind. Must not be null.
target - - the target bean to bind, allowed to be null.
observeChanges - - flag to indicate if the adapter should listen to changes of the target bean.
Method Detail

setBufferEnabled

public void setBufferEnabled(boolean externalTriggering)
flag to enable buffering of ValueModels. if true changes in components will be written to bean properties on commit() only and can be discarded by calling flush(). By default, buffering is disabled.

NOTE: this must be done before calling any of the bindXX methods!


setTarget

public void setTarget(java.lang.Object newTarget)
set the target to bind. May be null.


getTarget

public java.lang.Object getTarget()
returns the bound target. May be null.


getInputContainer

public javax.swing.JComponent getInputContainer()
returns a common ancestor of bound components.

Returns:

isBufferEnabled

public boolean isBufferEnabled()

commit

public void commit()

flush

public void flush()

bind

public void bind(java.util.Collection bindingMetaData)
tries to bind components to all given bindingMetaData.

Parameters:
bindingMetaData - - list containing metaData. Must not be null.
Throws:
java.lang.IllegalStateException - if !isBindable()

bindTextInput

public void bindTextInput(java.lang.String componentName)

bindTextInput

public void bindTextInput(java.lang.String componentName,
                          boolean editable)

bindTextInput

public void bindTextInput(java.lang.String componentName,
                          java.lang.String propertyName)

bindTextInput

public void bindTextInput(java.lang.String componentName,
                          java.lang.String propertyName,
                          boolean editable)
binds a TextField to a property. The editable state will be set as passed in.

PENDING: currently _not_ adapted to Document directly, that is inserts/remove will not be committed at once but on on internal (action and focusLost) trigger, need parameter to enable/disable on a per-binding basis.


bindTextAreaInput

public void bindTextAreaInput(java.lang.String componentName)

bindTextAreaInput

public void bindTextAreaInput(java.lang.String componentName,
                              boolean editable)

bindTextAreaInput

public void bindTextAreaInput(java.lang.String componentName,
                              java.lang.String propertyName)

bindTextAreaInput

public void bindTextAreaInput(java.lang.String componentName,
                              java.lang.String propertyName,
                              boolean editable)
binds a TextArea to a property. The editable state will be set as passed in.

PENDING: currently _not_ adapted to Document directly, that is inserts/remove will not be committed at once but on on internal (action and focusLost) trigger, need parameter to enable/disable on a per-binding basis.

Parameters:
componentName -
propertyName -
editable -

bindFormattedTextInput

public void bindFormattedTextInput(java.lang.String componentName)

bindFormattedTextInput

public void bindFormattedTextInput(java.lang.String componentName,
                                   java.lang.String propertyName)

bindSpinnerInput

public void bindSpinnerInput(java.lang.String componentName)

bindSpinnerInput

public void bindSpinnerInput(java.lang.String componentName,
                             java.lang.String propertyName)

bindSpinnerInput

public void bindSpinnerInput(java.lang.String componentName,
                             javax.swing.SpinnerModel model)

bindSpinnerInput

public void bindSpinnerInput(java.lang.String componentName,
                             java.lang.String propertyName,
                             javax.swing.SpinnerModel spinnerModel)
binds a spinner's value to the property. Set's the spinnerModel if != null. Installs a SpinnerConnector with the spinner's model to guarantee updates of the property.

All shortcut methods for spinner binding call this method.

Parameters:
componentName -
propertyName -
spinnerModel - the spinnerModel to use, may be null.

bindComboBoxInput

public void bindComboBoxInput(java.lang.String componentName,
                              java.lang.Object model)

bindComboBoxInput

public void bindComboBoxInput(java.lang.String componentName,
                              java.lang.Object model,
                              boolean editable)

bindComboBoxInput

public void bindComboBoxInput(java.lang.String componentName,
                              java.lang.String propertyName,
                              java.lang.Object model)

bindComboBoxInput

public void bindComboBoxInput(java.lang.String componentName,
                              java.lang.String propertyName,
                              java.lang.Object model,
                              boolean editable)
binds the selection of a comboBox to a property. The available values are passed in model. The editable state is set according the editable flag.

PRE: model can an Array, a ListModel, a List, or a property returning a ListModel or a List. Internally the binding will create a ComboBoxAdapter for all.

All short-cut methods for binding combos use this.


bindListAndSelectionInput

public void bindListAndSelectionInput(java.lang.String componentName,
                                      java.lang.String listPropertyName,
                                      java.lang.String selectionPropertyName)
binds a list with both data and (single) selection. listPropertyName is the source of the data, selectionPropertyName is the property to synch with on selection, may be null.

NOTE: clients are responsible to guarantee that listProperty returns a "list-like" structure usable by SelectionInList as listHolder.


bindListInput

public void bindListInput(java.lang.String componentName,
                          java.lang.String selectionPropertyName,
                          java.lang.String listPropertyName)
binds a list with both (single) selection and data. selectionPropertyName is the property to synch with on selection, listPropertyName is the source of the data.


bindListAndSelection

public void bindListAndSelection(java.lang.String componentName,
                                 java.lang.String listPropertyName,
                                 java.lang.String selectionPropertyName)
binds a list with both data and (single) selection. listPropertyName is the source of the data and selectionPropertyName is the property to synch with on selection.


bindBooleanInput

public void bindBooleanInput(java.lang.String componentName)

bindBooleanInput

public void bindBooleanInput(java.lang.String componentName,
                             java.lang.String propertyName)
binds an AbstractButton to a two-state property.

Internally uses a ToggleButtonAdapter. For constraints on the property, have a look at its api doc.

PENDING: client is responsible for not binding a radiobuttons/toggleButtons by this method at least none that should be used in a radioGroup.

Parameters:
componentName -
propertyName -

bindRadioGroup

public void bindRadioGroup(java.lang.String propertyName,
                           java.util.List componentIDs,
                           java.util.List optionValues)
binds the selection in a group of RadioButtons to a property. The first list contains the componentIDs of the buttons, the second list contains the list of the corresponding values to set to the property on selection of this button.

NOTE: it's the calling code's responsibility to guarantee valid options and equal lengths on boths lists.


bindRadioGroup

public void bindRadioGroup(java.util.List componentIDs,
                           java.lang.String propertyName,
                           java.util.List optionValues)
binds the selection in a group of RadioButtons to a property. The first list contains the componentIDs of the buttons, the second list contains the list of the corresponding values to set to the property on selection of this button.

NOTE: it's the calling code's responsibility to guarantee valid options and equal lengths on boths lists.


addToggleDependents

public void addToggleDependents(java.lang.String componentName,
                                java.util.List dependents)
adds a collection of components to be (dis)abled in synch with the selection state of the AbstractButton componentName.

Parameters:
componentName - the id of the controlling button
dependents - a list of ids of dependent components

addInversToggleDependents

public void addInversToggleDependents(java.lang.String componentName,
                                      java.util.List dependents)

setEnabled

public void setEnabled(java.lang.String componentName,
                       boolean enabled)

findComponent

public javax.swing.JComponent findComponent(java.lang.String name)

addToggleDependents

protected void addToggleDependents(EnableMultiplexer multiplexer,
                                   java.util.List dependents)

getValueModel

protected ValueModel getValueModel(java.lang.String propertyName)
returns an adapter from the beanAdapter. will wrap the adapter into a DelayedRefresher if not observeChanges (to guarantee synch with bean as closely as possible) PENDING: incomplete analysis internalTrigger/delayedRefresher/ externaltrigger....


bind

protected void bind(BindingMetaData metaData)
PRE: isBindable()


getBindingHandler

protected BindingHandler getBindingHandler(BindingMetaData metaData)

isBindable

protected boolean isBindable()
not really needed if null check in constructor

Returns:

checkBindable

protected void checkBindable()
                      throws BindingComponentNotFoundException
should not happen...

Throws:
BindingComponentNotFoundException - if !isBindable()

internalCommit

protected void internalCommit()
will trigger a commit from internal events. (f.i. actionEvents on textfields, or focusLost).


internalFlush

protected void internalFlush()

getExternalTrigger

protected Trigger getExternalTrigger()
returns the external trigger. creates it if null.


getBeanAdapter

protected BeanAdapter getBeanAdapter()

createBeanAdapter

protected BeanAdapter createBeanAdapter()

createMap

protected java.util.Map createMap()

createList

protected java.util.List createList()


Copyright © 2003, 2004 SwingEmpire Jeanette Winzenburg. All Rights Reserved.