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.explorer.client;
09:
10: import net.mygwt.samples.resources.client.Folder;
11: import net.mygwt.samples.resources.client.TestData;
12: import net.mygwt.ui.client.data.Model;
13: import net.mygwt.ui.client.viewer.IAsyncContentCallback;
14: import net.mygwt.ui.client.viewer.ITreeContentProvider;
15: import net.mygwt.ui.client.viewer.ModelLabelProvider;
16: import net.mygwt.ui.client.viewer.TreeViewer;
17: import net.mygwt.ui.client.viewer.Viewer;
18: import net.mygwt.ui.client.widget.WidgetContainer;
19: import net.mygwt.ui.client.widget.layout.FlowLayout;
20: import net.mygwt.ui.client.widget.tree.Tree;
21:
22: import com.google.gwt.user.client.Timer;
23:
24: public class AsyncTreeViewerPage extends Page {
25:
26: protected void createWidget(WidgetContainer container) {
27: ITreeContentProvider cp = new ITreeContentProvider() {
28:
29: public Object getParent(Object element) {
30: return ((Model) element).getParent();
31: }
32:
33: public boolean hasChildren(Object parent) {
34: if (parent instanceof Folder) {
35: return true;
36: }
37: return false;
38: }
39:
40: public void getChildren(final Object parent,
41: final IAsyncContentCallback callback) {
42: // emulate delay of rpc call
43: Timer t = new Timer() {
44: public void run() {
45: Model m = (Model) parent;
46: callback.setElements(m.getChildren().toArray());
47: }
48: };
49: t.schedule(1500);
50: }
51:
52: public void inputChanged(Viewer viewer, Object oldInput,
53: Object newInput) {
54:
55: }
56:
57: };
58:
59: Folder folder = TestData.getTreeModel();
60:
61: Tree tree = new Tree();
62: tree.setItemImageStyle("icon-music");
63:
64: TreeViewer viewer = new TreeViewer(tree);
65: viewer.setContentProvider(cp);
66: viewer.setLabelProvider(new ModelLabelProvider());
67:
68: viewer.setInput(folder);
69:
70: container.setLayout(new FlowLayout());
71: container.add(tree);
72: }
73: }
|