Class UI


public class UI extends MessageBus

UI base class

Applications made with the JBStrap framework can have multiple UIs defined, that can be display pages. The UIs function similarly like the pages, but during navigation, if two pages have to be displayed on the same UI, then the UI instance and display does not change. Thus, the components placed on the UI (we recommend using navigation components) do not change either, if the navigation is done within the UI.

In the application, every UI has to extend from this class.

Since:
4.0
Author:
JBStrap
  • Field Details

  • Constructor Details

    • UI

      public UI(String clientId)
      Creates a UI
      Parameters:
      clientId - The client ID, where the UI will be shown
      Throws:
      NullPointerException - If the client is specified as null
      IllegalStateException - If the component is set to be both Private and Public.
  • Method Details

    • getId

      public final String getId()
      Gets the UI's unique ID
      Returns:
      The UI's unique ID
    • getComponentById

      public Component<?> getComponentById(String id)
      Gets a component (specified by the ID) from the UI.
      Parameters:
      id - The ID of the component
      Returns:
      The component instance corresponding to the previously specified ID, or null, if not found.
    • getComponents

      public Collection<Component<?>> getComponents()
      Gets a collection of every component that is on the UI
      Returns:
      A collection of component instances, that are assigned to the UI. If there are none, it will return with an empty list
    • getComponentsByClass

      public final <T> List<T> getComponentsByClass(Class<T> clazz)
      Gets a list of every component, (specified by the class) from the UI.
      Type Parameters:
      T - The component type
      Parameters:
      clazz - The class of the component(s) that we want to get
      Returns:
      A list of component insances of the specified class
      Throws:
      NullPointerException - If the class was specified as null
    • draw

      public void draw(StringWriter writer)
    • getCurrentPage

      public BasePage getCurrentPage()
      Gets the page that is currently displayed on the UI
      Returns:
      The instance of the page, or null, if no page is currently displayed
    • findPage

      public BasePage findPage(String pageId)
      Gets a page from the UI that is specified by the page ID.
      Parameters:
      pageId - The page ID
      Returns:
      The page instance corresponding to the specified ID,or null if no page by that ID is currently open on the UI
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • runJavaScript

      public UI runJavaScript(String script)
      Runs the specified JavaScript on the client, where the UI is currently displayed.
      Parameters:
      script - The JavaScript
      Returns:
      The UI object
    • getClient

      public Client getClient()
      Gets the client, where the UI is currently displayed.
      Returns:
      The client class, where the UI is currently displayed.
      See Also:
    • getCurrentUser

      public CurrentUser getCurrentUser()
      Gets the object containing the data of the currently logged in user
      Returns:
      The object containing the data of the currently logged in user or null, if no logged in user is found
      See Also:
    • removeComponent

      public UI removeComponent(Component<?> component)
      Removes the specified component from the UI
      Parameters:
      component - The component instance to be removed
      Returns:
      The UI object
    • removeComponent

      public UI removeComponent(Predicate<Component<?>> filter)
      Removes the component(s), that are specified by the predicate.
      Parameters:
      filter - The predicate, that will be used as a filter
      Returns:
      The UI object
    • removeComponents

      public UI removeComponents(Component<?>... components)
      Removes the specified components from the UI
      Parameters:
      components - The component instances to be removed
      Returns:
      The UI object
    • removeAllComponents

      public UI removeAllComponents()
      Removes every component from the UI
      Returns:
      The UI object
    • showNotification

      public void showNotification(NotificationType notificationType, String title)
      Displays the specified notification on the interface.
      Parameters:
      notificationType - The notification type. See the NotificationType enum for applicable values.
      title - The notification title (header text)
    • showNotification

      public void showNotification(NotificationType notificationType, String title, String message)
      Displays the specified notification on the interface.
      Parameters:
      notificationType - The notification type. See the NotificationType enum for applicable values.
      title - The notification title (header text)
      message - The notification message
    • setLiveFavicon

      public final UI setLiveFavicon(LiveFavicon liveFavicon)
      Sets the LiveFavicon instance, that will be displayed on the UI
      Parameters:
      liveFavicon - The LiveFavicon instance
      Returns:
      The UI object
    • changeLiveFaviconText

      public final UI changeLiveFaviconText(String text)
      Changes the currently displayed live favicon content. This method can only be used, if the UI already has a LiveFavicon instance assigned.
      Parameters:
      text - The favicon text content
      Returns:
      The UI object
      Throws:
      NullPointerException - If the UI has no LiveFavicon instance assigned.
    • error

      public final void error(String title, String message)
      Shows the specified error message to the user
      Parameters:
      title - The error title (header text)
      message - The error message
    • say

      public void say(String title, String message)
      Shows a message in a popup window.
      Parameters:
      title - The message title (header text)
      message - The message text
    • ask

      public final boolean ask(String title, String text)
      Shows the specified question message to the user.
      Parameters:
      title - The message title (header text)
      text - The message text
      Returns:
      The user's answer. Returns true, if the user clicked the okButton, otherwise false.
    • input

      public final String input(String title, String text)
      Shows an input window to the user
      Parameters:
      title - The message title (header text)
      text - The message text
      Returns:
      The text that the user typed in. If the user didn't write anything, or closed the window, by pressing the cancel button, it will return with null.
    • isAccess

      public boolean isAccess()
      Returns:
      true, if they have access, otherwise false
    • getAccess

      public com.jbstrap.ui.Access getAccess()
      Returns:
      The UI access class
    • showProcessIndicator

      public final UI showProcessIndicator(boolean show)
      Shows or hides the Process Indicator
      Parameters:
      show - If true, the indicator is shown, if false, it is hidden
      Returns:
      The UI object
    • addComponent

      public UI addComponent(Component<?> component)
      Adds the specified component to the UI
      Parameters:
      component - The instance of the component to be added
      Returns:
      The UI object
    • addComponents

      public UI addComponents(Component<?>... components)
      Adds the specified components to the UI
      Parameters:
      components - The instances of the components to be added
      Returns:
      The UI object
    • getRoot

      public UI.RootLayout getRoot()
      Returns:
      The root layout
    • getLanguageCode

      public String getLanguageCode()
      Gets the UI language code
      Returns:
      The UI language code
    • getOpenedPages

      public List<BasePage> getOpenedPages()
      Returns:
      A list of every page that is currently open on the UI
    • getComponentSeq

      protected Integer getComponentSeq(String typeName)
      Parameters:
      typeName - Component type
      Returns:
      Component type sequence number