|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectinfo.joseluismartin.gui.AbstractView<T>
public abstract class AbstractView<T>
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.
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 |
---|
public static final String DEFAULT_BINDER_FACTORY_NAME
@Autowired protected org.springframework.context.MessageSource messageSource
protected org.springframework.validation.BindingResult errors
protected int width
protected int height
Constructor Detail |
---|
public AbstractView()
public AbstractView(T model)
model
- model to setMethod Detail |
---|
public void bind(Object component, String propertyName, boolean readOnly)
component
- controlpropertyName
- the model property path to bindreadOnly
- if true, binding only do refresh()public void bind(Object component, String propertyName)
component
- controlpropertyName
- the model property path to bindpublic JComponent getPanel()
getPanel
in interface View<T>
protected abstract JComponent buildPanel()
public T getModel()
getModel
in interface ModelHolder<T>
public final void setModel(T model)
setModel
in interface ModelHolder<T>
protected void onSetModel(T model)
model
- the new modelpublic final void update()
update
in interface Binder<T>
protected void doUpdate()
protected void afterUpdate()
public void addView(View view)
view
- public final void refresh()
refresh
in interface Binder<T>
protected void doRefresh()
protected void afterRefresh()
public void listen(Object control)
public void controlChange(ControlEvent e)
controlChange
in interface ControlChangeListener
e
- ControlEvent with control change infopublic BinderFactory getBinderFactory()
public void setBinderFactory(BinderFactory binderFactory)
binderFactory
- to setpublic boolean validateView()
validateView
in interface View<T>
public String getErrorMessage()
getErrorMessage
in interface View<T>
public void clear()
clear
in interface View<T>
public void enableView(boolean enabled)
enableView
in interface View<T>
public void autobind()
protected String getMessage(String code)
code
- message code
protected String getMessage(org.springframework.context.MessageSourceResolvable msr)
msr
- message source resolvable
public void addControlChangeListener(ControlChangeListener l)
View
addControlChangeListener
in interface View<T>
l
- the ControlChangeListener to add.public void removeControlChangeListener(ControlChangeListener l)
View
removeControlChangeListener
in interface View<T>
l
- ControlChangeListener to remove.protected void fireControlChange(ControlEvent e)
public void ignoreProperty(String propertyName)
propertyName
- property name to ignorepublic Set<String> getIgnoredProperties()
public void setIgnoredProperties(Set<String> ignoredProperties)
ignoredProperties
- the ignoredProperties to setpublic void ignoreProperties(Collection<? extends String> c)
c
- Collection of property names.public org.springframework.validation.Validator getValidator()
public void setValidator(org.springframework.validation.Validator validator)
validator
- the validator to setpublic org.springframework.context.MessageSource getMessageSource()
public void setMessageSource(org.springframework.context.MessageSource messageSource)
messageSource
- the messageSource to setpublic int getWidth()
public void setWidth(int width)
width
- the width to setpublic int getHeight()
public void setHeight(int height)
height
- the height to setpublic String getName()
View
getName
in interface View<T>
public void setName(String name)
name
- the name to setpublic List<ErrorProcessor> getErrorProcessors()
public void setErrorProcessors(List<ErrorProcessor> errorProcessors)
errorProcessors
- the errorProcessors to setpublic boolean isDirty()
View
isDirty
in interface View<T>
public void setDirty(boolean dirty)
dirty
- the dirty to setpublic ControlAccessorFactory getControlAccessorFactory()
public void setControlAccessorFactory(ControlAccessorFactory controlAccessorFactory)
controlAccessorFactory
- the controlAccessorFactory to setpublic boolean isAutobinding()
public void setAutobinding(boolean autobinding)
autobinding
- the autobinding to setpublic org.springframework.validation.BindingResult getBindingResult()
getBindingResult
in interface Binder<T>
public PropertyBinder getBinder(String propertyName)
getBinder
in interface BinderHolder
propertyName
- property name
public boolean isInitializeControls()
public void setInitializeControls(boolean initializeControls)
initializeControls
- the initializeControls to setpublic ControlInitializer getControlInitializer()
public void setControlInitializer(ControlInitializer controlInitializer)
controlInitializer
- the controlInitializer to set
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |