View Javadoc

1   /*
2    * Created on Mar 13, 2005. Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the "License"); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
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  }