Revision 3f8622d4 src/gr/grnet/pithos/web/client/MessagePanel.java

b/src/gr/grnet/pithos/web/client/MessagePanel.java
42 42
import com.google.gwt.event.dom.client.ClickHandler;
43 43
import com.google.gwt.resources.client.ClientBundle;
44 44
import com.google.gwt.resources.client.ImageResource;
45
import com.google.gwt.user.client.DOM;
46 45
import com.google.gwt.user.client.ui.AbstractImagePrototype;
47 46
import com.google.gwt.user.client.ui.Composite;
48 47
import com.google.gwt.user.client.ui.HTML;
......
50 49
import com.google.gwt.user.client.ui.HasVerticalAlignment;
51 50
import com.google.gwt.user.client.ui.HorizontalPanel;
52 51
import com.google.gwt.user.client.ui.SimplePanel;
52
import com.google.gwt.user.client.ui.VerticalPanel;
53 53

  
54 54
/**
55 55
 * A panel that displays various system messages.
......
77 77
	/**
78 78
	 * The system message to be displayed.
79 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>");
80
	private HTML message;
86 81

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

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

  
97 92
	/**
93
	 * A link to send feedBack about the error.
94
	 */
95
	private HTML feedbackLink;
96
	/**
98 97
	 * The widget's constructor.
99 98
	 *
100 99
	 * @param newImages a bundle that provides the images for this widget
101 100
	 */
102
	public MessagePanel(final Images newImages) {
101
	public MessagePanel(final Pithos app, final Images newImages) {
103 102
		images = newImages;
104
		buildPanel();
103
		simplePanel = new SimplePanel();
105 104
		simplePanel.setStyleName("effectPanel");
105
		
106
		inner = new HorizontalPanel();
106 107
		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 108
		inner.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
118 109
		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() {
110
		
111
		message = new HTML("&nbsp;");
112
		message.addClickHandler(new ClickHandler() {
124 113

  
125 114
			@Override
126 115
			public void onClick(@SuppressWarnings("unused") ClickEvent event) {
127 116
				FadeOut anim = new FadeOut(simplePanel){
117

  
128 118
					@Override
129 119
					protected void onComplete() {
130 120
						super.onComplete();
......
134 124
				anim.run(500);
135 125
			}
136 126
		});
137
	}
127
		inner.add(message);
128
		inner.setCellVerticalAlignment(message, HasVerticalAlignment.ALIGN_MIDDLE);
138 129

  
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() {
130
		VerticalPanel linkPanel = new VerticalPanel();
131
		linkPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
132
		/**
133
		 * A link to clear the displayed message.
134
		 */
135
		HTML clearMessageLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Clear</a>");
136
		clearMessageLink.addClickHandler(new ClickHandler() {
148 137

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

  
153 141
					@Override
154 142
					protected void onComplete() {
155 143
						super.onComplete();
......
159 147
				anim.run(500);
160 148
			}
161 149
		});
162
		buildPanel();
150
		linkPanel.add(clearMessageLink);
151

  
152
		feedbackLink = new HTML("<a class='pithos-clearMessage' href='javascript:;'>Send feedback</a>");
153
		feedbackLink.addClickHandler(new ClickHandler() {
154
			
155
			@Override
156
			public void onClick(@SuppressWarnings("unused") ClickEvent event) {
157
				new FeedbackDialog(app, app.getErrorData()).center();
158
			}
159
		});
160
		feedbackLink.setVisible(false);
161
		linkPanel.add(feedbackLink);
162

  
163
		inner.add(linkPanel);
164
		simplePanel.add(inner);
165
		
166
		initWidget(simplePanel);
167
	}
168

  
169
	/**
170
	 * Display an error message.
171
	 *
172
	 * @param msg the message to display
173
	 */
174
	public void displayError(final String msg) {
175
		GWT.log(msg, null);
176
		message.setHTML("<table class='pithos-errorMessage'><tr><td>" + AbstractImagePrototype.create(images.error()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
177
		feedbackLink.setVisible(true);
163 178
		setVisible(true);
164 179
		FadeIn anim = new FadeIn(simplePanel);
165 180
		anim.run(500);
......
171 186
	 * @param msg the message to display
172 187
	 */
173 188
	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();
189
		message.setHTML("<table class='pithos-warnMessage'><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
190
		feedbackLink.setVisible(false);
192 191
		setVisible(true);
193 192
		FadeIn anim = new FadeIn(simplePanel);
194 193
		anim.run(500);
......
200 199
	 * @param msg the message to display
201 200
	 */
202 201
	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();
202
		message.setHTML("<table class='pithos-infoMessage'><tr><td>" + AbstractImagePrototype.create(images.info()).getHTML() + "</td><td>" + msg + "</td></tr></table>");
203
		feedbackLink.setVisible(false);
221 204
		setVisible(true);
222 205
		FadeIn anim = new FadeIn(simplePanel);
223 206
		anim.run(500);
......
227 210
	 * Clear the displayed message and hide the panel.
228 211
	 */
229 212
	public void hideMessage() {
230
		inner.clear();
231 213
		message = new HTML("&nbsp;");
232 214
		this.setVisible(false);
233 215
	}

Also available in: Unified diff