001: /*
002: * MyGWT Widget Library
003: * Copyright(c) 2007, MyGWT.
004: * licensing@mygwt.net
005: *
006: * http://mygwt.net/license
007: */
008: package net.mygwt.samples.data.client;
009:
010: import java.util.ArrayList;
011: import java.util.List;
012:
013: import net.mygwt.ui.client.Events;
014: import net.mygwt.ui.client.Registry;
015: import net.mygwt.ui.client.Style;
016: import net.mygwt.ui.client.event.BaseEvent;
017: import net.mygwt.ui.client.event.Listener;
018: import net.mygwt.ui.client.event.SelectionListener;
019: import net.mygwt.ui.client.util.TreeBuilder;
020: import net.mygwt.ui.client.widget.ContentPanel;
021: import net.mygwt.ui.client.widget.ThemeSelector;
022: import net.mygwt.ui.client.widget.ToolButton;
023: import net.mygwt.ui.client.widget.Viewport;
024: import net.mygwt.ui.client.widget.WidgetContainer;
025: import net.mygwt.ui.client.widget.layout.BorderLayout;
026: import net.mygwt.ui.client.widget.layout.BorderLayoutData;
027: import net.mygwt.ui.client.widget.layout.FillLayout;
028: import net.mygwt.ui.client.widget.tree.Tree;
029: import net.mygwt.ui.client.widget.tree.TreeItem;
030:
031: import com.google.gwt.core.client.EntryPoint;
032: import com.google.gwt.core.client.GWT;
033: import com.google.gwt.user.client.DOM;
034: import com.google.gwt.user.client.Element;
035: import com.google.gwt.user.client.rpc.ServiceDefTarget;
036:
037: public class DataExplorer implements EntryPoint {
038:
039: private Viewport viewport;
040:
041: private ContentPanel westPanel;
042: private ContentPanel centerPanel;
043:
044: private Tree tree;
045: private TreeItem current;
046:
047: private Page currentPage;
048: private List pages = new ArrayList();
049:
050: public DataExplorer() {
051: pages.add(new XMLTableViewerPage());
052: pages.add(new PagingTableViewerPage());
053: }
054:
055: private void show(TreeItem item) {
056: if (current == item) {
057: return;
058: }
059: current = item;
060: currentPage = null;
061: String pageId = item.getId();
062: for (int i = 0; i < pages.size(); i++) {
063: Page page = (Page) pages.get(i);
064: if (page.getId().equals(pageId)) {
065: currentPage = page;
066: break;
067: }
068: }
069:
070: StringBuffer sb = new StringBuffer();
071: while (!item.isRoot()) {
072: sb.insert(0, " / " + item.getText());
073: item = item.getParentItem();
074: }
075: centerPanel.setText(sb.substring(3));
076:
077: if (currentPage == null) {
078: centerPanel.removeAll();
079: centerPanel.layout(true);
080: return;
081: }
082:
083: if (!currentPage.initialized) {
084: currentPage.init();
085: }
086:
087: centerPanel.removeAll();
088: centerPanel.add(currentPage);
089: centerPanel.layout(true);
090: }
091:
092: public void onModuleLoad() {
093: final SampleServiceAsync service = (SampleServiceAsync) GWT
094: .create(SampleService.class);
095: ServiceDefTarget endpoint = (ServiceDefTarget) service;
096: String moduleRelativeURL = GWT.getModuleBaseURL() + "service";
097: endpoint.setServiceEntryPoint(moduleRelativeURL);
098:
099: Registry.register("service", service);
100:
101: viewport = new Viewport();
102: viewport.setStyleName("my-border-layout");
103: viewport.setLayout(new BorderLayout());
104: viewport.setBorders(false);
105:
106: // create the tree contents
107: tree = new Tree(Style.SINGLE);
108: tree.setItemImageStyle("icon-list");
109:
110: // wrap tree to allow scrolling in content panel
111: WidgetContainer ct = new WidgetContainer();
112: ct.setScrollEnabled(true);
113: ct.add(tree);
114:
115: Element toc = DOM.getElementById("toc");
116: TreeBuilder.buildTree(tree, toc);
117: tree.addListener(Events.SelectionChange, new Listener() {
118: public void handleEvent(BaseEvent be) {
119: TreeItem item = (TreeItem) be.item;
120: show(item);
121: }
122: });
123:
124: BorderLayoutData westData = new BorderLayoutData(Style.WEST,
125: 200, 150, 300);
126:
127: westPanel = new ContentPanel(Style.HEADER);
128: westPanel.setLayout(new FillLayout());
129: westPanel.setText("MyGWT Explorer");
130:
131: ToolButton expandAll = new ToolButton("my-tool-plus");
132: expandAll.setTitle("Expand All");
133: expandAll.addSelectionListener(new SelectionListener() {
134: public void widgetSelected(BaseEvent be) {
135: tree.expandAll();
136: }
137: });
138: westPanel.getHeader().addWidget(expandAll);
139:
140: ToolButton collapseAll = new ToolButton("my-tool-minus");
141: collapseAll.setTitle("Collapse All");
142: collapseAll.addSelectionListener(new SelectionListener() {
143: public void widgetSelected(BaseEvent be) {
144: tree.collapseAll();
145: }
146: });
147: westPanel.getHeader().addWidget(collapseAll);
148: westPanel.add(ct);
149:
150: centerPanel = new ContentPanel(Style.HEADER);
151: centerPanel.getHeader().addWidget(new ThemeSelector());
152: centerPanel.setLayout(new FillLayout());
153:
154: viewport.add(westPanel, westData);
155: viewport.add(centerPanel, new BorderLayoutData(Style.CENTER));
156:
157: viewport.layout();
158:
159: viewport.hideLoadingPanel("loading");
160:
161: }
162:
163: }
|