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.TestData;
11: import net.mygwt.ui.client.Style;
12: import net.mygwt.ui.client.data.Model;
13: import net.mygwt.ui.client.event.BaseEvent;
14: import net.mygwt.ui.client.event.SelectionListener;
15: import net.mygwt.ui.client.viewer.ListViewer;
16: import net.mygwt.ui.client.viewer.ModelComparator;
17: import net.mygwt.ui.client.viewer.ModelContentProvider;
18: import net.mygwt.ui.client.viewer.ModelLabelProvider;
19: import net.mygwt.ui.client.viewer.Viewer;
20: import net.mygwt.ui.client.viewer.ViewerFilter;
21: import net.mygwt.ui.client.viewer.ViewerSorter;
22: import net.mygwt.ui.client.widget.Button;
23: import net.mygwt.ui.client.widget.ButtonBar;
24: import net.mygwt.ui.client.widget.List;
25: import net.mygwt.ui.client.widget.WidgetContainer;
26: import net.mygwt.ui.client.widget.layout.FlowLayout;
27:
28: public class ListViewerPage extends Page {
29:
30: protected void createWidget(WidgetContainer container) {
31: List list = new List(Style.MULTI);
32: list.setSize(210, 200);
33:
34: final ListViewer viewer = new ListViewer(list);
35: viewer.setContentProvider(new ModelContentProvider());
36: viewer.setLabelProvider(new ModelLabelProvider() {
37: public String getIconStyle(Object element) {
38: return "icon-chart";
39: }
40: });
41:
42: // sorter & filter
43: final ViewerSorter sorter = new ViewerSorter(
44: new ModelComparator());
45: final ViewerFilter filter = new ViewerFilter() {
46:
47: public boolean select(Viewer viewer, Object parent,
48: Object element) {
49: Model m = (Model) element;
50: if (m.getAsString("name").charAt(0) == 'A') {
51: return false;
52: }
53: return true;
54: }
55:
56: };
57:
58: viewer.setInput(TestData.getStocks());
59:
60: ButtonBar buttonBar = new ButtonBar();
61: buttonBar.add(new Button("Sort", new SelectionListener() {
62: public void widgetSelected(BaseEvent be) {
63: viewer.setSorter(sorter);
64: }
65: }));
66: buttonBar.add(new Button("Filter 'A's",
67: new SelectionListener() {
68: public void widgetSelected(BaseEvent be) {
69: viewer.addFilter(filter);
70: }
71: }));
72:
73: FlowLayout layout = new FlowLayout(8);
74: layout.setSpacing(5);
75: container.setScrollEnabled(true);
76: container.setLayout(layout);
77: container.add(buttonBar);
78: container.add(list);
79:
80: }
81:
82: }
|