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.Stock;
12: import net.mygwt.samples.resources.client.TestData;
13: import net.mygwt.ui.client.Style;
14: import net.mygwt.ui.client.widget.ContentPanel;
15: import net.mygwt.ui.client.widget.WidgetContainer;
16: import net.mygwt.ui.client.widget.layout.FillLayout;
17: import net.mygwt.ui.client.widget.table.CellRenderer;
18: import net.mygwt.ui.client.widget.table.DateTimeCellRenderer;
19: import net.mygwt.ui.client.widget.table.NumberCellRenderer;
20: import net.mygwt.ui.client.widget.table.Table;
21: import net.mygwt.ui.client.widget.table.TableColumn;
22: import net.mygwt.ui.client.widget.table.TableColumnModel;
23: import net.mygwt.ui.client.widget.table.TableItem;
24:
25: import com.google.gwt.i18n.client.NumberFormat;
26:
27: public class TablePage extends Page {
28:
29: protected void createWidget(WidgetContainer container) {
30: final NumberFormat currency = NumberFormat.getCurrencyFormat();
31: final NumberFormat number = NumberFormat.getFormat("0.00");
32:
33: TableColumn[] columns = new TableColumn[5];
34:
35: columns[0] = new TableColumn("Company", 180);
36: columns[0].setMinWidth(75);
37: columns[0].setMaxWidth(300);
38:
39: columns[1] = new TableColumn("Symbol", 75);
40:
41: columns[2] = new TableColumn("Last", 75);
42: columns[2].setMaxWidth(100);
43: columns[2].setAlignment(Style.RIGHT);
44: columns[2].setRenderer(new NumberCellRenderer(currency));
45:
46: columns[3] = new TableColumn("Change", 75);
47: columns[3].setAlignment(Style.RIGHT);
48: columns[3].setRenderer(new CellRenderer() {
49: public String render(String property, Object value) {
50: double val = ((Double) value).doubleValue();
51: String style = val < 0 ? "red" : "green";
52: return "<span style='color:" + style + "'>"
53: + number.format(val) + "</span>";
54: }
55: });
56:
57: columns[4] = new TableColumn("Last Updated", 100);
58: columns[4].setAlignment(Style.RIGHT);
59: columns[4].setRenderer(new DateTimeCellRenderer("MM/d/y"));
60:
61: TableColumnModel cm = new TableColumnModel(columns);
62:
63: Table tbl = new Table(Style.MULTI | Style.HORIZONTAL, cm);
64: tbl.setBorders(false);
65:
66: Folder stocks = TestData.getStocks();
67: for (int i = 0; i < stocks.getChildCount(); i++) {
68: Stock stock = (Stock) stocks.getChild(i);
69: Object[] values = new Object[5];
70: values[0] = stock.getName();
71: values[1] = stock.getSymbol();
72: values[2] = new Double(stock.getLast());
73: values[3] = new Double(stock.getLast() - stock.getOpen());
74: values[4] = stock.getLastTrans();
75:
76: TableItem item = new TableItem(values);
77: tbl.add(item);
78: }
79:
80: ContentPanel panel = new ContentPanel(Style.HEADER
81: | Style.COLLAPSE);
82: panel.setFrame(true);
83: panel.setAnimateCollapse(false);
84: panel.setText("Table Demo");
85: panel.setLayout(new FillLayout());
86: panel.add(tbl);
87:
88: container.setLayout(new FillLayout(15));
89: container.add(panel);
90: }
91:
92: }
|