com.vaadin.flow.component.internal.
Class UIInternals
- java.lang.Object
-
- com.vaadin.flow.component.internal.UIInternals
-
All Implemented Interfaces:
public class UIInternals extends Object implements Serializable
Holds UI-specific methods and data which are intended for internal use by the framework.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
UIInternals.JavaScriptInvocation
A
Page.executeJavaScript(String, Serializable...)
invocation that has not yet been sent to the client.
-
Constructor Summary
Constructors Constructor and Description UIInternals(UI ui)
Creates a new instance for the given UI.
-
Method Summary
All Methods Modifier and Type Method and Description Registration
addAfterNavigationListener(AfterNavigationListener listener)
Add a listener that will be informed when new components have been attached and all navigation tasks have resolved.
Registration
addBeforeEnterListener(BeforeEnterListener listener)
Add a listener that will be informed when a new set of components are going to be attached.
Registration
addBeforeLeaveListener(BeforeLeaveListener listener)
Add a listener that will be informed when old components are detached.
void
addComponentDependencies(Class<? extends Component> componentClass)
Adds the dependencies defined using
StyleSheet
,JavaScript
orHtmlImport
on the given Component class.Page.ExecutionCanceler
addJavaScriptInvocation(UIInternals.JavaScriptInvocation invocation)
Adds a JavaScript invocation to be sent to the client.
boolean
cancelPendingTitleUpdate()
Cancels any pending page title update set via
setTitle(String)
.void
clearLastHandledNavigation()
Clear latest handled navigation location.
List<UIInternals.JavaScriptInvocation>
dumpPendingJavaScriptInvocations()
Gets all the pending JavaScript invocations and clears the queue.
List<HasElement>
getActiveRouterTargetsChain()
Gets the currently active router target and parent layouts.
Location
getActiveViewLocation()
Gets the location of the currently shown view.
String
getAppId()
Gets the application id tied with this UI.
ConstantPool
getConstantPool()
Gets the constant pool that is used for keeping track of constants shared with the client for this UI.
String
getContextRootRelativePath()
Gets the relative path from the UI (servlet) path to the context root.
BeforeLeaveEvent.ContinueNavigationAction
getContinueNavigationAction()
Get stored
BeforeLeaveEvent.ContinueNavigationAction
if any.DependencyList
getDependencyList()
Returns the helper which handles loading of dependencies (css, js).
Location
getLastHandledLocation()
Get the latest handled location or empty optional if no active navigation.
long
getLastHeartbeatTimestamp()
Returns the timestamp of the last received heartbeat for the related UI.
int
getLastProcessedClientToServerId()
Gets the last processed server message id.
byte[]
getLastProcessedMessageHash()
Gets the hash of the last processed message from the client.
<E> List<E>
getNavigationListeners(Class<E> navigationHandler)
Get all registered listeners for given navigation handler type.
PushConnection
getPushConnection()
Returns the internal push connection object used by the related UI.
Router
getRouter()
Gets the router used for navigating in this UI, if the router was active when this UI was initialized.
int
getServerSyncId()
Gets the server sync id.
VaadinSession
getSession()
Gets the VaadinSession to which the related UI is attached.
StateTree
getStateTree()
Gets the state tree of the related UI.
String
getTitle()
Gets the page title recorded with
Page.setTitle(String)
.UI
getUI()
Gets the UI that this instance belongs to.
boolean
hasLastHandledLocation()
Check if we have already started navigation to some location on this roundtrip.
void
incrementServerId()
Increments the server sync id.
boolean
isDirty()
Checks if there are changes waiting to be sent to the client side.
void
setAppId(String appId)
Sets the application id tied with this UI.
void
setContextRoot(String contextRootRelativePath)
Sets the relative path from the UI (servlet) path to the context root.
void
setContinueNavigationAction(BeforeLeaveEvent.ContinueNavigationAction continueNavigationAction)
Set a
BeforeLeaveEvent.ContinueNavigationAction
or null to clear existing action.void
setLastHandledNavigation(Location location)
Set the latest navigation location for active navigation.
void
setLastHeartbeatTimestamp(long lastHeartbeat)
Sets the last heartbeat request timestamp for the related UI.
void
setLastProcessedClientToServerId(int lastProcessedClientToServerId, byte[] lastProcessedMessageHash)
Sets the last processed server message id.
void
setPushConnection(PushConnection pushConnection)
Sets the internal push connection object used by the related UI.
void
setSession(VaadinSession session)
Sets the session to which the related UI is assigned.
void
setTitle(String title)
Records the page title set with
Page.setTitle(String)
.void
showRouteTarget(Location viewLocation, String path, Component target, List<RouterLayout> layouts)
Shows a route target in the related UI.
-
-
-
Constructor Detail
-
UIInternals
public UIInternals(UI ui)
Creates a new instance for the given UI.
Parameters:
ui
- the UI to use
-
-
Method Detail
-
getStateTree
public StateTree getStateTree()
Gets the state tree of the related UI.
Returns:
the state tree
-
getLastProcessedClientToServerId
public int getLastProcessedClientToServerId()
Gets the last processed server message id.
Used internally for communication tracking.
Returns:
lastProcessedServerMessageId the id of the last processed server message
-
getLastProcessedMessageHash
public byte[] getLastProcessedMessageHash()
Gets the hash of the last processed message from the client.
The hash is set through
setLastProcessedClientToServerId(int, byte[])
.Used internally for communication tracking.
Returns:
the hash as a byte array, or
null
if no hash has been set
-
setLastProcessedClientToServerId
public void setLastProcessedClientToServerId(int lastProcessedClientToServerId, byte[] lastProcessedMessageHash)
Sets the last processed server message id.
Used internally for communication tracking.
Parameters:
lastProcessedClientToServerId
- the id of the last processed server messagelastProcessedMessageHash
- the hash of the message
-
getServerSyncId
public int getServerSyncId()
Gets the server sync id.
The sync id is incremented by one whenever a new response is written. This id is then sent over to the client. The client then adds the most recent sync id to each communication packet it sends back to the server. This way, the server knows at what state the client is when the packet is sent. If the state has changed on the server side since that, the server can try to adjust the way it handles the actions from the client side.
The sync id value
-1
is ignored to facilitate testing with pre-recorded requests.Returns:
the server sync id
-
incrementServerId
public void incrementServerId()
Increments the server sync id.
This should only be called by whoever sends a message to the client, after the message has been sent.
-
getLastHeartbeatTimestamp
public long getLastHeartbeatTimestamp()
Returns the timestamp of the last received heartbeat for the related UI.
This method is not intended to be overridden. If it is overridden, care should be taken since this method might be called in situations where
UI.getCurrent()
does not return the UI.Returns:
The time the last heartbeat request occurred, in milliseconds since the epoch.
See Also:
-
setLastHeartbeatTimestamp
public void setLastHeartbeatTimestamp(long lastHeartbeat)
Sets the last heartbeat request timestamp for the related UI. Called by the framework whenever the application receives a valid heartbeat request for the UI.
This method is not intended to be overridden. If it is overridden, care should be taken since this method might be called in situations where
UI.getCurrent()
does not return the UI.Parameters:
lastHeartbeat
- The time the last heartbeat request occurred, in milliseconds since the epoch.
-
setSession
public void setSession(VaadinSession session)
Sets the session to which the related UI is assigned.
This method is for internal use by the framework. To explicitly close a UI, see
UI.close()
.Parameters:
session
- the session to setThrows:
IllegalStateException
- if the session has already been setSee Also:
-
getPushConnection
public PushConnection getPushConnection()
Returns the internal push connection object used by the related UI. This method should only be called by the framework.
This method is not intended to be overridden. If it is overridden, care should be taken since this method might be called in situations where
UI.getCurrent()
does not return the UI.Returns:
the push connection used by the UI, or
null
if push is not available.
-
setPushConnection
public void setPushConnection(PushConnection pushConnection)
Sets the internal push connection object used by the related UI. This method should only be called by the framework.
The
pushConnection
argument must be non-null if and only ifgetPushConfiguration().getPushMode().isEnabled()
.Parameters:
pushConnection
- the push connection to use for the UI
-
addBeforeEnterListener
public Registration addBeforeEnterListener(BeforeEnterListener listener)
Add a listener that will be informed when a new set of components are going to be attached.
Parameters:
listener
- the before enter listenerReturns:
handler to remove the event listener
-
addBeforeLeaveListener
public Registration addBeforeLeaveListener(BeforeLeaveListener listener)
Add a listener that will be informed when old components are detached.
Parameters:
listener
- the before leave listenerReturns:
handler to remove the event listener
-
addAfterNavigationListener
public Registration addAfterNavigationListener(AfterNavigationListener listener)
Add a listener that will be informed when new components have been attached and all navigation tasks have resolved.
Parameters:
listener
- the after navigation listenerReturns:
handler to remove the event listener
-
getNavigationListeners
public <E> List<E> getNavigationListeners(Class<E> navigationHandler)
Get all registered listeners for given navigation handler type.
Type Parameters:
E
- the handler typeParameters:
navigationHandler
- handler to get listeners forReturns:
unmodifiable list of registered listeners for navigation handler
-
addJavaScriptInvocation
public Page.ExecutionCanceler addJavaScriptInvocation(UIInternals.JavaScriptInvocation invocation)
Adds a JavaScript invocation to be sent to the client.
Parameters:
invocation
- the invocation to addReturns:
a callback for canceling the execution if not yet sent to browser
-
dumpPendingJavaScriptInvocations
public List<UIInternals.JavaScriptInvocation> dumpPendingJavaScriptInvocations()
Gets all the pending JavaScript invocations and clears the queue.
Returns:
a list of pending JavaScript invocations
-
setTitle
public void setTitle(String title)
Records the page title set with
Page.setTitle(String)
.You should not set the page title for the browser with this method, use
Page.setTitle(String)
instead.Parameters:
title
- the title to set
-
getTitle
public String getTitle()
Gets the page title recorded with
Page.setTitle(String)
.NOTE this might not be up to date with the actual title set since it is not updated from the browser and the update might have been canceled before it has been sent to the browser with
cancelPendingTitleUpdate()
.Returns:
the page title
-
cancelPendingTitleUpdate
public boolean cancelPendingTitleUpdate()
Cancels any pending page title update set via
setTitle(String)
.Returns:
true
if pending title update was cancelled,false
if not
-
showRouteTarget
public void showRouteTarget(Location viewLocation, String path, Component target, List<RouterLayout> layouts)
Shows a route target in the related UI. This method is intended for framework use only. Use
UI.navigate(String)
to change the route target that is shown in a UI.Parameters:
viewLocation
- the location of the route target relative to the servlet serving the UI, notnull
target
- the component to show, notnull
path
- the resolved route path so we can determine what the rendered target is forlayouts
- the parent layouts
-
getActiveRouterTargetsChain
public List<HasElement> getActiveRouterTargetsChain()
Gets the currently active router target and parent layouts.
Returns:
a list of active router target and parent layout instances, starting from the innermost part
-
getActiveViewLocation
public Location getActiveViewLocation()
Gets the location of the currently shown view. The location is relative the servlet mapping used for serving the related UI.
Returns:
the view location, not
null
-
getSession
public VaadinSession getSession()
Gets the VaadinSession to which the related UI is attached.
The method will return
null
if the UI is not currently attached to a VaadinSession.Returns:
the VaadinSession to which the related UI is attached
-
getDependencyList
public DependencyList getDependencyList()
Returns the helper which handles loading of dependencies (css, js).
Returns:
the dependency list helper
-
addComponentDependencies
public void addComponentDependencies(Class<? extends Component> componentClass)
Adds the dependencies defined using
StyleSheet
,JavaScript
orHtmlImport
on the given Component class.Parameters:
componentClass
- the component class to read annotations from
-
getConstantPool
public ConstantPool getConstantPool()
Gets the constant pool that is used for keeping track of constants shared with the client for this UI.
Returns:
the constant pool to use, not
null
-
getLastHandledLocation
public Location getLastHandledLocation()
Get the latest handled location or empty optional if no active navigation.
Returns:
location if navigated during active navigation or
null
-
setLastHandledNavigation
public void setLastHandledNavigation(Location location)
Set the latest navigation location for active navigation.
Parameters:
location
- last location navigated to
-
hasLastHandledLocation
public boolean hasLastHandledLocation()
Check if we have already started navigation to some location on this roundtrip.
Returns:
true if the last navigation location
!=
null
-
clearLastHandledNavigation
public void clearLastHandledNavigation()
Clear latest handled navigation location.
-
getContinueNavigationAction
public BeforeLeaveEvent.ContinueNavigationAction getContinueNavigationAction()
Get stored
BeforeLeaveEvent.ContinueNavigationAction
if any.Returns:
continue navigation action object
-
setContinueNavigationAction
public void setContinueNavigationAction(BeforeLeaveEvent.ContinueNavigationAction continueNavigationAction)
Set a
BeforeLeaveEvent.ContinueNavigationAction
or null to clear existing action.Parameters:
continueNavigationAction
- continue navigatio action to store or null
-
setAppId
public void setAppId(String appId)
Sets the application id tied with this UI. Different applications in the same page have different unique ids.
Parameters:
appId
- the id of the application tied with this UI
-
getAppId
public String getAppId()
Gets the application id tied with this UI. Different applications in the same page have different unique ids.
Returns:
the id of the application tied with this UI
-
getRouter
public Router getRouter()
Gets the router used for navigating in this UI, if the router was active when this UI was initialized.
Returns:
the router used for this UI, or
null
if there is no router
-
isDirty
public boolean isDirty()
Checks if there are changes waiting to be sent to the client side.
Returns:
true
if there are pending changes,false
otherwise
-
setContextRoot
public void setContextRoot(String contextRootRelativePath)
Sets the relative path from the UI (servlet) path to the context root.
Parameters:
contextRootRelativePath
- the relative path from servlet to context root
-
getContextRootRelativePath
public String getContextRootRelativePath()
Gets the relative path from the UI (servlet) path to the context root.
Returns:
the relative path from servlet to context root
-
getUI
public UI getUI()
Gets the UI that this instance belongs to.
Returns:
the UI instance.
-
-