01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08: package com.gwtext.sample.showcase2.client;
09:
10: import com.google.gwt.user.client.Element;
11: import com.google.gwt.user.client.DeferredCommand;
12: import com.google.gwt.user.client.Command;
13: import com.gwtext.client.core.EventObject;
14: import com.gwtext.client.core.XTemplate;
15: import com.gwtext.client.data.Record;
16: import com.gwtext.client.data.Store;
17: import com.gwtext.client.util.DOMUtil;
18: import com.gwtext.client.util.Format;
19: import com.gwtext.client.widgets.DataView;
20: import com.gwtext.client.widgets.Panel;
21: import com.gwtext.client.widgets.event.DataViewListenerAdapter;
22: import com.gwtext.client.widgets.layout.FitLayout;
23:
24: public class ShowcaseView extends Panel {
25:
26: private ScreenManager screenManager;
27:
28: public ShowcaseView(ScreenManager screenManager) {
29: this .screenManager = screenManager;
30: setBorder(false);
31: setLayout(new FitLayout());
32: setAutoScroll(true);
33: }
34:
35: protected void afterRender() {
36: final Store store = ScreenManager.getStore();
37:
38: XTemplate template = new XTemplate(
39: new String[] {
40: "<tpl for='.'>",
41: "<tpl if='thumbnail'>",
42: "<div id={id}-dv class='thumb-wrap'>",
43: "<div class='thumb'><img src='{thumbnail}' ext:qtip='{title}'></div>",
44: "<span class='x-editable' ext:qtip='{title}'>{shortTitle}</span></div>",
45: "</tpl>", "</tpl>",
46: "<div class='x-clear'></div>" });
47:
48: Panel panel = new Panel();
49: panel.setId("showcase-view");
50: panel.setAutoWidth(true);
51: panel.setAutoScroll(true);
52: panel.setCollapsible(true);
53: panel.setLayout(new FitLayout());
54: panel.setTitle("Welcome to GWT-Ext 2.0");
55:
56: final DataView dataView = new DataView("div.thumb-wrap") {
57: public void prepareData(Data data) {
58: data.setProperty("shortTitle", Format.ellipsis(data
59: .getProperty("title"), 15));
60: }
61: };
62:
63: dataView.addListener(new DataViewListenerAdapter() {
64:
65: public void onClick(DataView source, int index,
66: Element node, EventObject e) {
67: String id = DOMUtil.getID(node);
68: String screenName = id.substring(0, id.length() - 3);
69: Record[] records = store.query("id", screenName);
70: Record record = records[0];
71: final ShowcasePanel panel = (ShowcasePanel) record
72: .getAsObject("screen");
73: if (panel != null) {
74: String title = record.getAsString("title");
75: String icon = record.getAsString("icon");
76: screenManager.showScreen(panel, title, icon,
77: screenName);
78: }
79: }
80: });
81:
82: dataView.setTpl(template);
83: dataView.setAutoWidth(true);
84: dataView.setAutoHeight(true);
85: dataView.setMultiSelect(false);
86: dataView.setOverCls("x-view-over");
87: dataView.setEmptyText("No Images to display");
88: panel.add(dataView);
89:
90: DeferredCommand.addCommand(new Command() {
91: public void execute() {
92: dataView.setStore(store);
93: dataView.refresh();
94: }
95: });
96: add(panel);
97: }
98:
99: }
|