Skip to contentMethod: toString()
1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 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
12: * the License. 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
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.util.ui;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.Immutable;
31: import lombok.Getter;
32: import lombok.RequiredArgsConstructor;
33: import lombok.ToString;
34: import static it.tidalwave.util.BundleUtilities.getMessage;
35: import static lombok.AccessLevel.PROTECTED;
36:
37: /***********************************************************************************************************************
38: *
39: * @author Fabrizio Giudici
40: *
41: **********************************************************************************************************************/
42: @Immutable
43: @RequiredArgsConstructor(access = PROTECTED) @ToString
44: public class UserNotification
45: {
46: @Getter
47: protected final String text;
48:
49: @Getter
50: protected final String caption;
51:
52: /*******************************************************************************************************************
53: *
54: * Creates a notification with empty caption and text.
55: *
56: * @return the notification
57: *
58: ******************************************************************************************************************/
59: @Nonnull
60: public static UserNotification notification()
61: {
62: return new UserNotification("", "");
63: }
64:
65: /*******************************************************************************************************************
66: *
67: * Associates a caption to the notification.
68: *
69: * @param caption the caption
70: * @return the notification
71: *
72: ******************************************************************************************************************/
73: @Nonnull
74: public UserNotification withCaption (@Nonnull final String caption)
75: {
76: return new UserNotification(text, caption);
77: }
78:
79: /*******************************************************************************************************************
80: *
81: * Associates a caption to the notification, retrieved from a resource bundle.
82: *
83: * @param bundleClass the class where to search the resource bundle from
84: * @param resourceName the resource name of the caption in the bundle
85: * @param params some (optional) parameters to the resource
86: * @return the notification
87: *
88: ******************************************************************************************************************/
89: @Nonnull
90: public UserNotification withCaption (@Nonnull final Class<?> bundleClass,
91: @Nonnull final String resourceName,
92: @Nonnull final Object ... params)
93: {
94: return new UserNotification(text, getMessage(bundleClass, resourceName, params));
95: }
96:
97: /*******************************************************************************************************************
98: *
99: * Associates a text to the notification.
100: *
101: * @param text the text
102: * @return the notification
103: *
104: ******************************************************************************************************************/
105: @Nonnull
106: public UserNotification withText (@Nonnull final String text)
107: {
108: return new UserNotification(text, caption);
109: }
110:
111: /*******************************************************************************************************************
112: *
113: * Associates a text to the notification, retrieved from a resource bundle.
114: *
115: * @param bundleClass the class where to search the resource bundle from
116: * @param resourceName the resource name of the text in the bundle
117: * @param params some (optional) parameters to the resource
118: * @return the notification
119: *
120: ******************************************************************************************************************/
121: @Nonnull
122: public UserNotification withText (@Nonnull final Class<?> bundleClass,
123: @Nonnull final String resourceName,
124: @Nonnull final Object ... params)
125: {
126: return new UserNotification(getMessage(bundleClass, resourceName, params), caption);
127: }
128: }