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.data.client;
09:
10: import net.mygwt.ui.client.Events;
11: import net.mygwt.ui.client.Style;
12: import net.mygwt.ui.client.MyGWT;
13: import net.mygwt.ui.client.event.BaseEvent;
14: import net.mygwt.ui.client.event.Listener;
15: import net.mygwt.ui.client.widget.TabFolder;
16: import net.mygwt.ui.client.widget.TabItem;
17: import net.mygwt.ui.client.widget.WidgetContainer;
18: import net.mygwt.ui.client.widget.layout.FillLayout;
19:
20: import com.google.gwt.core.client.EntryPoint;
21: import com.google.gwt.core.client.GWT;
22: import com.google.gwt.user.client.ui.RootPanel;
23:
24: public abstract class Page extends WidgetContainer implements
25: EntryPoint {
26:
27: public boolean initialized = false;
28:
29: private TabFolder tabFolder;
30: private TabItem contentItem, sourceItem;
31: private boolean loadedSource = false;
32:
33: protected boolean hasSource;
34:
35: public void onModuleLoad() {
36: WidgetContainer c = new WidgetContainer();
37: createWidget(c);
38:
39: RootPanel.get().add(c);
40: MyGWT.hideLoadingPanel("my-start-panel");
41: }
42:
43: protected abstract void createWidget(WidgetContainer container);
44:
45: final public String getId() {
46: String s = GWT.getTypeName(this );
47: return s.substring(s.lastIndexOf(".") + 1, s.length());
48: }
49:
50: protected void init() {
51: initialized = true;
52: FillLayout layout = new FillLayout();
53: setLayout(layout);
54:
55: tabFolder = new TabFolder(Style.NONE);
56: tabFolder.setBorders(false);
57: final Page fPage = this ;
58: tabFolder.addListener(Events.SelectionChange, new Listener() {
59: public void handleEvent(BaseEvent be) {
60: TabItem item = (TabItem) be.item;
61: if (item == sourceItem && !loadedSource) {
62: loadedSource = true;
63: String name = GWT.getTypeName(fPage);
64: name = name.substring(name.lastIndexOf(".") + 1);
65: name = "code/" + name + ".html";
66: item.setURL(name);
67: }
68: }
69:
70: });
71: add(tabFolder);
72:
73: contentItem = new TabItem(Style.NONE);
74: contentItem.setText("View");
75:
76: createWidget(contentItem.getContainer());
77:
78: tabFolder.add(contentItem);
79:
80: sourceItem = new TabItem(Style.NONE);
81: sourceItem.setText("Source");
82: tabFolder.add(sourceItem);
83:
84: tabFolder.setSelection(contentItem);
85:
86: }
87:
88: }
|