moved towards gwt version 2.0 - updated dnd to version 3 -removed all deprecations
[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.event.dom.client.ClickEvent;\r
26 import com.google.gwt.event.dom.client.ClickHandler;\r
27 import com.google.gwt.resources.client.ClientBundle;\r
28 import com.google.gwt.resources.client.ImageResource;\r
29 import com.google.gwt.user.client.DOM;\r
30 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
31 import com.google.gwt.user.client.ui.Composite;\r
32 import com.google.gwt.user.client.ui.HTML;\r
33 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
34 import com.google.gwt.user.client.ui.HasVerticalAlignment;\r
35 import com.google.gwt.user.client.ui.HorizontalPanel;\r
36 import com.google.gwt.user.client.ui.SimplePanel;\r
37 \r
38 /**\r
39  * A panel that displays various system messages.\r
40  */\r
41 public class MessagePanel extends Composite {\r
42         /**\r
43          * An image bundle for this widget's images.\r
44          */\r
45         public interface Images extends ClientBundle {\r
46                 @Source("gr/ebs/gss/resources/messagebox_info.png")\r
47                 ImageResource info();\r
48 \r
49                 @Source("gr/ebs/gss/resources/messagebox_warning.png")\r
50                 ImageResource warn();\r
51 \r
52                 @Source("gr/ebs/gss/resources/messagebox_critical.png")\r
53                 ImageResource error();\r
54         }\r
55 \r
56         /**\r
57          * The widget's images.\r
58          */\r
59         public static Images images;\r
60 \r
61         /**\r
62          * The system message to be displayed.\r
63          */\r
64         private HTML message = new HTML("&nbsp;");\r
65 \r
66         /**\r
67          * A link to clear the displayed message.\r
68          */\r
69         private HTML clearMessageLink = new HTML("<a class='gss-clearMessage' href='javascript:;'>Clear</a>");\r
70 \r
71         /**\r
72          * The panel that contains the messages.\r
73          */\r
74         private HorizontalPanel inner = new HorizontalPanel();\r
75 \r
76         /**\r
77          * The panel that enables special effects for this widget.\r
78          */\r
79         private SimplePanel simplePanel = new SimplePanel();\r
80 \r
81         /**\r
82          * The widget's constructor.\r
83          *\r
84          * @param newImages a bundle that provides the images for this widget\r
85          */\r
86         public MessagePanel(final Images newImages) {\r
87                 images = newImages;\r
88                 buildPanel();\r
89                 simplePanel.setStyleName("effectPanel");\r
90                 inner.setStyleName("effectPanel-inner");\r
91                 DOM.setStyleAttribute(simplePanel.getElement(), "zoom", "1");\r
92                 simplePanel.add(inner);\r
93                 initWidget(simplePanel);\r
94         }\r
95 \r
96         /**\r
97          * Build the panel that contains the icon, the message and the 'clear' link.\r
98          */\r
99         private void buildPanel() {\r
100                 inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);\r
101                 inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);\r
102                 inner.setSpacing(4);\r
103                 inner.add(message);\r
104                 inner.add(clearMessageLink);\r
105                 inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);\r
106 \r
107                 clearMessageLink.addClickHandler(new ClickHandler() {\r
108 \r
109                         @Override\r
110                         public void onClick(ClickEvent event) {\r
111                                 FadeOut anim = new FadeOut(simplePanel){\r
112                                         @Override\r
113                                         protected void onComplete() {\r
114                                                 super.onComplete();\r
115                                                 hideMessage();\r
116                                         }\r
117                                 };\r
118                                 anim.run(1000);\r
119 \r
120                         }\r
121                 });\r
122         }\r
123 \r
124         /**\r
125          * Display an error message.\r
126          *\r
127          * @param msg the message to display\r
128          */\r
129         public void displayError(final String msg) {\r
130                 GWT.log(msg, null);\r
131                 message = new HTML("<table class='gss-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
132                 message.addClickHandler(new ClickHandler() {\r
133 \r
134                         @Override\r
135                         public void onClick(ClickEvent event) {\r
136                                 FadeOut anim = new FadeOut(simplePanel){\r
137 \r
138                                         @Override\r
139                                         protected void onComplete() {\r
140                                                 super.onComplete();\r
141                                                 hideMessage();\r
142                                         }\r
143                                 };\r
144                                 anim.run(1000);\r
145                         }\r
146                 });\r
147                 buildPanel();\r
148                 setVisible(true);\r
149                 FadeIn anim = new FadeIn(simplePanel);\r
150                 anim.run(1000);\r
151         }\r
152 \r
153         /**\r
154          * Display a warning message.\r
155          *\r
156          * @param msg the message to display\r
157          */\r
158         public void displayWarning(final String msg) {\r
159                 message = new HTML("<table class='gss-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
160                 message.addClickHandler(new ClickHandler() {\r
161 \r
162                         @Override\r
163                         public void onClick(ClickEvent event) {\r
164                                 FadeOut anim = new FadeOut(simplePanel){\r
165 \r
166                                         @Override\r
167                                         protected void onComplete() {\r
168                                                 super.onComplete();\r
169                                                 hideMessage();\r
170                                         }\r
171                                 };\r
172                                 anim.run(1000);\r
173                         }\r
174                 });\r
175 \r
176                 buildPanel();\r
177                 setVisible(true);\r
178                 FadeIn anim = new FadeIn(simplePanel);\r
179                 anim.run(1000);\r
180         }\r
181 \r
182         /**\r
183          * Display an informational message.\r
184          *\r
185          * @param msg the message to display\r
186          */\r
187         public void displayInformation(final String msg) {\r
188                 message = new HTML("<table class='gss-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");\r
189                 message.addClickHandler(new ClickHandler() {\r
190 \r
191                         @Override\r
192                         public void onClick(ClickEvent event) {\r
193                                 FadeOut anim = new FadeOut(simplePanel){\r
194 \r
195                                         @Override\r
196                                         protected void onComplete() {\r
197                                                 super.onComplete();\r
198                                                 hideMessage();\r
199                                         }\r
200                                 };\r
201                                 anim.run(1000);\r
202                         }\r
203                 });\r
204 \r
205                 buildPanel();\r
206                 setVisible(true);\r
207                 FadeIn anim = new FadeIn(simplePanel);\r
208                 anim.run(1000);\r
209         }\r
210 \r
211         /**\r
212          * Clear the displayed message and hide the panel.\r
213          */\r
214         public void hideMessage() {\r
215                 inner.clear();\r
216                 message = new HTML("&nbsp;");\r
217                 this.setVisible(false);\r
218         }\r
219 \r
220 }\r