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:
  • Constructor Details

    • 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 use
      internalsHandler - an implementation of UIInternalUpdater
  • Method Details

    • 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 message
      lastProcessedMessageHash - 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:
      • 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:
    • 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 if getPushConfiguration().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 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
    • 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 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
    • 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 via setTitle(String).
      Returns:
      true if pending title update was cancelled, false if not
    • 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. 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, not null
      target - the component to show, not null
      layouts - 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 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 or JavaScript 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()
      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 navigation action to store or null
    • setFullAppId

      public void setFullAppId(String fullAppId)
      Sets the application id tied with this UI. Different applications in the same page have different unique ids.
      Parameters:
      fullAppId - the (full, not stripped) 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
    • getFullAppId

      public String getFullAppId()
      Gets the full app id, which funnily enough is not the same as appId. This really should be removed but not right now. Don't use this method, it will be gone.
      Returns:
      the full app id
    • 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 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:
      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
    • 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:
      true if 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
    • getContainerTag

      public String getContainerTag()