Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / MessagePanel.java @ 49a8183f

History | View | Annotate | Download (6.2 kB)

1
/*
2
 * Copyright 2011-2013 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 com.google.gwt.core.client.GWT;
38
import com.google.gwt.event.dom.client.ClickEvent;
39
import com.google.gwt.event.dom.client.ClickHandler;
40
import com.google.gwt.resources.client.ClientBundle;
41
import com.google.gwt.resources.client.ImageResource;
42
import com.google.gwt.user.client.Window;
43
import com.google.gwt.user.client.ui.AbstractImagePrototype;
44
import com.google.gwt.user.client.ui.Composite;
45
import com.google.gwt.user.client.ui.HTML;
46
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
47
import com.google.gwt.user.client.ui.HasVerticalAlignment;
48
import com.google.gwt.user.client.ui.HorizontalPanel;
49
import com.google.gwt.user.client.ui.SimplePanel;
50
import com.google.gwt.user.client.ui.VerticalPanel;
51

    
52
/**
53
 * A panel that displays various system messages.
54
 */
55
public class MessagePanel extends Composite {
56
        /**
57
         * An image bundle for this widget's images.
58
         */
59
        public interface Images extends ClientBundle {
60
                @Source("gr/grnet/pithos/resources/messagebox_info.png")
61
                ImageResource info();
62

    
63
                @Source("gr/grnet/pithos/resources/messagebox_warning.png")
64
                ImageResource warn();
65

    
66
                @Source("gr/grnet/pithos/resources/messagebox_critical.png")
67
                ImageResource error();
68
        }
69

    
70
        /**
71
         * The widget's images.
72
         */
73
        public static Images images;
74

    
75
        /**
76
         * The system message to be displayed.
77
         */
78
        private HTML message;
79

    
80
        /**
81
         * The panel that contains the messages.
82
         */
83
        private HorizontalPanel inner;
84

    
85
        /**
86
         * The panel that enables special effects for this widget.
87
         */
88
        protected SimplePanel simplePanel;
89

    
90
        /**
91
         * A link to send feedBack about the error.
92
         */
93
        private HTML feedbackLink;
94
        
95
        Pithos app;
96
        
97
        /**
98
         * The widget's constructor.
99
         *
100
         * @param newImages a bundle that provides the images for this widget
101
         */
102
        public MessagePanel(Pithos _app, final Images newImages) {
103
                app = _app;
104
                images = newImages;
105
                simplePanel = new SimplePanel();
106
                simplePanel.setStyleName("effectPanel");
107
                
108
                inner = new HorizontalPanel();
109
                inner.setStyleName("effectPanel-inner");
110
                inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
111
                inner.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
112
                
113
                message = new HTML(" ");
114
                message.addClickHandler(new ClickHandler() {
115

    
116
                        @Override
117
                        public void onClick(ClickEvent event) {
118
                                hideMessage();
119
                        }
120
                });
121
                inner.add(message);
122
                inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);
123

    
124
                VerticalPanel linkPanel = new VerticalPanel();
125
                linkPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
126
                /**
127
                 * A link to clear the displayed message.
128
                 */
129
                HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>");
130
                clearMessageLink.addClickHandler(new ClickHandler() {
131

    
132
                        @Override
133
                        public void onClick(ClickEvent event) {
134
                                hideMessage();
135
                        }
136
                });
137
                linkPanel.add(clearMessageLink);
138

    
139
                feedbackLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Send feedback</a>");
140
                feedbackLink.addClickHandler(new ClickHandler() {
141
                        
142
                        @Override
143
                        public void onClick(ClickEvent event) {
144
                                new FeedbackDialog(app, app.getErrorData()).center();
145
                        }
146
                });
147
                feedbackLink.setVisible(false);
148
                linkPanel.add(feedbackLink);
149

    
150
                inner.add(linkPanel);
151
                simplePanel.add(inner);
152
                
153
                initWidget(simplePanel);
154
        }
155

    
156
        /**
157
         * Display an error message.
158
         *
159
         * @param msg the message to display
160
         */
161
        public void displayError(final String msg) {
162
                GWT.log(msg, null);
163
                message.setHTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
164
                feedbackLink.setVisible(true);
165
                setVisible(true);
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.setHTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
175
                feedbackLink.setVisible(false);
176
                setVisible(true);
177
        }
178

    
179
        /**
180
         * Display an informational message.
181
         *
182
         * @param msg the message to display
183
         */
184
        public void displayInformation(final String msg) {
185
                message.setHTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
186
                feedbackLink.setVisible(false);
187
                setVisible(true);
188
        }
189

    
190
        /**
191
         * Clear the displayed message and hide the panel.
192
         */
193
        public void hideMessage() {
194
                message = new HTML("&nbsp;");
195
                this.setVisible(false);
196
                app.onWindowResized(Window.getClientHeight());
197
        }
198
}