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