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