01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.samples.mail.client;
09:
10: import net.mygwt.samples.resources.client.MailItem;
11: import net.mygwt.ui.client.Style;
12: import net.mygwt.ui.client.Registry;
13: import net.mygwt.ui.client.mvc.AppEvent;
14: import net.mygwt.ui.client.mvc.Controller;
15: import net.mygwt.ui.client.mvc.View;
16: import net.mygwt.ui.client.util.Format;
17: import net.mygwt.ui.client.widget.WidgetContainer;
18: import net.mygwt.ui.client.widget.layout.RowData;
19: import net.mygwt.ui.client.widget.layout.RowLayout;
20:
21: import com.google.gwt.user.client.DOM;
22: import com.google.gwt.user.client.ui.HTML;
23:
24: public class MailItemView extends View {
25:
26: private WidgetContainer wrapper;
27: private HTML header;
28: private WidgetContainer body;
29:
30: private String headerHTML = "<div class=mail-item-detail><h1>{0}</h1><h2><b>From:</b> {1}</h2><h3><b>To:</b> {2}</h3></div><div>{3}</div>";
31:
32: public MailItemView(Controller controller) {
33: super (controller);
34: }
35:
36: protected void initialize() {
37: wrapper = new WidgetContainer();
38: wrapper.setLayout(new RowLayout(Style.VERTICAL));
39:
40: header = new HTML("");
41: header.setStyleName("mail-item-detail");
42: wrapper.add(header, new RowData(RowData.FILL_HORIZONTAL));
43:
44: body = new WidgetContainer();
45: body.setScrollEnabled(true);
46: wrapper.add(body, new RowData(RowData.FILL_BOTH));
47: }
48:
49: protected void handleEvent(AppEvent event) {
50: if (event.type == AppEvents.ViewMailItem) {
51: MailItem item = (MailItem) event.data;
52: WidgetContainer south = (WidgetContainer) Registry
53: .get("south");
54:
55: if (item != null) {
56: String[] values = new String[4];
57: values[0] = item.getSubject();
58: values[1] = item.getSender();
59: values[2] = item.getEmail();
60:
61: String s = Format.substitute(headerHTML, values);
62: DOM.setInnerHTML(header.getElement(), s);
63:
64: s = "<div style='padding: 12px'>" + item.getBody()
65: + "</div>";
66: DOM.setInnerHTML(body.getElement(), s);
67:
68: south.removeAll();
69: south.add(wrapper);
70: south.layout(true);
71:
72: } else {
73: south.removeAll();
74: }
75:
76: }
77: }
78:
79: }
|