Removed animation that is broken by latest chrome (v.24)
[pithos-web-client] / src / gr / grnet / pithos / web / client / MessagePanel.java
1 /*\r
2  * Copyright 2011-2012 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 com.google.gwt.core.client.GWT;\r
38 import com.google.gwt.event.dom.client.ClickEvent;\r
39 import com.google.gwt.event.dom.client.ClickHandler;\r
40 import com.google.gwt.resources.client.ClientBundle;\r
41 import com.google.gwt.resources.client.ImageResource;\r
42 import com.google.gwt.user.client.Window;\r
43 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
44 import com.google.gwt.user.client.ui.Composite;\r
45 import com.google.gwt.user.client.ui.HTML;\r
46 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
47 import com.google.gwt.user.client.ui.HasVerticalAlignment;\r
48 import com.google.gwt.user.client.ui.HorizontalPanel;\r
49 import com.google.gwt.user.client.ui.SimplePanel;\r
50 import com.google.gwt.user.client.ui.VerticalPanel;\r
51 \r
52 /**\r
53  * A panel that displays various system messages.\r
54  */\r
55 public class MessagePanel extends Composite {\r
56         /**\r
57          * An image bundle for this widget's images.\r
58          */\r
59         public interface Images extends ClientBundle {\r
60                 @Source("gr/grnet/pithos/resources/messagebox_info.png")\r
61                 ImageResource info();\r
62 \r
63                 @Source("gr/grnet/pithos/resources/messagebox_warning.png")\r
64                 ImageResource warn();\r
65 \r
66                 @Source("gr/grnet/pithos/resources/messagebox_critical.png")\r
67                 ImageResource error();\r
68         }\r
69 \r
70         /**\r
71          * The widget's images.\r
72          */\r
73         public static Images images;\r
74 \r
75         /**\r
76          * The system message to be displayed.\r
77          */\r
78         private HTML message;\r
79 \r
80         /**\r
81          * The panel that contains the messages.\r
82          */\r
83         private HorizontalPanel inner;\r
84 \r
85         /**\r
86          * The panel that enables special effects for this widget.\r
87          */\r
88         protected SimplePanel simplePanel;\r
89 \r
90         /**\r
91          * A link to send feedBack about the error.\r
92          */\r
93         private HTML feedbackLink;\r
94         \r
95         Pithos app;\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(Pithos _app, final Images newImages) {\r
103                 app = _app;\r
104                 images = newImages;\r
105                 simplePanel = new SimplePanel();\r
106                 simplePanel.setStyleName("effectPanel");\r
107                 \r
108                 inner = new HorizontalPanel();\r
109                 inner.setStyleName("effectPanel-inner");\r
110                 inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);\r
111                 inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);\r
112                 \r
113                 message = new HTML(" ");\r
114                 message.addClickHandler(new ClickHandler() {\r
115 \r
116                         @Override\r
117                         public void onClick(ClickEvent event) {\r
118                                 hideMessage();\r
119                         }\r
120                 });\r
121                 inner.add(message);\r
122                 inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);\r
123 \r
124                 VerticalPanel linkPanel = new VerticalPanel();\r
125                 linkPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);\r
126                 /**\r
127                  * A link to clear the displayed message.\r
128                  */\r
129                 HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>");\r
130                 clearMessageLink.addClickHandler(new ClickHandler() {\r
131 \r
132                         @Override\r
133                         public void onClick(ClickEvent event) {\r
134                                 hideMessage();\r
135                         }\r
136                 });\r
137                 linkPanel.add(clearMessageLink);\r
138 \r
139                 feedbackLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Send feedback</a>");\r
140                 feedbackLink.addClickHandler(new ClickHandler() {\r
141                         \r
142                         @Override\r
143                         public void onClick(ClickEvent event) {\r
144                                 new FeedbackDialog(app, app.getErrorData()).center();\r
145                         }\r
146                 });\r
147                 feedbackLink.setVisible(false);\r
148                 linkPanel.add(feedbackLink);\r
149 \r
150                 inner.add(linkPanel);\r
151                 simplePanel.add(inner);\r
152                 \r
153                 initWidget(simplePanel);\r
154         }\r
155 \r
156         /**\r
157          * Display an error message.\r
158          *\r
159          * @param msg the message to display\r
160          */\r
161         public void displayError(final String msg) {\r
162                 GWT.log(msg, null);\r
163                 message.setHTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
164                 feedbackLink.setVisible(true);\r
165                 setVisible(true);\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.setHTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
175                 feedbackLink.setVisible(false);\r
176                 setVisible(true);\r
177         }\r
178 \r
179         /**\r
180          * Display an informational message.\r
181          *\r
182          * @param msg the message to display\r
183          */\r
184         public void displayInformation(final String msg) {\r
185                 message.setHTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
186                 feedbackLink.setVisible(false);\r
187                 setVisible(true);\r
188         }\r
189 \r
190         /**\r
191          * Clear the displayed message and hide the panel.\r
192          */\r
193         public void hideMessage() {\r
194                 message = new HTML("&nbsp;");\r
195                 this.setVisible(false);\r
196                 app.onWindowResized(Window.getClientHeight());\r
197         }\r
198 }\r