root / src / gr / grnet / pithos / web / client / MessagePanel.java @ 3f8622d4
History | View | Annotate | Download (6.8 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.ui.AbstractImagePrototype; |
46 |
import com.google.gwt.user.client.ui.Composite; |
47 |
import com.google.gwt.user.client.ui.HTML; |
48 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
49 |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
50 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
51 |
import com.google.gwt.user.client.ui.SimplePanel; |
52 |
import com.google.gwt.user.client.ui.VerticalPanel; |
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; |
81 |
|
82 |
/**
|
83 |
* The panel that contains the messages.
|
84 |
*/
|
85 |
private HorizontalPanel inner;
|
86 |
|
87 |
/**
|
88 |
* The panel that enables special effects for this widget.
|
89 |
*/
|
90 |
protected SimplePanel simplePanel;
|
91 |
|
92 |
/**
|
93 |
* A link to send feedBack about the error.
|
94 |
*/
|
95 |
private HTML feedbackLink; |
96 |
/**
|
97 |
* The widget's constructor.
|
98 |
*
|
99 |
* @param newImages a bundle that provides the images for this widget
|
100 |
*/
|
101 |
public MessagePanel(final Pithos app, final Images newImages) { |
102 |
images = newImages; |
103 |
simplePanel = new SimplePanel();
|
104 |
simplePanel.setStyleName("effectPanel");
|
105 |
|
106 |
inner = new HorizontalPanel();
|
107 |
inner.setStyleName("effectPanel-inner");
|
108 |
inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); |
109 |
inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); |
110 |
|
111 |
message = new HTML(" "); |
112 |
message.addClickHandler(new ClickHandler() {
|
113 |
|
114 |
@Override
|
115 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
116 |
FadeOut anim = new FadeOut(simplePanel){
|
117 |
|
118 |
@Override
|
119 |
protected void onComplete() { |
120 |
super.onComplete();
|
121 |
hideMessage(); |
122 |
} |
123 |
}; |
124 |
anim.run(500);
|
125 |
} |
126 |
}); |
127 |
inner.add(message); |
128 |
inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE); |
129 |
|
130 |
VerticalPanel linkPanel = new VerticalPanel();
|
131 |
linkPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); |
132 |
/**
|
133 |
* A link to clear the displayed message.
|
134 |
*/
|
135 |
HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>"); |
136 |
clearMessageLink.addClickHandler(new ClickHandler() {
|
137 |
|
138 |
@Override
|
139 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
140 |
FadeOut anim = new FadeOut(simplePanel){
|
141 |
@Override
|
142 |
protected void onComplete() { |
143 |
super.onComplete();
|
144 |
hideMessage(); |
145 |
} |
146 |
}; |
147 |
anim.run(500);
|
148 |
} |
149 |
}); |
150 |
linkPanel.add(clearMessageLink); |
151 |
|
152 |
feedbackLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Send feedback</a>"); |
153 |
feedbackLink.addClickHandler(new ClickHandler() {
|
154 |
|
155 |
@Override
|
156 |
public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
157 |
new FeedbackDialog(app, app.getErrorData()).center();
|
158 |
} |
159 |
}); |
160 |
feedbackLink.setVisible(false);
|
161 |
linkPanel.add(feedbackLink); |
162 |
|
163 |
inner.add(linkPanel); |
164 |
simplePanel.add(inner); |
165 |
|
166 |
initWidget(simplePanel); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* Display an error message.
|
171 |
*
|
172 |
* @param msg the message to display
|
173 |
*/
|
174 |
public void displayError(final String msg) { |
175 |
GWT.log(msg, null);
|
176 |
message.setHTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>"); |
177 |
feedbackLink.setVisible(true);
|
178 |
setVisible(true);
|
179 |
FadeIn anim = new FadeIn(simplePanel);
|
180 |
anim.run(500);
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Display a warning message.
|
185 |
*
|
186 |
* @param msg the message to display
|
187 |
*/
|
188 |
public void displayWarning(final String msg) { |
189 |
message.setHTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>"); |
190 |
feedbackLink.setVisible(false);
|
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.setHTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>"); |
203 |
feedbackLink.setVisible(false);
|
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 |
message = new HTML(" "); |
214 |
this.setVisible(false); |
215 |
} |
216 |
|
217 |
} |