Merge with d1e79f3c8c8779d14ab5297049bdc0812f942654
[pithos] / src / gr / ebs / gss / client / MessagePanel.java
1 /*\r
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
3  *\r
4  * This file is part of GSS.\r
5  *\r
6  * GSS is free software: you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation, either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * GSS is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
18  */\r
19 package gr.ebs.gss.client;\r
20 \r
21 import gr.ebs.gss.client.animation.FadeIn;\r
22 import gr.ebs.gss.client.animation.FadeOut;\r
23 \r
24 import com.google.gwt.core.client.GWT;\r
25 import com.google.gwt.user.client.DOM;\r
26 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
27 import com.google.gwt.user.client.ui.ClickListener;\r
28 import com.google.gwt.user.client.ui.Composite;\r
29 import com.google.gwt.user.client.ui.HTML;\r
30 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
31 import com.google.gwt.user.client.ui.HasVerticalAlignment;\r
32 import com.google.gwt.user.client.ui.HorizontalPanel;\r
33 import com.google.gwt.user.client.ui.ImageBundle;\r
34 import com.google.gwt.user.client.ui.SimplePanel;\r
35 import com.google.gwt.user.client.ui.Widget;\r
36 \r
37 /**\r
38  * A panel that displays various system messages.\r
39  */\r
40 public class MessagePanel extends Composite {\r
41         /**\r
42          * An image bundle for this widget's images.\r
43          */\r
44         public interface Images extends ImageBundle {\r
45                 @Resource("gr/ebs/gss/resources/messagebox_info.png")\r
46                 AbstractImagePrototype info();\r
47 \r
48                 @Resource("gr/ebs/gss/resources/messagebox_warning.png")\r
49                 AbstractImagePrototype warn();\r
50 \r
51                 @Resource("gr/ebs/gss/resources/messagebox_critical.png")\r
52                 AbstractImagePrototype error();\r
53         }\r
54 \r
55         /**\r
56          * The widget's images.\r
57          */\r
58         public static Images images;\r
59 \r
60         /**\r
61          * The system message to be displayed.\r
62          */\r
63         private HTML message = new HTML("&nbsp;");\r
64 \r
65         /**\r
66          * A link to clear the displayed message.\r
67          */\r
68         private HTML clearMessageLink = new HTML("<a class='gss-clearMessage' href='javascript:;'>Clear</a>");\r
69 \r
70         /**\r
71          * The panel that contains the messages.\r
72          */\r
73         private HorizontalPanel inner = new HorizontalPanel();\r
74 \r
75         /**\r
76          * The panel that enables special effects for this widget.\r
77          */\r
78         private SimplePanel simplePanel = new SimplePanel();\r
79 \r
80         /**\r
81          * The widget's constructor.\r
82          *\r
83          * @param newImages a bundle that provides the images for this widget\r
84          */\r
85         public MessagePanel(final Images newImages) {\r
86                 images = newImages;\r
87                 buildPanel();\r
88                 simplePanel.setStyleName("effectPanel");\r
89                 inner.setStyleName("effectPanel-inner");\r
90                 DOM.setStyleAttribute(simplePanel.getElement(), "zoom", "1");\r
91                 simplePanel.add(inner);\r
92                 initWidget(simplePanel);\r
93         }\r
94 \r
95         /**\r
96          * Build the panel that contains the icon, the message and the 'clear' link.\r
97          */\r
98         private void buildPanel() {\r
99                 inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);\r
100                 inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);\r
101                 inner.setSpacing(4);\r
102                 inner.add(message);\r
103                 inner.add(clearMessageLink);\r
104                 inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);\r
105 \r
106                 clearMessageLink.addClickListener(new ClickListener() {\r
107 \r
108                         public void onClick(final Widget sender) {\r
109                                 FadeOut anim = new FadeOut(simplePanel){\r
110                                         @Override\r
111                                         protected void onComplete() {\r
112                                                 super.onComplete();\r
113                                                 hideMessage();\r
114                                         }\r
115                                 };\r
116                                 anim.run(1000);\r
117                         }\r
118                 });\r
119         }\r
120 \r
121         /**\r
122          * Display an error message.\r
123          *\r
124          * @param msg the message to display\r
125          */\r
126         public void displayError(final String msg) {\r
127                 GWT.log(msg, null);\r
128                 message = new HTML("<table class='gss-errorMessage'><tr><td>" + images.error().getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
129                 message.addClickListener(new ClickListener() {\r
130 \r
131                         public void onClick(final Widget sender) {\r
132                                 FadeOut anim = new FadeOut(simplePanel){\r
133 \r
134                                         @Override\r
135                                         protected void onComplete() {\r
136                                                 super.onComplete();\r
137                                                 hideMessage();\r
138                                         }\r
139                                 };\r
140                                 anim.run(1000);\r
141                         }\r
142                 });\r
143                 buildPanel();\r
144                 setVisible(true);\r
145                 FadeIn anim = new FadeIn(simplePanel);\r
146                 anim.run(1000);\r
147         }\r
148 \r
149         /**\r
150          * Display a warning message.\r
151          *\r
152          * @param msg the message to display\r
153          */\r
154         public void displayWarning(final String msg) {\r
155                 message = new HTML("<table class='gss-warnMessage'><tr><td>" + images.warn().getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
156                 message.addClickListener(new ClickListener() {\r
157 \r
158                         public void onClick(final Widget sender) {\r
159                                 FadeOut anim = new FadeOut(simplePanel){\r
160 \r
161                                         @Override\r
162                                         protected void onComplete() {\r
163                                                 super.onComplete();\r
164                                                 hideMessage();\r
165                                         }\r
166                                 };\r
167                                 anim.run(1000);\r
168                         }\r
169                 });\r
170 \r
171                 buildPanel();\r
172                 setVisible(true);\r
173                 FadeIn anim = new FadeIn(simplePanel);\r
174                 anim.run(1000);\r
175         }\r
176 \r
177         /**\r
178          * Display an informational message.\r
179          *\r
180          * @param msg the message to display\r
181          */\r
182         public void displayInformation(final String msg) {\r
183                 message = new HTML("<table class='gss-infoMessage'><tr><td>" + images.info().getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
184                 message.addClickListener(new ClickListener() {\r
185 \r
186                         public void onClick(final Widget sender) {\r
187                                 FadeOut anim = new FadeOut(simplePanel){\r
188 \r
189                                         @Override\r
190                                         protected void onComplete() {\r
191                                                 super.onComplete();\r
192                                                 hideMessage();\r
193                                         }\r
194                                 };\r
195                                 anim.run(1000);\r
196                         }\r
197                 });\r
198 \r
199                 buildPanel();\r
200                 setVisible(true);\r
201                 FadeIn anim = new FadeIn(simplePanel);\r
202                 anim.run(1000);\r
203         }\r
204 \r
205         /**\r
206          * Clear the displayed message and hide the panel.\r
207          */\r
208         public void hideMessage() {\r
209                 inner.clear();\r
210                 message = new HTML("&nbsp;");\r
211                 this.setVisible(false);\r
212         }\r
213 \r
214 }\r