public class Form extends Object implements LspsScreen
FormComponent
instances; there are no scopes and no potential 1-to-many relationship like in the old UI.
To construct the form, you will need to:
callInForm(Form, Runnable)
; in the Runnable call createComponent(Variant.RecordVariant)
on the root
FormComponent
definition, to initialize the component graphsetRootComponent(RecordHolder)
to set the root componentConstructor and Description |
---|
Form(FormComponentFactory componentFactory,
LspsContextHolder context)
Creates the new form.
|
Modifier and Type | Method and Description |
---|---|
void |
addBrowserWindowResizeListener(Variant.ScopedClosureVariant listener)
Adds a resize listener to the browser window.
|
void |
addComponentToRefresh(UIComponent component)
Schedules a component to be refreshed during next call to
LspsScreen.triggerEventProcessing(com.whitestein.lsps.vaadin.ui.events.UIEvent) . |
void |
addUploadedBinaryData(long binaryDataId)
Adds a temporary file to the list of files to be deleted once the screen is closed.
|
<R> R |
call(Callable<R> callable)
Call any listener body in this, in order for the methods called from the listener to have access to the form
instance (via
get() ). |
<R> R |
callDontCatch(Callable<R> callable)
Call any listener body in this, in order for the methods called from the listener to have access to the form
instance (via
get() ). |
static void |
callInForm(Form form,
Runnable runnable)
Call any listener body in this, in order for the methods called from the listener to have access to the form
instance (via
get() ). |
void |
cleanup()
Called after the screen content is removed from the Vaadin UI or submitted.
|
void |
clearErrorMessages(RecordHolder component)
Clears error messages on the component and all it's descendants.
|
void |
createComponent(Variant.RecordVariant def)
INTERNAL, DO NOT CALL.
|
UIComponent |
createUIComponent(UIComponent parent,
RecordHolder componentDefinition,
UIComponentScope scope)
Creates a Vaadin component based on the provided component definition.
|
void |
fireApplicationEvent(UIApplicationEvent appEvent)
Schedules given application event to be fired on all registered components that have an application event listener.
|
void |
fireBrowserWindowResizeEvent(Dimension dimension)
A browser window resize has been detected.
|
int |
gc()
Runs a full GC, both over the Form and over the model.
|
static Form |
get()
Returns the current form the expression is executing in.
|
Set<UIComponent> |
getAllComponents()
Returns all components contained in this screen.
|
FormComponent |
getComponent(com.vaadin.ui.Component component)
Returns the FormComponent which produced given Vaadin component.
|
FormComponent |
getComponent(RecordHolder rh)
Gets a
FormComponent corresponding to the given form component definition. |
FormComponentFactory |
getComponentFactory()
Gets factory for form components.
|
Set<UIComponent> |
getComponentsForDefinition(RecordHolder componentDefinition,
UIComponent scopeComponent)
Returns all component instances for the given component definition,
visible from the scope of the given component.
|
LspsContextHolder |
getContext()
Gets the context holder.
|
LspsContextHolder |
getContextHolder()
Returns the the LSPS context which produced this screen.
|
Variant.RecordVariant |
getDef(FormComponent component)
Returns the LSPS Record instance, mapped one-to-one to given Vaadin Form Component instance.
|
Locale |
getLocale()
Gets the locale set to the root component widget.
|
static Form |
getNull()
Gets the current form from bound to the current thread the expression is executed in
or
null if there is no form instance bound to the current thread. |
FormComponent |
getRootComponent()
Gets the root component of thsi form.
|
UIComponentScope |
getRootScope()
Returns the root scope.
|
ContextWrapper |
getScreenContext()
Deprecated.
|
UIComponent |
getTopmostComponent()
Returns the topmost component.
|
Set<ValueHolder> |
getValuesToRetain()
Returns the set of value holders that should not be garbage collected
even if they are not referenced from any variables in the model.
|
boolean |
isFormComponent(com.vaadin.ui.Component component)
Returns
true if the component is a widget of a FormComponent contained in this form. |
boolean |
isInvalid(UIComponent component)
Checks whether given component is marked as invalid, by calling
LspsScreen.markComponentAsInvalid(com.whitestein.lsps.vaadin.ui.components.UIComponent) . |
static void |
listener(FormComponent component,
Runnable runnable)
Call any listener body in this, in order for the methods called from the listener to have access to the form
instance (via
get() ). |
void |
markComponentAsInvalid(UIComponent component)
Marks the component as invalid.
|
void |
markComponentAsValid(UIComponent component)
Marks the component as valid again.
|
void |
registerUIComponent(UIComponent component)
Register the given UI component and its children in this screen.
|
void |
registerValueToRetain(Handle handle)
Registers the value for the given handle as one to be kept during garbage collection.
|
com.vaadin.ui.Component |
render()
Called when the screen content should be added to the Vaadin UI.
|
void |
resume()
Called after the screen component has been added to Vaadin UI.
|
RecordHolder |
save(ExecutionContext ctx)
Saves the current Todo/Document.
|
void |
setRootComponent(RecordHolder rootDef)
Sets the root component of this form.
|
void |
showConstraintViolations(ListHolder constraintViolations,
RecordHolder root)
Displays constraint violations in the forms.
|
boolean |
triggerEventProcessing(UIEvent triggeringEvent)
Process all events in the queue - invokes standard LSPS ui lifecycle
|
void |
unregisterUIComponent(UIComponent component)
Unregister the given UI component and its children from this screen.
|
void |
unregisterValueToRetain(Handle handle)
Unregisters the value for the given handle as one to be kept during garbage collection.
|
void |
updateContextFor(UIComponentData componentData)
Updates context dependent variables for the given
componentData . |
public Form(FormComponentFactory componentFactory, LspsContextHolder context)
componentFactory
- the factory which produces actual instances of UI components and renderers, not null.context
- LSPS context, not null.public FormComponentFactory getComponentFactory()
public FormComponent getComponent(RecordHolder rh)
FormComponent
corresponding to the given form component definition.rh
- the form component definitionpublic FormComponent getComponent(com.vaadin.ui.Component component)
component
- the component, not nullIllegalArgumentException
- if given Vaadin component is not registered in this form.public boolean isFormComponent(com.vaadin.ui.Component component)
Returns true
if the component is a widget of a FormComponent
contained in this form.
In other words it checks whether the component was returned by one of the forms components when
calling FormComponent.getWidget()
.
If this method returns false
then calling getComponent(Component)
with the same
component argument will throw an exception.
component
- the component to checktrue
if the component is a widget of a FormComponent
contianed in this formpublic void createComponent(Variant.RecordVariant def)
getComponent(RecordHolder)
to retrieve the FormComponent
counterpart.def
- the definition, not null.public static Form get()
IllegalStateException
- if this is not called from UI.public static Form getNull()
null
if there is no form instance bound to the current thread.null
get()
public LspsContextHolder getContext()
public void setRootComponent(RecordHolder rootDef)
rootDef
- public com.vaadin.ui.Component render()
LspsScreen
LspsScreen.resume()
method is called after this method.
This method must be called exactly once.render
in interface LspsScreen
public FormComponent getRootComponent()
public void resume()
LspsScreen
LspsScreen.render()
method has already been calledresume
in interface LspsScreen
public void cleanup()
LspsScreen
cleanup
in interface LspsScreen
public void registerValueToRetain(Handle handle)
LspsScreen
LspsScreen.getValuesToRetain()
.registerValueToRetain
in interface LspsScreen
handle
- a handle to the model object, not null.public void unregisterValueToRetain(Handle handle)
LspsScreen
LspsScreen.getValuesToRetain()
.unregisterValueToRetain
in interface LspsScreen
handle
- a handle to the model object, not null.public int gc()
public Set<ValueHolder> getValuesToRetain()
LspsScreen
getValuesToRetain
in interface LspsScreen
public Set<UIComponent> getAllComponents()
LspsScreen
getRootScope().getRegisteredComponents()
getAllComponents
in interface LspsScreen
public UIComponentScope getRootScope()
LspsScreen
getRootScope
in interface LspsScreen
public void fireBrowserWindowResizeEvent(Dimension dimension)
LspsScreen
internal_windowresize
, having payload
of type hu::Dimension which
holds new window dimension. The event originator component is set to ROOT.
Warning: browsers on Android return value in DPs instead of pixels. From Android documentation:
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen.
The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Example: a screen width of 720 on a 320 DPI screen will be reported as 360 DPs.
Therefore, to render special page for small devices, compare screen width to the value of 400. If equal or smaller, provide small screen version.fireBrowserWindowResizeEvent
in interface LspsScreen
dimension
- the new dimension, in pixels (on desktop OS) or DPs (on Android phones).@Deprecated public ContextWrapper getScreenContext()
LspsScreen
getScreenContext
in interface LspsScreen
public LspsContextHolder getContextHolder()
LspsScreen
getContextHolder
in interface LspsScreen
public UIComponent createUIComponent(UIComponent parent, RecordHolder componentDefinition, UIComponentScope scope)
LspsScreen
UIComponentFactory.createComponent(LspsScreen, com.whitestein.lsps.vaadin.ui.components.UIComponent, com.whitestein.lsps.lang.exec.RecordHolder, com.whitestein.lsps.vaadin.ui.UIComponentScope)
.createUIComponent
in interface LspsScreen
parent
- parent of the component in the LSPS component hierarchycomponentDefinition
- definition of the component to createscope
- component scope; if null, same scope as parent will be usedpublic boolean triggerEventProcessing(UIEvent triggeringEvent)
LspsScreen
triggerEventProcessing
in interface LspsScreen
triggeringEvent
- the event that triggered this round of processing; can be null if there is no such event.LspsScreen.markComponentAsInvalid(com.whitestein.lsps.vaadin.ui.components.UIComponent)
.public void markComponentAsInvalid(UIComponent component)
LspsScreen
LspsScreen.triggerEventProcessing(com.whitestein.lsps.vaadin.ui.events.UIEvent)
to return false for events which
processes given component.
Note that this will not cause the component to show an error icon.markComponentAsInvalid
in interface LspsScreen
component
- the component, not null.public void markComponentAsValid(UIComponent component)
LspsScreen
markComponentAsValid
in interface LspsScreen
component
- the component, not null.public boolean isInvalid(UIComponent component)
LspsScreen
LspsScreen.markComponentAsInvalid(com.whitestein.lsps.vaadin.ui.components.UIComponent)
.isInvalid
in interface LspsScreen
component
- the component, not null.LspsScreen.markComponentAsValid(com.whitestein.lsps.vaadin.ui.components.UIComponent)
.public void registerUIComponent(UIComponent component)
LspsScreen
registerUIComponent
in interface LspsScreen
component
- not null. The component parent must already be registered.public void unregisterUIComponent(UIComponent component)
LspsScreen
unregisterUIComponent
in interface LspsScreen
component
- not null. The component parent must already be registered.public void addComponentToRefresh(UIComponent component)
LspsScreen
LspsScreen.triggerEventProcessing(com.whitestein.lsps.vaadin.ui.events.UIEvent)
.addComponentToRefresh
in interface LspsScreen
component
- the component, not null. The component must be initialized.public void updateContextFor(UIComponentData componentData)
LspsScreen
componentData
. See UIComponentScope.updateContext()
.updateContextFor
in interface LspsScreen
componentData
- a component data, may not be null
public UIComponent getTopmostComponent()
LspsScreen
getTopmostComponent
in interface LspsScreen
public void fireApplicationEvent(UIApplicationEvent appEvent)
LspsScreen
LspsScreen.triggerEventProcessing(com.whitestein.lsps.vaadin.ui.events.UIEvent)
is called.fireApplicationEvent
in interface LspsScreen
appEvent
- the event, not null.public Set<UIComponent> getComponentsForDefinition(RecordHolder componentDefinition, UIComponent scopeComponent)
LspsScreen
getComponentsForDefinition
in interface LspsScreen
componentDefinition
- the definition, not null.scopeComponent
- find the components in this scope only. Not null.UIComponent
associated with the given component definition. Never null, never contains nulls.public void addUploadedBinaryData(long binaryDataId)
LspsScreen
addUploadedBinaryData
in interface LspsScreen
public Variant.RecordVariant getDef(FormComponent component)
component
- the form component, not null. Fails if given form component is not registered in this form instance.public static void callInForm(Form form, Runnable runnable)
get()
).form
- calling some listener in this form, not null.runnable
- the listener body, not null.public <R> R call(Callable<R> callable)
get()
).R
- return type value of the callablecallable
- the listener body, not null.public <R> R callDontCatch(Callable<R> callable) throws Exception
get()
).R
- return type value of the callablecallable
- the listener body, not null.Exception
- an exception thrown by the callablepublic static void listener(FormComponent component, Runnable runnable)
get()
).component
- calling some listener of this component.runnable
- the listener body, not null.public Locale getLocale()
public void addBrowserWindowResizeListener(Variant.ScopedClosureVariant listener)
listener
- the listener to addpublic RecordHolder save(ExecutionContext ctx) throws ErrorException
ctx
- ErrorException
- if the save action fails.public void showConstraintViolations(ListHolder constraintViolations, RecordHolder root)
constraintViolations
- root
- the component defining the root of the sub-component-tree where to start.public void clearErrorMessages(RecordHolder component)
component
- Copyright © 2007-2018 Whitestein Technologies. All Rights Reserved.