CSS fixes
[pithos-web-client] / src / gr / grnet / pithos / web / client / MessagePanel.java
1 /*\r
2  * Copyright 2011 GRNET S.A. All rights reserved.\r
3  *\r
4  * Redistribution and use in source and binary forms, with or\r
5  * without modification, are permitted provided that the following\r
6  * conditions are met:\r
7  *\r
8  *   1. Redistributions of source code must retain the above\r
9  *      copyright notice, this list of conditions and the following\r
10  *      disclaimer.\r
11  *\r
12  *   2. Redistributions in binary form must reproduce the above\r
13  *      copyright notice, this list of conditions and the following\r
14  *      disclaimer in the documentation and/or other materials\r
15  *      provided with the distribution.\r
16  *\r
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
28  * POSSIBILITY OF SUCH DAMAGE.\r
29  *\r
30  * The views and conclusions contained in the software and\r
31  * documentation are those of the authors and should not be\r
32  * interpreted as representing official policies, either expressed\r
33  * or implied, of GRNET S.A.\r
34  */\r
35 package gr.grnet.pithos.web.client;\r
36 \r
37 import gr.grnet.pithos.web.client.animation.FadeIn;\r
38 import gr.grnet.pithos.web.client.animation.FadeOut;\r
39 \r
40 import com.google.gwt.core.client.GWT;\r
41 import com.google.gwt.event.dom.client.ClickEvent;\r
42 import com.google.gwt.event.dom.client.ClickHandler;\r
43 import com.google.gwt.resources.client.ClientBundle;\r
44 import com.google.gwt.resources.client.ImageResource;\r
45 import com.google.gwt.user.client.DOM;\r
46 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
47 import com.google.gwt.user.client.ui.Composite;\r
48 import com.google.gwt.user.client.ui.HTML;\r
49 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
50 import com.google.gwt.user.client.ui.HasVerticalAlignment;\r
51 import com.google.gwt.user.client.ui.HorizontalPanel;\r
52 import com.google.gwt.user.client.ui.SimplePanel;\r
53 \r
54 /**\r
55  * A panel that displays various system messages.\r
56  */\r
57 public class MessagePanel extends Composite {\r
58         /**\r
59          * An image bundle for this widget's images.\r
60          */\r
61         public interface Images extends ClientBundle {\r
62                 @Source("gr/grnet/pithos/resources/messagebox_info.png")\r
63                 ImageResource info();\r
64 \r
65                 @Source("gr/grnet/pithos/resources/messagebox_warning.png")\r
66                 ImageResource warn();\r
67 \r
68                 @Source("gr/grnet/pithos/resources/messagebox_critical.png")\r
69                 ImageResource error();\r
70         }\r
71 \r
72         /**\r
73          * The widget's images.\r
74          */\r
75         public static Images images;\r
76 \r
77         /**\r
78          * The system message to be displayed.\r
79          */\r
80         private HTML message = new HTML(" ");\r
81 \r
82         /**\r
83          * A link to clear the displayed message.\r
84          */\r
85         private HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>");\r
86 \r
87         /**\r
88          * The panel that contains the messages.\r
89          */\r
90         private HorizontalPanel inner = new HorizontalPanel();\r
91 \r
92         /**\r
93          * The panel that enables special effects for this widget.\r
94          */\r
95         protected SimplePanel simplePanel = new SimplePanel();\r
96 \r
97         /**\r
98          * The widget's constructor.\r
99          *\r
100          * @param newImages a bundle that provides the images for this widget\r
101          */\r
102         public MessagePanel(final Images newImages) {\r
103                 images = newImages;\r
104                 buildPanel();\r
105                 simplePanel.setStyleName("effectPanel");\r
106                 inner.setStyleName("effectPanel-inner");\r
107                 DOM.setStyleAttribute(simplePanel.getElement(), "zoom", "1");\r
108                 simplePanel.add(inner);\r
109                 initWidget(simplePanel);\r
110         }\r
111 \r
112         /**\r
113          * Build the panel that contains the icon, the message and the 'clear' link.\r
114          */\r
115         private void buildPanel() {\r
116                 inner.clear();\r
117                 inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);\r
118                 inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);\r
119 //              inner.setSpacing(4);\r
120                 inner.add(message);\r
121                 inner.add(clearMessageLink);\r
122                 inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);\r
123                 clearMessageLink.addClickHandler(new ClickHandler() {\r
124 \r
125                         @Override\r
126                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
127                                 FadeOut anim = new FadeOut(simplePanel){\r
128                                         @Override\r
129                                         protected void onComplete() {\r
130                                                 super.onComplete();\r
131                                                 hideMessage();\r
132                                         }\r
133                                 };\r
134                                 anim.run(500);\r
135                         }\r
136                 });\r
137         }\r
138 \r
139         /**\r
140          * Display an error message.\r
141          *\r
142          * @param msg the message to display\r
143          */\r
144         public void displayError(final String msg) {\r
145                 GWT.log(msg, null);\r
146                 message = new HTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
147                 message.addClickHandler(new ClickHandler() {\r
148 \r
149                         @Override\r
150                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
151                                 FadeOut anim = new FadeOut(simplePanel){\r
152 \r
153                                         @Override\r
154                                         protected void onComplete() {\r
155                                                 super.onComplete();\r
156                                                 hideMessage();\r
157                                         }\r
158                                 };\r
159                                 anim.run(500);\r
160                         }\r
161                 });\r
162                 buildPanel();\r
163                 setVisible(true);\r
164                 FadeIn anim = new FadeIn(simplePanel);\r
165                 anim.run(500);\r
166         }\r
167 \r
168         /**\r
169          * Display a warning message.\r
170          *\r
171          * @param msg the message to display\r
172          */\r
173         public void displayWarning(final String msg) {\r
174                 message = new HTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
175                 message.addClickHandler(new ClickHandler() {\r
176 \r
177                         @Override\r
178                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
179                                 FadeOut anim = new FadeOut(simplePanel){\r
180 \r
181                                         @Override\r
182                                         protected void onComplete() {\r
183                                                 super.onComplete();\r
184                                                 hideMessage();\r
185                                         }\r
186                                 };\r
187                                 anim.run(500);\r
188                         }\r
189                 });\r
190 \r
191                 buildPanel();\r
192                 setVisible(true);\r
193                 FadeIn anim = new FadeIn(simplePanel);\r
194                 anim.run(500);\r
195         }\r
196 \r
197         /**\r
198          * Display an informational message.\r
199          *\r
200          * @param msg the message to display\r
201          */\r
202         public void displayInformation(final String msg) {\r
203                 message = new HTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
204                 message.addClickHandler(new ClickHandler() {\r
205 \r
206                         @Override\r
207                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
208                                 FadeOut anim = new FadeOut(simplePanel){\r
209 \r
210                                         @Override\r
211                                         protected void onComplete() {\r
212                                                 super.onComplete();\r
213                                                 hideMessage();\r
214                                         }\r
215                                 };\r
216                                 anim.run(500);\r
217                         }\r
218                 });\r
219 \r
220                 buildPanel();\r
221                 setVisible(true);\r
222                 FadeIn anim = new FadeIn(simplePanel);\r
223                 anim.run(500);\r
224         }\r
225 \r
226         /**\r
227          * Clear the displayed message and hide the panel.\r
228          */\r
229         public void hideMessage() {\r
230                 inner.clear();\r
231                 message = new HTML("&nbsp;");\r
232                 this.setVisible(false);\r
233         }\r
234 \r
235 }\r