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.Folder;
11: import net.mygwt.ui.client.Registry;
12: import net.mygwt.ui.client.mvc.AppEvent;
13: import net.mygwt.ui.client.mvc.Controller;
14: import net.mygwt.ui.client.mvc.View;
15: import net.mygwt.ui.client.viewer.IAsyncContentCallback;
16: import net.mygwt.ui.client.viewer.ModelLabelProvider;
17: import net.mygwt.ui.client.viewer.ModelTreeContentProvider;
18: import net.mygwt.ui.client.viewer.SelectionChangedEvent;
19: import net.mygwt.ui.client.viewer.ISelectionChangedListener;
20: import net.mygwt.ui.client.viewer.TreeViewer;
21: import net.mygwt.ui.client.widget.ExpandItem;
22: import net.mygwt.ui.client.widget.tree.Tree;
23:
24: public class MailFolderView extends View {
25:
26: private Tree tree;
27: private TreeViewer folders;
28:
29: public MailFolderView(Controller controller) {
30: super (controller);
31: }
32:
33: protected void initialize() {
34: tree = new Tree();
35: tree.setItemImageStyle("tree-folder");
36:
37: folders = new TreeViewer(tree);
38: folders.setLabelProvider(new ModelLabelProvider());
39: folders.setContentProvider(new ModelTreeContentProvider() {
40:
41: public void getChildren(Object parent,
42: IAsyncContentCallback callback) {
43: if (parent instanceof Folder) {
44: callback.setElements(((Folder) parent)
45: .getChildren().toArray());
46: return;
47: }
48: callback.setElements(null);
49: }
50:
51: public boolean hasChildren(Object element) {
52: return false;
53: }
54:
55: });
56:
57: folders.addSelectionListener(new ISelectionChangedListener() {
58:
59: public void selectionChanged(SelectionChangedEvent se) {
60: Folder f = (Folder) se.getSelection().getFirstElement();
61: AppEvent evt = new AppEvent(AppEvents.ViewMailItems, f);
62: fireEvent(evt);
63: }
64:
65: });
66:
67: ExpandItem mailItem = (ExpandItem) Registry.get("mailItem");
68: mailItem.getContainer().add(tree);
69: mailItem.getContainer().layout(true);
70:
71: Folder mail = (Folder) Registry.get("mail");
72: folders.setInput(mail);
73:
74: }
75:
76: protected void handleEvent(AppEvent event) {
77: Folder mail = (Folder) Registry.get("mail");
78: if (event.type == AppEvents.NavMail) {
79: if (folders.getSelection().size() == 0) {
80: // inbox
81: folders.select(mail.getChild(0));
82: } else {
83: Folder f = (Folder) folders.getSelection()
84: .getFirstElement();
85: AppEvent evt = new AppEvent(AppEvents.ViewMailItems, f);
86: fireEvent(evt);
87: }
88:
89: }
90: }
91:
92: }
|