Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / MessagePanel.java @ 58777026

History | View | Annotate | Download (6.9 kB)

1 ab1eb3f8 Christos Stathis
/*
2 58777026 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 58777026 Christos Stathis
 *
4 58777026 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 58777026 Christos Stathis
 * without modification, are permitted provided that the following
6 58777026 Christos Stathis
 * conditions are met:
7 58777026 Christos Stathis
 *
8 58777026 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 58777026 Christos Stathis
 *      disclaimer.
11 58777026 Christos Stathis
 *
12 58777026 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 58777026 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 58777026 Christos Stathis
 *      provided with the distribution.
16 58777026 Christos Stathis
 *
17 58777026 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 58777026 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 58777026 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 58777026 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 58777026 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 58777026 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 58777026 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 58777026 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 58777026 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 58777026 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 58777026 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 58777026 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 58777026 Christos Stathis
 *
30 58777026 Christos Stathis
 * The views and conclusions contained in the software and
31 58777026 Christos Stathis
 * documentation are those of the authors and should not be
32 58777026 Christos Stathis
 * interpreted as representing official policies, either expressed
33 58777026 Christos Stathis
 * or implied, of GRNET S.A.
34 ab1eb3f8 Christos Stathis
 */
35 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client;
36 ab1eb3f8 Christos Stathis
37 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.animation.FadeIn;
38 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.animation.FadeOut;
39 ab1eb3f8 Christos Stathis
40 ab1eb3f8 Christos Stathis
import com.google.gwt.core.client.GWT;
41 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
42 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
43 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
44 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
45 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.DOM;
46 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
47 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
48 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HTML;
49 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
50 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HasVerticalAlignment;
51 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
52 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.SimplePanel;
53 ab1eb3f8 Christos Stathis
54 ab1eb3f8 Christos Stathis
/**
55 ab1eb3f8 Christos Stathis
 * A panel that displays various system messages.
56 ab1eb3f8 Christos Stathis
 */
57 ab1eb3f8 Christos Stathis
public class MessagePanel extends Composite {
58 ab1eb3f8 Christos Stathis
        /**
59 ab1eb3f8 Christos Stathis
         * An image bundle for this widget's images.
60 ab1eb3f8 Christos Stathis
         */
61 ab1eb3f8 Christos Stathis
        public interface Images extends ClientBundle {
62 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/messagebox_info.png")
63 ab1eb3f8 Christos Stathis
                ImageResource info();
64 ab1eb3f8 Christos Stathis
65 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/messagebox_warning.png")
66 ab1eb3f8 Christos Stathis
                ImageResource warn();
67 ab1eb3f8 Christos Stathis
68 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/messagebox_critical.png")
69 ab1eb3f8 Christos Stathis
                ImageResource error();
70 ab1eb3f8 Christos Stathis
        }
71 ab1eb3f8 Christos Stathis
72 ab1eb3f8 Christos Stathis
        /**
73 ab1eb3f8 Christos Stathis
         * The widget's images.
74 ab1eb3f8 Christos Stathis
         */
75 ab1eb3f8 Christos Stathis
        public static Images images;
76 ab1eb3f8 Christos Stathis
77 ab1eb3f8 Christos Stathis
        /**
78 ab1eb3f8 Christos Stathis
         * The system message to be displayed.
79 ab1eb3f8 Christos Stathis
         */
80 ab1eb3f8 Christos Stathis
        private HTML message = new HTML(" ");
81 ab1eb3f8 Christos Stathis
82 ab1eb3f8 Christos Stathis
        /**
83 ab1eb3f8 Christos Stathis
         * A link to clear the displayed message.
84 ab1eb3f8 Christos Stathis
         */
85 ab1eb3f8 Christos Stathis
        private HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>");
86 ab1eb3f8 Christos Stathis
87 ab1eb3f8 Christos Stathis
        /**
88 ab1eb3f8 Christos Stathis
         * The panel that contains the messages.
89 ab1eb3f8 Christos Stathis
         */
90 ab1eb3f8 Christos Stathis
        private HorizontalPanel inner = new HorizontalPanel();
91 ab1eb3f8 Christos Stathis
92 ab1eb3f8 Christos Stathis
        /**
93 ab1eb3f8 Christos Stathis
         * The panel that enables special effects for this widget.
94 ab1eb3f8 Christos Stathis
         */
95 ab1eb3f8 Christos Stathis
        private SimplePanel simplePanel = new SimplePanel();
96 ab1eb3f8 Christos Stathis
97 ab1eb3f8 Christos Stathis
        /**
98 ab1eb3f8 Christos Stathis
         * The widget's constructor.
99 ab1eb3f8 Christos Stathis
         *
100 ab1eb3f8 Christos Stathis
         * @param newImages a bundle that provides the images for this widget
101 ab1eb3f8 Christos Stathis
         */
102 ab1eb3f8 Christos Stathis
        public MessagePanel(final Images newImages) {
103 ab1eb3f8 Christos Stathis
                images = newImages;
104 ab1eb3f8 Christos Stathis
                buildPanel();
105 ab1eb3f8 Christos Stathis
                simplePanel.setStyleName("effectPanel");
106 ab1eb3f8 Christos Stathis
                inner.setStyleName("effectPanel-inner");
107 ab1eb3f8 Christos Stathis
                DOM.setStyleAttribute(simplePanel.getElement(), "zoom", "1");
108 ab1eb3f8 Christos Stathis
                simplePanel.add(inner);
109 ab1eb3f8 Christos Stathis
                initWidget(simplePanel);
110 ab1eb3f8 Christos Stathis
        }
111 ab1eb3f8 Christos Stathis
112 ab1eb3f8 Christos Stathis
        /**
113 ab1eb3f8 Christos Stathis
         * Build the panel that contains the icon, the message and the 'clear' link.
114 ab1eb3f8 Christos Stathis
         */
115 ab1eb3f8 Christos Stathis
        private void buildPanel() {
116 ab1eb3f8 Christos Stathis
                inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
117 ab1eb3f8 Christos Stathis
                inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
118 ab1eb3f8 Christos Stathis
                inner.setSpacing(4);
119 ab1eb3f8 Christos Stathis
                inner.add(message);
120 ab1eb3f8 Christos Stathis
                inner.add(clearMessageLink);
121 ab1eb3f8 Christos Stathis
                inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);
122 ab1eb3f8 Christos Stathis
                clearMessageLink.addClickHandler(new ClickHandler() {
123 ab1eb3f8 Christos Stathis
124 ab1eb3f8 Christos Stathis
                        @Override
125 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
126 ab1eb3f8 Christos Stathis
                                FadeOut anim = new FadeOut(simplePanel){
127 ab1eb3f8 Christos Stathis
                                        @Override
128 ab1eb3f8 Christos Stathis
                                        protected void onComplete() {
129 ab1eb3f8 Christos Stathis
                                                super.onComplete();
130 ab1eb3f8 Christos Stathis
                                                hideMessage();
131 ab1eb3f8 Christos Stathis
                                        }
132 ab1eb3f8 Christos Stathis
                                };
133 ab1eb3f8 Christos Stathis
                                anim.run(500);
134 ab1eb3f8 Christos Stathis
                        }
135 ab1eb3f8 Christos Stathis
                });
136 ab1eb3f8 Christos Stathis
        }
137 ab1eb3f8 Christos Stathis
138 ab1eb3f8 Christos Stathis
        /**
139 ab1eb3f8 Christos Stathis
         * Display an error message.
140 ab1eb3f8 Christos Stathis
         *
141 ab1eb3f8 Christos Stathis
         * @param msg the message to display
142 ab1eb3f8 Christos Stathis
         */
143 ab1eb3f8 Christos Stathis
        public void displayError(final String msg) {
144 ab1eb3f8 Christos Stathis
                GWT.log(msg, null);
145 ab1eb3f8 Christos Stathis
                message = new HTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
146 ab1eb3f8 Christos Stathis
                message.addClickHandler(new ClickHandler() {
147 ab1eb3f8 Christos Stathis
148 ab1eb3f8 Christos Stathis
                        @Override
149 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
150 ab1eb3f8 Christos Stathis
                                FadeOut anim = new FadeOut(simplePanel){
151 ab1eb3f8 Christos Stathis
152 ab1eb3f8 Christos Stathis
                                        @Override
153 ab1eb3f8 Christos Stathis
                                        protected void onComplete() {
154 ab1eb3f8 Christos Stathis
                                                super.onComplete();
155 ab1eb3f8 Christos Stathis
                                                hideMessage();
156 ab1eb3f8 Christos Stathis
                                        }
157 ab1eb3f8 Christos Stathis
                                };
158 ab1eb3f8 Christos Stathis
                                anim.run(500);
159 ab1eb3f8 Christos Stathis
                        }
160 ab1eb3f8 Christos Stathis
                });
161 ab1eb3f8 Christos Stathis
                buildPanel();
162 ab1eb3f8 Christos Stathis
                setVisible(true);
163 ab1eb3f8 Christos Stathis
                FadeIn anim = new FadeIn(simplePanel);
164 ab1eb3f8 Christos Stathis
                anim.run(500);
165 ab1eb3f8 Christos Stathis
        }
166 ab1eb3f8 Christos Stathis
167 ab1eb3f8 Christos Stathis
        /**
168 ab1eb3f8 Christos Stathis
         * Display a warning message.
169 ab1eb3f8 Christos Stathis
         *
170 ab1eb3f8 Christos Stathis
         * @param msg the message to display
171 ab1eb3f8 Christos Stathis
         */
172 ab1eb3f8 Christos Stathis
        public void displayWarning(final String msg) {
173 ab1eb3f8 Christos Stathis
                message = new HTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
174 ab1eb3f8 Christos Stathis
                message.addClickHandler(new ClickHandler() {
175 ab1eb3f8 Christos Stathis
176 ab1eb3f8 Christos Stathis
                        @Override
177 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
178 ab1eb3f8 Christos Stathis
                                FadeOut anim = new FadeOut(simplePanel){
179 ab1eb3f8 Christos Stathis
180 ab1eb3f8 Christos Stathis
                                        @Override
181 ab1eb3f8 Christos Stathis
                                        protected void onComplete() {
182 ab1eb3f8 Christos Stathis
                                                super.onComplete();
183 ab1eb3f8 Christos Stathis
                                                hideMessage();
184 ab1eb3f8 Christos Stathis
                                        }
185 ab1eb3f8 Christos Stathis
                                };
186 ab1eb3f8 Christos Stathis
                                anim.run(500);
187 ab1eb3f8 Christos Stathis
                        }
188 ab1eb3f8 Christos Stathis
                });
189 ab1eb3f8 Christos Stathis
190 ab1eb3f8 Christos Stathis
                buildPanel();
191 ab1eb3f8 Christos Stathis
                setVisible(true);
192 ab1eb3f8 Christos Stathis
                FadeIn anim = new FadeIn(simplePanel);
193 ab1eb3f8 Christos Stathis
                anim.run(500);
194 ab1eb3f8 Christos Stathis
        }
195 ab1eb3f8 Christos Stathis
196 ab1eb3f8 Christos Stathis
        /**
197 ab1eb3f8 Christos Stathis
         * Display an informational message.
198 ab1eb3f8 Christos Stathis
         *
199 ab1eb3f8 Christos Stathis
         * @param msg the message to display
200 ab1eb3f8 Christos Stathis
         */
201 ab1eb3f8 Christos Stathis
        public void displayInformation(final String msg) {
202 ab1eb3f8 Christos Stathis
                message = new HTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
203 ab1eb3f8 Christos Stathis
                message.addClickHandler(new ClickHandler() {
204 ab1eb3f8 Christos Stathis
205 ab1eb3f8 Christos Stathis
                        @Override
206 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
207 ab1eb3f8 Christos Stathis
                                FadeOut anim = new FadeOut(simplePanel){
208 ab1eb3f8 Christos Stathis
209 ab1eb3f8 Christos Stathis
                                        @Override
210 ab1eb3f8 Christos Stathis
                                        protected void onComplete() {
211 ab1eb3f8 Christos Stathis
                                                super.onComplete();
212 ab1eb3f8 Christos Stathis
                                                hideMessage();
213 ab1eb3f8 Christos Stathis
                                        }
214 ab1eb3f8 Christos Stathis
                                };
215 ab1eb3f8 Christos Stathis
                                anim.run(500);
216 ab1eb3f8 Christos Stathis
                        }
217 ab1eb3f8 Christos Stathis
                });
218 ab1eb3f8 Christos Stathis
219 ab1eb3f8 Christos Stathis
                buildPanel();
220 ab1eb3f8 Christos Stathis
                setVisible(true);
221 ab1eb3f8 Christos Stathis
                FadeIn anim = new FadeIn(simplePanel);
222 ab1eb3f8 Christos Stathis
                anim.run(500);
223 ab1eb3f8 Christos Stathis
        }
224 ab1eb3f8 Christos Stathis
225 ab1eb3f8 Christos Stathis
        /**
226 ab1eb3f8 Christos Stathis
         * Clear the displayed message and hide the panel.
227 ab1eb3f8 Christos Stathis
         */
228 ab1eb3f8 Christos Stathis
        public void hideMessage() {
229 ab1eb3f8 Christos Stathis
                inner.clear();
230 ab1eb3f8 Christos Stathis
                message = new HTML("&nbsp;");
231 ab1eb3f8 Christos Stathis
                this.setVisible(false);
232 ab1eb3f8 Christos Stathis
        }
233 ab1eb3f8 Christos Stathis
234 ab1eb3f8 Christos Stathis
}