Class WNotification

java.lang.Object
eu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WNotification

public class WNotification extends WObject
A class that represent a notification.

A notification is a message sent to the user that can be read from outside the webpage. For a page to be allowed to send notifications, permission must be explicitly given by the user to the application. The permission can be asked to the user with askPermission() or will be asked automatically the first time send() is called in the application. It is possible to listen to the permissionUpdated() signal to react to the user granting or denying permission to send notifications.

If the user has previously granted permission to the page to display notifications, the browser will remember it, and JWt will not ask for that permission again.

The WNotification will not be sent to the user if the permission has not yet been granted. Instead, the notification will wait for the user to accept notifications before being sent. This will however not happen if the notification was closed or destroyed.

A WNotification represents a notification with a tag. The value of this tag is the id of the WNotification. If the same WNotification is sent multiple times, this will update the notification instead of creating a new one, as long as it was not closed.

You can react to a notification being closed or clicked by listening to the closed() and clicked() signals, this does however require that the WNotification has not been destroyed before the event happens.

Notifications can have an icon and a badge. Those can be set using setIcon() and setBadge(), but since these are likely the same for all the notifications sent by your application, it is possible to set a default icon and a default badge for all notifications with setDefaultIcon() and setDefaultBadge().

See Also:
  • Constructor Details

  • Method Details

    • setTitle

      public void setTitle(CharSequence title)
      Sets the title of the notification.

      This sets the title of the notification.

      By default, the title is an empty string.

    • getTitle

      public WString getTitle()
      Returns the title of the notification.

      See Also:
    • setBody

      public void setBody(CharSequence body)
      Sets the body of the notification.

      This sets the body of the notification.

      By default, the notification has no body, which is represented by an empty string.

    • getBody

      public WString getBody()
      Returns the body of the notification.

      Returns the body of the notification or an empty string if the notification has no body.

      See Also:
    • setIcon

      public void setIcon(WLink iconLink)
      Sets the link to the notification's icon.

      This sets the link to the notification's icon which is the image displayed on the left of the notification.

      By default, the icon is set to the default icon.

      See Also:
    • getIcon

      public WLink getIcon()
      Returns the link to the notification's icon.

      Returns the link to the notification's icon or a null link if the notification uses the default icon.

      By default, the icon is set to the default icon.

      See Also:
    • setBadge

      public void setBadge(WLink badgeLink)
      Sets the link to the notification's badge.

      This sets the link to the notification's badge which is the image displayed when there is not enough space to display the notification.

      By default, the badge is set to the default badge.

      See Also:
    • getBadge

      public WLink getBadge()
      Returns the link to the notification's badge.

      Returns the link to the notification's badge.

      By default, the badge is set to the default badge.

      See Also:
    • setSilent

      public void setSilent(boolean enable)
      Sets whether the notification should be silent or not.

      This sets whether the notification should be silent or not. A silent notification will not make any noise or vibration.

      By default, the notification is not silent.

      Note: A non silent notification may still make no noise or vibration as it will respect the user's configuration.

    • setSilent

      public final void setSilent()
      Sets whether the notification should be silent or not.

      Calls setSilent(true)

    • isSilent

      public boolean isSilent()
      Returns whether the notification should be silent or not.

      See Also:
    • setRequireInteraction

      public void setRequireInteraction(boolean enable)
      Sets whether the notification require interaction to become inactive or not.

      This sets whether the notification should remain active until the user click's on it or dismiss it.

      By default, this is set to false.

    • setRequireInteraction

      public final void setRequireInteraction()
      Sets whether the notification require interaction to become inactive or not.

      Calls setRequireInteraction(true)

    • isRequireInteraction

      public boolean isRequireInteraction()
      Returns whether the notification require interaction to become inactive or not.

      See Also:
    • send

      public void send()
      Sends the notification.

      Sends the notification to the user. This only happens if the permission to send notification has been granted by the user.

      In case the user has not denied or granted notification to the user, the first call to send will instead ask for permission to send notification. The notification will then be sent after the user granted permission to send notification, unless this notification was closed or destroyed.

      Calling send() multiple times on the same notification will not create multiple notification but replace the previous with the new one, as long as the previous one has not been closed. This means that the user will not be notified again for this notification unless the previous one has been closed.

      See Also:
    • close

      public void close()
      Closes the notification.

      Closes the notification. This does nothing if the notification was not sent or was already closed.

      See Also:
    • clicked

      public JSignal clicked()
      Signal emitted when the notification is clicked.
    • closed

      public JSignal closed()
      Signal emitted when the notification is closed.
    • shown

      public JSignal shown()
      Signal emitted when the notification is shown.
    • error

      public JSignal error()
      Signal emitted when the notification was not shown due to an error.
    • setDefaultIcon

      public static void setDefaultIcon(WLink iconLink)
      Sets the link to the notifications default icon.

      By default, this is a null link which means no default icon is used.

      See Also:
    • getDefaultIcon

      public static WLink getDefaultIcon()
      Returns the link to the notifications default icon.

      See Also:
    • setDefaultBadge

      public static void setDefaultBadge(WLink badgeLink)
      Sets the link to the notifications default badge.

      By default, this is a null link which means no default badge is used.

      See Also:
    • getDefaultBadge

      public static WLink getDefaultBadge()
      Returns the link to the notifications default badge.

      See Also:
    • isSupported

      public static boolean isSupported()
      Returns whether the user supports notifications or not.
    • askPermission

      public static void askPermission()
      Ask permission to send notifications to the user.

      This ask permission to the user to send notifications. This will only be done once per application. More calls to this function will not do anything.

      See Also:
    • getPermission

      public static WNotification.Permission getPermission()
      Returns the status of the permission to send notifications.

      See Also:
    • permissionUpdated

      public static Signal1<WNotification.Permission> permissionUpdated()
      Signal emitted when the permission to send notification has been updated.

      Signal emitted when the permission to send notification has been updated. This happens when the user answered to askPermission(), and the new permission status is given by the signal as parameter to all connected functions.

      See Also: