001: /*
002: * MyGWT Widget Library
003: * Copyright(c) 2007, MyGWT.
004: * licensing@mygwt.net
005: *
006: * http://mygwt.net/license
007: */
008: package net.mygwt.samples.mail.client;
009:
010: import net.mygwt.samples.resources.client.Folder;
011: import net.mygwt.samples.resources.client.MailItem;
012: import net.mygwt.ui.client.Events;
013: import net.mygwt.ui.client.Registry;
014: import net.mygwt.ui.client.Style;
015: import net.mygwt.ui.client.event.BaseEvent;
016: import net.mygwt.ui.client.event.Listener;
017: import net.mygwt.ui.client.mvc.AppEvent;
018: import net.mygwt.ui.client.mvc.Controller;
019: import net.mygwt.ui.client.mvc.View;
020: import net.mygwt.ui.client.widget.ContentPanel;
021: import net.mygwt.ui.client.widget.WidgetContainer;
022: import net.mygwt.ui.client.widget.table.Table;
023: import net.mygwt.ui.client.widget.table.TableColumn;
024: import net.mygwt.ui.client.widget.table.TableColumnModel;
025: import net.mygwt.ui.client.widget.table.TableItem;
026:
027: public class MailListView extends View {
028:
029: private Table table;
030: private Folder folder;
031:
032: public MailListView(Controller controller) {
033: super (controller);
034: }
035:
036: protected void handleEvent(AppEvent event) {
037: if (event.type == AppEvents.ViewMailItems) {
038: Folder f = (Folder) event.data;
039:
040: ContentPanel center = (ContentPanel) Registry.get("center");
041: center.setText(f.getName());
042:
043: center.removeAll();
044: center.add(table);
045: center.layout(true);
046:
047: WidgetContainer south = (WidgetContainer) Registry
048: .get("south");
049: south.removeAll();
050:
051: if (folder != f) {
052: folder = f;
053: table.removeAll();
054: for (int i = 0; i < f.getChildCount(); i++) {
055: MailItem m = (MailItem) f.getChild(i);
056: Object[] values = new Object[3];
057: values[0] = m.getSender();
058: values[1] = m.getEmail();
059: values[2] = m.getSubject();
060: TableItem item = new TableItem(values);
061: item.setData(m);
062: table.add(item);
063: }
064: if (table.getItemCount() > 0) {
065: table.select(0);
066: }
067: } else {
068: if (table.getSelection().length > 0) {
069: TableItem item = table.getSelection()[0];
070: MailItem mail = (MailItem) item.getData();
071: showMailItem(mail);
072: }
073: }
074:
075: }
076: }
077:
078: protected void initialize() {
079: TableColumn[] columns = new TableColumn[3];
080: columns[0] = new TableColumn("sender", "Sender", .2f);
081: columns[1] = new TableColumn("email", "Email", .3f);
082: columns[2] = new TableColumn("subject", "Subject", .5f);
083:
084: TableColumnModel cm = new TableColumnModel(columns);
085:
086: table = new Table(Style.MULTI, cm);
087: table.setBorders(false);
088:
089: table.addListener(Events.SelectionChange, new Listener() {
090:
091: public void handleEvent(BaseEvent be) {
092: if (table.getSelection().length > 0) {
093: TableItem item = table.getSelection()[0];
094: MailItem mail = (MailItem) item.getData();
095: showMailItem(mail);
096: }
097: }
098: });
099: }
100:
101: private void showMailItem(MailItem item) {
102: AppEvent evt = new AppEvent(AppEvents.ViewMailItem, item);
103: fireEvent(evt);
104: }
105:
106: }
|