info.joseluismartin.gui
Class AbstractView<T>

java.lang.Object
  extended by info.joseluismartin.gui.AbstractView<T>
All Implemented Interfaces:
BinderHolder, ControlChangeListener, Binder<T>, ModelHolder<T>, View<T>, EventListener
Direct Known Subclasses:
AttachmentView, DbConnectionForm, PaginatorView, ReportFileView, ReportFilterView, ReportListView, ReportTypeView, ReportView, TableEditor, TableListView, TreeView

public abstract class AbstractView<T>
extends Object
implements View<T>, ControlChangeListener, BinderHolder

Template class that simplifies View implementation.

The central method is buildPanel that builds the JComponent that hold the view controls. You may use custom binding of the view overwriting the methods doUpdate and doRefresh.

For common binding code, you usually use autobinding facitility, that is, using the same name to the field control and model property name, and setting autobinding to true. When using autobinding, you may exclude model properties from binding using some of ignoreProperty methods.

Manual binding is also supported via bind methods. When binding a control, a the View is added to control as ChangeListener is added to the control for setting dirty property on control changes.

Only org.springframework.util.validation.Validator validators are supported The validateView method calls configured ErrorProcessors to process errors found in validation.

Since:
1.0
Author:
Jose Luis Martin - (jlm@joseluismartin.info)
See Also:
BinderFactory, ControlAccessorFactory, ErrorProcessor

Field Summary
static String DEFAULT_BINDER_FACTORY_NAME
           
protected  org.springframework.validation.BindingResult errors
          Validation Errors
protected  int height
           
protected  org.springframework.context.MessageSource messageSource
          message source for internationalization
protected  int width
           
 
Constructor Summary
AbstractView()
          Default ctor
AbstractView(T model)
          Create the view and set the model
 
Method Summary
 void addControlChangeListener(ControlChangeListener l)
          Add a ControlChangeListener to be notified on view changes.
 void addView(View view)
          Add a subview, the subview is refreshed, updated and hold the same model that this view, for adding views with other models, use bind()
protected  void afterRefresh()
          Allow subclasses to do something after refresh
protected  void afterUpdate()
          Callback method on update()
 void autobind()
          Bind Controls with the same name that a property in the model.
 void bind(Object component, String propertyName)
          add a binding for control and model property name
 void bind(Object component, String propertyName, boolean readOnly)
          add a binding for control and model property name
protected abstract  JComponent buildPanel()
          Build the JComponent that hold controls.
 void clear()
          Reset view state to default values
 void controlChange(ControlEvent e)
          Notify that the value of the control has changed
protected  void doRefresh()
          Allow subclasses to do custom refresh
protected  void doUpdate()
          Callback method on update()
 void enableView(boolean enabled)
          Enable/Disable All controls
protected  void fireControlChange(ControlEvent e)
          Notifiy Listeners that control value has changed
 PropertyBinder getBinder(String propertyName)
          Lookup for a binder by property name
 BinderFactory getBinderFactory()
          Gets the binder factory
 org.springframework.validation.BindingResult getBindingResult()
          Get binding result
 ControlAccessorFactory getControlAccessorFactory()
           
 ControlInitializer getControlInitializer()
           
 String getErrorMessage()
          Build a error message with all errors.
 List<ErrorProcessor> getErrorProcessors()
           
 int getHeight()
           
 Set<String> getIgnoredProperties()
           
protected  String getMessage(org.springframework.context.MessageSourceResolvable msr)
          I18n Support
protected  String getMessage(String code)
          I18n Support
 org.springframework.context.MessageSource getMessageSource()
           
 T getModel()
          Gets model
 String getName()
          Gets the view name
 JComponent getPanel()
          Gets the view JComponent
 org.springframework.validation.Validator getValidator()
           
 int getWidth()
           
 void ignoreProperties(Collection<? extends String> c)
          Add a Collection of property names to ignore on binding
 void ignoreProperty(String propertyName)
          Add a property name to ignore on binding.
 boolean isAutobinding()
           
 boolean isDirty()
          Check if user change any controls of view
 boolean isInitializeControls()
           
 void listen(Object control)
          Listen control for changes.
protected  void onSetModel(T model)
          Callback method to handle model changes
 void refresh()
          Update Component from model
 void removeControlChangeListener(ControlChangeListener l)
          Remove a previously added ControlChangeListener
 void setAutobinding(boolean autobinding)
           
 void setBinderFactory(BinderFactory binderFactory)
          Sets the binder factory, propagate it to composite binder.
 void setControlAccessorFactory(ControlAccessorFactory controlAccessorFactory)
           
 void setControlInitializer(ControlInitializer controlInitializer)
           
 void setDirty(boolean dirty)
           
 void setErrorProcessors(List<ErrorProcessor> errorProcessors)
           
 void setHeight(int height)
           
 void setIgnoredProperties(Set<String> ignoredProperties)
           
 void setInitializeControls(boolean initializeControls)
           
 void setMessageSource(org.springframework.context.MessageSource messageSource)
           
 void setModel(T model)
          Sets model
 void setName(String name)
           
 void setValidator(org.springframework.validation.Validator validator)
           
 void setWidth(int width)
           
 void update()
          Update Model from Component
 boolean validateView()
          validate model
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BINDER_FACTORY_NAME

public static final String DEFAULT_BINDER_FACTORY_NAME
See Also:
Constant Field Values

messageSource

@Autowired
protected org.springframework.context.MessageSource messageSource
message source for internationalization


errors

protected org.springframework.validation.BindingResult errors
Validation Errors


width

protected int width

height

protected int height
Constructor Detail

AbstractView

public AbstractView()
Default ctor


AbstractView

public AbstractView(T model)
Create the view and set the model

Parameters:
model - model to set
Method Detail

bind

public void bind(Object component,
                 String propertyName,
                 boolean readOnly)
add a binding for control and model property name

Parameters:
component - control
propertyName - the model property path to bind
readOnly - if true, binding only do refresh()

bind

public void bind(Object component,
                 String propertyName)
add a binding for control and model property name

Parameters:
component - control
propertyName - the model property path to bind

getPanel

public JComponent getPanel()
Gets the view JComponent

Specified by:
getPanel in interface View<T>

buildPanel

protected abstract JComponent buildPanel()
Build the JComponent that hold controls.

Returns:
a JCompoent

getModel

public T getModel()
Gets model

Specified by:
getModel in interface ModelHolder<T>
Returns:
the model

setModel

public final void setModel(T model)
Sets model

Specified by:
setModel in interface ModelHolder<T>

onSetModel

protected void onSetModel(T model)
Callback method to handle model changes

Parameters:
model - the new model

update

public final void update()
Update Model from Component

Specified by:
update in interface Binder<T>

doUpdate

protected void doUpdate()
Callback method on update()


afterUpdate

protected void afterUpdate()
Callback method on update()


addView

public void addView(View view)
Add a subview, the subview is refreshed, updated and hold the same model that this view, for adding views with other models, use bind()

Parameters:
view -

refresh

public final void refresh()
Update Component from model

Specified by:
refresh in interface Binder<T>

doRefresh

protected void doRefresh()
Allow subclasses to do custom refresh


afterRefresh

protected void afterRefresh()
Allow subclasses to do something after refresh


listen

public void listen(Object control)
Listen control for changes.


controlChange

public void controlChange(ControlEvent e)
Notify that the value of the control has changed

Specified by:
controlChange in interface ControlChangeListener
Parameters:
e - ControlEvent with control change info

getBinderFactory

public BinderFactory getBinderFactory()
Gets the binder factory

Returns:
the binder factory

setBinderFactory

public void setBinderFactory(BinderFactory binderFactory)
Sets the binder factory, propagate it to composite binder.

Parameters:
binderFactory - to set

validateView

public boolean validateView()
validate model

Specified by:
validateView in interface View<T>
Returns:
true if there are not binding errors.

getErrorMessage

public String getErrorMessage()
Build a error message with all errors.

Specified by:
getErrorMessage in interface View<T>
Returns:
String with error message

clear

public void clear()
Reset view state to default values

Specified by:
clear in interface View<T>

enableView

public void enableView(boolean enabled)
Enable/Disable All controls

Specified by:
enableView in interface View<T>

autobind

public void autobind()
Bind Controls with the same name that a property in the model.


getMessage

protected String getMessage(String code)
I18n Support

Parameters:
code - message code
Returns:
message or code if none defined

getMessage

protected String getMessage(org.springframework.context.MessageSourceResolvable msr)
I18n Support

Parameters:
msr - message source resolvable
Returns:
message or code if none defined

addControlChangeListener

public void addControlChangeListener(ControlChangeListener l)
Description copied from interface: View
Add a ControlChangeListener to be notified on view changes.

Specified by:
addControlChangeListener in interface View<T>
Parameters:
l - the ControlChangeListener to add.

removeControlChangeListener

public void removeControlChangeListener(ControlChangeListener l)
Description copied from interface: View
Remove a previously added ControlChangeListener

Specified by:
removeControlChangeListener in interface View<T>
Parameters:
l - ControlChangeListener to remove.

fireControlChange

protected void fireControlChange(ControlEvent e)
Notifiy Listeners that control value has changed


ignoreProperty

public void ignoreProperty(String propertyName)
Add a property name to ignore on binding.

Parameters:
propertyName - property name to ignore

getIgnoredProperties

public Set<String> getIgnoredProperties()
Returns:
the ignoredProperties

setIgnoredProperties

public void setIgnoredProperties(Set<String> ignoredProperties)
Parameters:
ignoredProperties - the ignoredProperties to set

ignoreProperties

public void ignoreProperties(Collection<? extends String> c)
Add a Collection of property names to ignore on binding

Parameters:
c - Collection of property names.

getValidator

public org.springframework.validation.Validator getValidator()
Returns:
the validator

setValidator

public void setValidator(org.springframework.validation.Validator validator)
Parameters:
validator - the validator to set

getMessageSource

public org.springframework.context.MessageSource getMessageSource()
Returns:
the messageSource

setMessageSource

public void setMessageSource(org.springframework.context.MessageSource messageSource)
Parameters:
messageSource - the messageSource to set

getWidth

public int getWidth()
Returns:
the width

setWidth

public void setWidth(int width)
Parameters:
width - the width to set

getHeight

public int getHeight()
Returns:
the height

setHeight

public void setHeight(int height)
Parameters:
height - the height to set

getName

public String getName()
Description copied from interface: View
Gets the view name

Specified by:
getName in interface View<T>
Returns:
the name

setName

public void setName(String name)
Parameters:
name - the name to set

getErrorProcessors

public List<ErrorProcessor> getErrorProcessors()
Returns:
the errorProcessors

setErrorProcessors

public void setErrorProcessors(List<ErrorProcessor> errorProcessors)
Parameters:
errorProcessors - the errorProcessors to set

isDirty

public boolean isDirty()
Description copied from interface: View
Check if user change any controls of view

Specified by:
isDirty in interface View<T>
Returns:
the dirty

setDirty

public void setDirty(boolean dirty)
Parameters:
dirty - the dirty to set

getControlAccessorFactory

public ControlAccessorFactory getControlAccessorFactory()
Returns:
the controlAccessorFactory

setControlAccessorFactory

public void setControlAccessorFactory(ControlAccessorFactory controlAccessorFactory)
Parameters:
controlAccessorFactory - the controlAccessorFactory to set

isAutobinding

public boolean isAutobinding()
Returns:
the autobinding

setAutobinding

public void setAutobinding(boolean autobinding)
Parameters:
autobinding - the autobinding to set

getBindingResult

public org.springframework.validation.BindingResult getBindingResult()
Get binding result

Specified by:
getBindingResult in interface Binder<T>
Returns:
the binding result

getBinder

public PropertyBinder getBinder(String propertyName)
Lookup for a binder by property name

Specified by:
getBinder in interface BinderHolder
Parameters:
propertyName - property name
Returns:
PropertyBinder or null if none

isInitializeControls

public boolean isInitializeControls()
Returns:
the initializeControls

setInitializeControls

public void setInitializeControls(boolean initializeControls)
Parameters:
initializeControls - the initializeControls to set

getControlInitializer

public ControlInitializer getControlInitializer()
Returns:
the controlInitializer

setControlInitializer

public void setControlInitializer(ControlInitializer controlInitializer)
Parameters:
controlInitializer - the controlInitializer to set


Copyright © 2013 JDAL. All Rights Reserved.