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