Class UIInternals
- java.lang.Object
-
- com.vaadin.flow.component.internal.UIInternals
-
- All Implemented Interfaces:
Serializable
public class UIInternals extends Object implements Serializable
Holds UI-specific methods and data which are intended for internal use by the framework.For internal use only. May be renamed or removed in a future release.
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUIInternals.JavaScriptInvocationAPage.executeJs(String, Serializable...)invocation that has not yet been sent to the client.
-
Constructor Summary
Constructors Constructor Description UIInternals(UI ui)Creates a new instance for the given UI.UIInternals(UI ui, UIInternalUpdater internalsHandler)Creates a new instance for the given UI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddAfterNavigationListener(AfterNavigationListener listener)Add a listener that will be informed when new components have been attached and all navigation tasks have resolved.RegistrationaddBeforeEnterListener(BeforeEnterListener listener)Add a listener that will be informed when a new set of components are going to be attached.RegistrationaddBeforeLeaveListener(BeforeLeaveListener listener)Add a listener that will be informed when old components are detached.voidaddComponentDependencies(Class<? extends Component> componentClass)Adds the dependencies defined usingStyleSheetorJavaScripton the given Component class.RegistrationaddHeartbeatListener(HeartbeatListener listener)voidaddJavaScriptInvocation(PendingJavaScriptInvocation invocation)Adds a JavaScript invocation to be sent to the client.booleancancelPendingTitleUpdate()Cancels any pending page title update set viasetTitle(String).voidclearLastHandledNavigation()Clear latest handled navigation location.List<PendingJavaScriptInvocation>dumpPendingJavaScriptInvocations()Gets all the pending JavaScript invocations that are ready to be sent to a client.ComponentgetActiveDragSourceComponent()Gets the drag source of an active HTML5 drag event.ComponentgetActiveModalComponent()Get the active modal component if modal components set.List<HasElement>getActiveRouterTargetsChain()Gets the currently active router target and parent layouts.LocationgetActiveViewLocation()Gets the location of the currently shown view.StringgetAppId()Gets the application id tied with this UI.StringgetAppShellTitle()Gets the stored app shell title.ConstantPoolgetConstantPool()Gets the constant pool that is used for keeping track of constants shared with the client for this UI.StringgetContextRootRelativePath()Gets the relative path from the UI (servlet) path to the context root.BeforeLeaveEvent.ContinueNavigationActiongetContinueNavigationAction()Get storedBeforeLeaveEvent.ContinueNavigationActionif any.DependencyListgetDependencyList()Returns the helper which handles loading of dependencies (css, js).ExtendedClientDetailsgetExtendedClientDetails()The extended client details, if obtained, are cached in this field.LocationgetLastHandledLocation()Get the latest handled location or empty optional if no active navigation.longgetLastHeartbeatTimestamp()Returns the timestamp of the last received heartbeat for the related UI.intgetLastProcessedClientToServerId()Gets the last processed server message id.byte[]getLastProcessedMessageHash()Gets the hash of the last processed message from the client.<E> List<E>getListeners(Class<E> handler)Get all registered listeners for given navigation handler type.PushConnectiongetPushConnection()Returns the internal push connection object used by the related UI.RoutergetRouter()Gets the router used for navigating in this UI, if the router was active when this UI was initialized.intgetServerSyncId()Gets the server sync id.VaadinSessiongetSession()Gets the VaadinSession to which the related UI is attached.StateTreegetStateTree()Gets the state tree of the related UI.StringgetTitle()Gets the page title recorded withPage.setTitle(String).UIgetUI()Gets the UI that this instance belongs to.booleanhasLastHandledLocation()Check if we have already started navigation to some location on this roundtrip.booleanhasModalComponent()Check if we have a modal component defined for the UI.voidincrementServerId()Increments the server sync id.booleanisDirty()Checks if there are changes waiting to be sent to the client side.voidmoveElementsFrom(UI otherUI)Move all the children of the other UI to this current UI.voidsetActiveDragSourceComponent(Component activeDragSourceComponent)Sets the drag source of an active HTML5 drag event.voidsetAppId(String appId)Sets the application id tied with this UI.voidsetAppShellTitle(String appShellTitle)Records the text content of the title tag in the application shell.voidsetChildModal(Component child)Makes an existing child component modal.voidsetChildModeless(Component child)Sets the given child modeless.voidsetContextRoot(String contextRootRelativePath)Sets the relative path from the UI (servlet) path to the context root.voidsetContinueNavigationAction(BeforeLeaveEvent.ContinueNavigationAction continueNavigationAction)Set aBeforeLeaveEvent.ContinueNavigationActionor null to clear existing action.voidsetExtendedClientDetails(ExtendedClientDetails details)Updates the extended client details.voidsetLastHandledNavigation(Location location)Set the latest navigation location for active navigation.voidsetLastHeartbeatTimestamp(long lastHeartbeat)Sets the last heartbeat request timestamp for the related UI.voidsetLastProcessedClientToServerId(int lastProcessedClientToServerId, byte[] lastProcessedMessageHash)Sets the last processed server message id.voidsetPushConnection(PushConnection pushConnection)Sets the internal push connection object used by the related UI.voidsetRouterTargetChain(List<RouterLayout> layouts)Populate the routerTargetChain with RouterLayouts, but only if the target chain is empty.voidsetSession(VaadinSession session)Sets the session to which the related UI is assigned.voidsetTitle(String title)Records the page title set withPage.setTitle(String).voidshowRouteTarget(Location viewLocation, 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
-
UIInternals
public UIInternals(UI ui, UIInternalUpdater internalsHandler)
Creates a new instance for the given UI.- Parameters:
ui- the UI to useinternalsHandler- an implementation ofUIInternalUpdater
-
-
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
nullif 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
-1is 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:
VaadinService.closeInactiveUIs(VaadinSession)
-
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 set- Throws:
IllegalStateException- if the session has already been set- See Also:
getSession()
-
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
nullif 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
pushConnectionargument 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 listener- Returns:
- 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 listener- Returns:
- 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 listener- Returns:
- handler to remove the event listener
-
addHeartbeatListener
public Registration addHeartbeatListener(HeartbeatListener listener)
-
getListeners
public <E> List<E> getListeners(Class<E> handler)
Get all registered listeners for given navigation handler type.- Type Parameters:
E- the handler type- Parameters:
handler- handler to get listeners for- Returns:
- unmodifiable list of registered listeners for navigation handler
-
addJavaScriptInvocation
public void addJavaScriptInvocation(PendingJavaScriptInvocation invocation)
Adds a JavaScript invocation to be sent to the client.- Parameters:
invocation- the invocation to add
-
dumpPendingJavaScriptInvocations
public List<PendingJavaScriptInvocation> dumpPendingJavaScriptInvocations()
Gets all the pending JavaScript invocations that are ready to be sent to a client. Retains pending JavaScript invocations owned by invisible components in the queue.- Returns:
- a list of pending JavaScript invocations
-
setTitle
public void setTitle(String title)
Records the page title set withPage.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
-
setAppShellTitle
public void setAppShellTitle(String appShellTitle)
Records the text content of the title tag in the application shell.NOTE Intended for internal use, you should not call this method.
- Parameters:
appShellTitle- the appShellTitle to set
-
getTitle
public String getTitle()
Gets the page title recorded withPage.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
-
getAppShellTitle
public String getAppShellTitle()
Gets the stored app shell title.NOTE Intended for internal use, you should not call this method.
- Returns:
- the app shell title
-
cancelPendingTitleUpdate
public boolean cancelPendingTitleUpdate()
Cancels any pending page title update set viasetTitle(String).- Returns:
trueif pending title update was cancelled,falseif not
-
setRouterTargetChain
public void setRouterTargetChain(List<RouterLayout> layouts)
Populate the routerTargetChain with RouterLayouts, but only if the target chain is empty. If the chain contains elements the given list is ignored.- Parameters:
layouts- stored router target chain to set as last navigated chain
-
showRouteTarget
public void showRouteTarget(Location viewLocation, Component target, List<RouterLayout> layouts)
Shows a route target in the related UI. This method is intended for framework use only. UseUI.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, notnulltarget- the component to show, notnulllayouts- the parent layouts
-
moveElementsFrom
public void moveElementsFrom(UI otherUI)
Move all the children of the other UI to this current UI.- Parameters:
otherUI- the other UI to transfer content from.
-
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
nullif 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 usingStyleSheetorJavaScripton 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 storedBeforeLeaveEvent.ContinueNavigationActionif any.- Returns:
- continue navigation action object
-
setContinueNavigationAction
public void setContinueNavigationAction(BeforeLeaveEvent.ContinueNavigationAction continueNavigationAction)
Set aBeforeLeaveEvent.ContinueNavigationActionor null to clear existing action.- Parameters:
continueNavigationAction- continue navigation 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
nullif there is no router or the UI doesn't support navigation.
-
isDirty
public boolean isDirty()
Checks if there are changes waiting to be sent to the client side.- Returns:
trueif there are pending changes,falseotherwise
-
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
-
setActiveDragSourceComponent
public void setActiveDragSourceComponent(Component activeDragSourceComponent)
Sets the drag source of an active HTML5 drag event.- Parameters:
activeDragSourceComponent- the drag source component- Since:
- 2.0
-
getActiveDragSourceComponent
public Component getActiveDragSourceComponent()
Gets the drag source of an active HTML5 drag event.- Returns:
- Extension of the drag source component if the drag event is active and originated from this UI, null otherwise.
- Since:
- 2.0
-
getUI
public UI getUI()
Gets the UI that this instance belongs to.- Returns:
- the UI instance.
-
getExtendedClientDetails
public ExtendedClientDetails getExtendedClientDetails()
The extended client details, if obtained, are cached in this field.- Returns:
- the extended client details, or null if not yet received.
-
setExtendedClientDetails
public void setExtendedClientDetails(ExtendedClientDetails details)
Updates the extended client details.- Parameters:
details- the updated extended client details.
-
hasModalComponent
public boolean hasModalComponent()
Check if we have a modal component defined for the UI.- Returns:
trueif modal component is defined
-
getActiveModalComponent
public Component getActiveModalComponent()
Get the active modal component if modal components set.- Returns:
- the current active modal component
-
setChildModal
public void setChildModal(Component child)
Makes an existing child component modal. This will make the UI and the other components inside it inert - they will not react to any user interaction until the modal component is removed.In case there was an existing modal component in the UI already, that is made inert until the given new component is removed. The UI is no longer inert after all modal components have been removed from it. Inert state is updated automatically when a component is removed from the UI, no need to call anything. Moving an inert component will remove inert status.
- Parameters:
child- the child component to toggle modal
-
setChildModeless
public void setChildModeless(Component child)
Sets the given child modeless. The inert state of the UI and other child components is updated. This method is called automatically when a modal child component is removed from the UI.- Parameters:
child- the child component to make modeless
-
-