root / web_client / src / gr / grnet / pithos / web / client / MessagePanel.java @ ab1eb3f8
History | View | Annotate | Download (6 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package gr.grnet.pithos.web.client; |
20 |
|
21 |
import gr.grnet.pithos.web.client.animation.FadeIn; |
22 |
import gr.grnet.pithos.web.client.animation.FadeOut; |
23 |
|
24 |
import com.google.gwt.core.client.GWT; |
25 |
import com.google.gwt.event.dom.client.ClickEvent; |
26 |
import com.google.gwt.event.dom.client.ClickHandler; |
27 |
import com.google.gwt.resources.client.ClientBundle; |
28 |
import com.google.gwt.resources.client.ImageResource; |
29 |
import com.google.gwt.user.client.DOM; |
30 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
31 |
import com.google.gwt.user.client.ui.Composite; |
32 |
import com.google.gwt.user.client.ui.HTML; |
33 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
34 |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
35 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
36 |
import com.google.gwt.user.client.ui.SimplePanel; |
37 |
|
38 |
/**
|
39 |
* A panel that displays various system messages.
|
40 |
*/
|
41 |
public class MessagePanel extends Composite { |
42 |
/**
|
43 |
* An image bundle for this widget's images.
|
44 |
*/
|
45 |
public interface Images extends ClientBundle { |
46 |
@Source("gr/grnet/pithos/resources/messagebox_info.png") |
47 |
ImageResource info(); |
48 |
|
49 |
@Source("gr/grnet/pithos/resources/messagebox_warning.png") |
50 |
ImageResource warn(); |
51 |
|
52 |
@Source("gr/grnet/pithos/resources/messagebox_critical.png") |
53 |
ImageResource error(); |
54 |
} |
55 |
|
56 |
/**
|
57 |
* The widget's images.
|
58 |
*/
|
59 |
public static Images images; |
60 |
|
61 |
/**
|
62 |
* The system message to be displayed.
|
63 |
*/
|
64 |
private HTML message = new HTML(" "); |
65 |
|
66 |
/**
|
67 |
* A link to clear the displayed message.
|
68 |
*/
|
69 |
private HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>"); |
70 |
|
71 |
/**
|
72 |
* The panel that contains the messages.
|
73 |
*/
|
74 |
private HorizontalPanel inner = new HorizontalPanel(); |
75 |
|
76 |
/**
|
77 |
* The panel that enables special effects for this widget.
|
78 |
*/
|
79 |
private SimplePanel simplePanel = new SimplePanel(); |
80 |
|
81 |
/**
|
82 |
* The widget's constructor.
|
83 |
*
|
84 |
* @param newImages a bundle that provides the images for this widget
|
85 |
*/
|
86 |
public MessagePanel(final Images newImages) { |
87 |
images = newImages; |
88 |
buildPanel(); |
89 |
simplePanel.setStyleName("effectPanel");
|
90 |
inner.setStyleName("effectPanel-inner");
|
91 |
DOM.setStyleAttribute(simplePanel.getElement(), "zoom", "1"); |
92 |
simplePanel.add(inner); |
93 |
initWidget(simplePanel); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Build the panel that contains the icon, the message and the 'clear' link.
|
98 |
*/
|
99 |
private void buildPanel() { |
100 |
inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); |
101 |
inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); |
102 |
inner.setSpacing(4);
|
103 |
inner.add(message); |
104 |
inner.add(clearMessageLink); |
105 |
inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE); |
106 |
clearMessageLink.addClickHandler(new ClickHandler() {
|
107 |
|
108 |
@Override
|
109 |
public void onClick(ClickEvent event) { |
110 |
FadeOut anim = new FadeOut(simplePanel){
|
111 |
@Override
|
112 |
protected void onComplete() { |
113 |
super.onComplete();
|
114 |
hideMessage(); |
115 |
} |
116 |
}; |
117 |
anim.run(500);
|
118 |
} |
119 |
}); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Display an error message.
|
124 |
*
|
125 |
* @param msg the message to display
|
126 |
*/
|
127 |
public void displayError(final String msg) { |
128 |
GWT.log(msg, null);
|
129 |
message = new HTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>"); |
130 |
message.addClickHandler(new ClickHandler() {
|
131 |
|
132 |
@Override
|
133 |
public void onClick(ClickEvent event) { |
134 |
FadeOut anim = new FadeOut(simplePanel){
|
135 |
|
136 |
@Override
|
137 |
protected void onComplete() { |
138 |
super.onComplete();
|
139 |
hideMessage(); |
140 |
} |
141 |
}; |
142 |
anim.run(500);
|
143 |
} |
144 |
}); |
145 |
buildPanel(); |
146 |
setVisible(true);
|
147 |
FadeIn anim = new FadeIn(simplePanel);
|
148 |
anim.run(500);
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* Display a warning message.
|
153 |
*
|
154 |
* @param msg the message to display
|
155 |
*/
|
156 |
public void displayWarning(final String msg) { |
157 |
message = new HTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>"); |
158 |
message.addClickHandler(new ClickHandler() {
|
159 |
|
160 |
@Override
|
161 |
public void onClick(ClickEvent event) { |
162 |
FadeOut anim = new FadeOut(simplePanel){
|
163 |
|
164 |
@Override
|
165 |
protected void onComplete() { |
166 |
super.onComplete();
|
167 |
hideMessage(); |
168 |
} |
169 |
}; |
170 |
anim.run(500);
|
171 |
} |
172 |
}); |
173 |
|
174 |
buildPanel(); |
175 |
setVisible(true);
|
176 |
FadeIn anim = new FadeIn(simplePanel);
|
177 |
anim.run(500);
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Display an informational message.
|
182 |
*
|
183 |
* @param msg the message to display
|
184 |
*/
|
185 |
public void displayInformation(final String msg) { |
186 |
message = new HTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>"); |
187 |
message.addClickHandler(new ClickHandler() {
|
188 |
|
189 |
@Override
|
190 |
public void onClick(ClickEvent event) { |
191 |
FadeOut anim = new FadeOut(simplePanel){
|
192 |
|
193 |
@Override
|
194 |
protected void onComplete() { |
195 |
super.onComplete();
|
196 |
hideMessage(); |
197 |
} |
198 |
}; |
199 |
anim.run(500);
|
200 |
} |
201 |
}); |
202 |
|
203 |
buildPanel(); |
204 |
setVisible(true);
|
205 |
FadeIn anim = new FadeIn(simplePanel);
|
206 |
anim.run(500);
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Clear the displayed message and hide the panel.
|
211 |
*/
|
212 |
public void hideMessage() { |
213 |
inner.clear(); |
214 |
message = new HTML(" "); |
215 |
this.setVisible(false); |
216 |
} |
217 |
|
218 |
} |