1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.widgets;
13 /***
14 * Contains three kinds of messages: error message, warning and info.
15 * @author Martin Vysny
16 */
17 public enum MessageLevelEnum {
18 /***
19 * Error message.
20 */
21 ERROR {
22 @Override
23 public void setMessageInternal(ValidityMessages messages, String message) {
24 if (messages.error != null)
25 return;
26 messages.error = message;
27 }
28 },
29 /***
30 * Warning message.
31 */
32 WARNING {
33 @Override
34 public void setMessageInternal(ValidityMessages messages, String message) {
35 if (messages.warning != null)
36 return;
37 messages.warning = message;
38 }
39 },
40 /***
41 * Info message.
42 */
43 INFO {
44 @Override
45 public void setMessageInternal(ValidityMessages messages, String message) {
46 if (messages.info != null)
47 return;
48 messages.info = message;
49 }
50 };
51 /***
52 * Produces validity messages instance, with given message. Message must not
53 * change when it already is non-<code>null</code> in given messages
54 * object.
55 * @param message set this message
56 * @param messages set the message to this object.
57 */
58 protected abstract void setMessageInternal(ValidityMessages messages,
59 String message);
60 /***
61 * Produces validity messages instance, with given message. Message does not
62 * change when it already is non-<code>null</code> in given messages
63 * object.
64 * @param message set this message
65 * @param messages set the message to this object. If <code>null</code>
66 * then new instance of validity messages object shall be created.
67 * @return <code>messages</code>, or new instance of messages object if
68 * messages was <code>null</code>.
69 */
70 public final ValidityMessages setMessage(ValidityMessages messages,
71 String message) {
72 if (messages == null)
73 return newMessage(message);
74 setMessageInternal(messages, message);
75 return messages;
76 }
77 /***
78 * Produces validity messages instance, with given message.
79 * @param message message to set
80 * @return new instance of messages object
81 */
82 public final ValidityMessages newMessage(String message) {
83 ValidityMessages result = new ValidityMessages();
84 setMessage(result, message);
85 return result;
86 }
87 }