UserNotification.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * SteelBlue: DCI User Interfaces
  5.  * http://tidalwave.it/projects/steelblue
  6.  *
  7.  * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/steelblue-src
  22.  * git clone https://github.com/tidalwave-it/steelblue-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.ui.core;

  27. import jakarta.annotation.Nonnull;
  28. import javax.annotation.concurrent.Immutable;
  29. import lombok.Getter;
  30. import lombok.RequiredArgsConstructor;
  31. import lombok.ToString;
  32. import static it.tidalwave.util.BundleUtilities.getMessage;
  33. import static lombok.AccessLevel.PROTECTED;

  34. /***************************************************************************************************************************************************************
  35.  *
  36.  * This class models a notification that will be presented to a user, without a feedback.
  37.  *
  38.  * @since   2.0-ALPHA-2
  39.  * @author  Fabrizio Giudici
  40.  *
  41.  **************************************************************************************************************************************************************/
  42. @Getter @Immutable
  43. @RequiredArgsConstructor(access = PROTECTED) @ToString
  44. public class UserNotification
  45.   {
  46.     @Nonnull
  47.     protected final String text;

  48.     @Nonnull
  49.     protected final String caption;

  50.     /***********************************************************************************************************************************************************
  51.      * {@return a notification with empty caption and text}.
  52.      **********************************************************************************************************************************************************/
  53.     @Nonnull
  54.     public static UserNotification notification()
  55.       {
  56.         return new UserNotification("", "");
  57.       }

  58.     /***********************************************************************************************************************************************************
  59.      * {@return a notification with a caption}.
  60.      * @param  caption       the caption
  61.      **********************************************************************************************************************************************************/
  62.     @Nonnull
  63.     public UserNotification withCaption (@Nonnull final String caption)
  64.       {
  65.         return new UserNotification(text, caption);
  66.       }

  67.     /***********************************************************************************************************************************************************
  68.      * {@return a notification with a caption from a bundle}.
  69.      * @param  bundleClass   the class where to search the resource bundle from
  70.      * @param  resourceName  the resource name of the caption in the bundle
  71.      * @param  params        some (optional) parameters to the resource
  72.      **********************************************************************************************************************************************************/
  73.     @Nonnull
  74.     public UserNotification withCaption (@Nonnull final Class<?> bundleClass, @Nonnull final String resourceName, @Nonnull final Object ... params)
  75.       {
  76.         return new UserNotification(text, getMessage(bundleClass, resourceName, params));
  77.       }

  78.     /***********************************************************************************************************************************************************
  79.      * {@return a notification with a text}.
  80.      * @param  text          the text
  81.      **********************************************************************************************************************************************************/
  82.     @Nonnull
  83.     public UserNotification withText (@Nonnull final String text)
  84.       {
  85.         return new UserNotification(text, caption);
  86.       }

  87.     /***********************************************************************************************************************************************************
  88.      * {@return a notification with a text from a bundle}.
  89.      * @param  bundleClass   the class where to search the resource bundle from
  90.      * @param  resourceName  the resource name of the text in the bundle
  91.      * @param  params        some (optional) parameters to the resource
  92.      **********************************************************************************************************************************************************/
  93.     @Nonnull
  94.     public UserNotification withText (@Nonnull final Class<?> bundleClass,  @Nonnull final String resourceName, @Nonnull final Object ... params)
  95.       {
  96.         return new UserNotification(getMessage(bundleClass, resourceName, params), caption);
  97.       }
  98.   }