Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / MessagePanel.java @ 0f797b1b

History | View | Annotate | Download (7 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.DOM;
46
import com.google.gwt.user.client.ui.AbstractImagePrototype;
47
import com.google.gwt.user.client.ui.Composite;
48
import com.google.gwt.user.client.ui.HTML;
49
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
50
import com.google.gwt.user.client.ui.HasVerticalAlignment;
51
import com.google.gwt.user.client.ui.HorizontalPanel;
52
import com.google.gwt.user.client.ui.SimplePanel;
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 = new HTML(" ");
81

    
82
        /**
83
         * A link to clear the displayed message.
84
         */
85
        private HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>");
86

    
87
        /**
88
         * The panel that contains the messages.
89
         */
90
        private HorizontalPanel inner = new HorizontalPanel();
91

    
92
        /**
93
         * The panel that enables special effects for this widget.
94
         */
95
        protected SimplePanel simplePanel = new SimplePanel();
96

    
97
        /**
98
         * The widget's constructor.
99
         *
100
         * @param newImages a bundle that provides the images for this widget
101
         */
102
        public MessagePanel(final Images newImages) {
103
                images = newImages;
104
                buildPanel();
105
                simplePanel.setStyleName("effectPanel");
106
                inner.setStyleName("effectPanel-inner");
107
                DOM.setStyleAttribute(simplePanel.getElement(), "zoom", "1");
108
                simplePanel.add(inner);
109
                initWidget(simplePanel);
110
        }
111

    
112
        /**
113
         * Build the panel that contains the icon, the message and the 'clear' link.
114
         */
115
        private void buildPanel() {
116
                inner.clear();
117
                inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
118
                inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
119
//                inner.setSpacing(4);
120
                inner.add(message);
121
                inner.add(clearMessageLink);
122
                inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);
123
                clearMessageLink.addClickHandler(new ClickHandler() {
124

    
125
                        @Override
126
                        public void onClick(@SuppressWarnings("unused") ClickEvent event) {
127
                                FadeOut anim = new FadeOut(simplePanel){
128
                                        @Override
129
                                        protected void onComplete() {
130
                                                super.onComplete();
131
                                                hideMessage();
132
                                        }
133
                                };
134
                                anim.run(500);
135
                        }
136
                });
137
        }
138

    
139
        /**
140
         * Display an error message.
141
         *
142
         * @param msg the message to display
143
         */
144
        public void displayError(final String msg) {
145
                GWT.log(msg, null);
146
                message = new HTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
147
                message.addClickHandler(new ClickHandler() {
148

    
149
                        @Override
150
                        public void onClick(@SuppressWarnings("unused") ClickEvent event) {
151
                                FadeOut anim = new FadeOut(simplePanel){
152

    
153
                                        @Override
154
                                        protected void onComplete() {
155
                                                super.onComplete();
156
                                                hideMessage();
157
                                        }
158
                                };
159
                                anim.run(500);
160
                        }
161
                });
162
                buildPanel();
163
                setVisible(true);
164
                FadeIn anim = new FadeIn(simplePanel);
165
                anim.run(500);
166
        }
167

    
168
        /**
169
         * Display a warning message.
170
         *
171
         * @param msg the message to display
172
         */
173
        public void displayWarning(final String msg) {
174
                message = new HTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
175
                message.addClickHandler(new ClickHandler() {
176

    
177
                        @Override
178
                        public void onClick(@SuppressWarnings("unused") ClickEvent event) {
179
                                FadeOut anim = new FadeOut(simplePanel){
180

    
181
                                        @Override
182
                                        protected void onComplete() {
183
                                                super.onComplete();
184
                                                hideMessage();
185
                                        }
186
                                };
187
                                anim.run(500);
188
                        }
189
                });
190

    
191
                buildPanel();
192
                setVisible(true);
193
                FadeIn anim = new FadeIn(simplePanel);
194
                anim.run(500);
195
        }
196

    
197
        /**
198
         * Display an informational message.
199
         *
200
         * @param msg the message to display
201
         */
202
        public void displayInformation(final String msg) {
203
                message = new HTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
204
                message.addClickHandler(new ClickHandler() {
205

    
206
                        @Override
207
                        public void onClick(@SuppressWarnings("unused") ClickEvent event) {
208
                                FadeOut anim = new FadeOut(simplePanel){
209

    
210
                                        @Override
211
                                        protected void onComplete() {
212
                                                super.onComplete();
213
                                                hideMessage();
214
                                        }
215
                                };
216
                                anim.run(500);
217
                        }
218
                });
219

    
220
                buildPanel();
221
                setVisible(true);
222
                FadeIn anim = new FadeIn(simplePanel);
223
                anim.run(500);
224
        }
225

    
226
        /**
227
         * Clear the displayed message and hide the panel.
228
         */
229
        public void hideMessage() {
230
                inner.clear();
231
                message = new HTML("&nbsp;");
232
                this.setVisible(false);
233
        }
234

    
235
}