Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / MessagePanel.java @ a60ea262

History | View | Annotate | Download (6 kB)

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