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.explorer.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.Style;
015: import net.mygwt.ui.client.event.BaseEvent;
016: import net.mygwt.ui.client.event.Listener;
017: import net.mygwt.ui.client.event.SelectionListener;
018: import net.mygwt.ui.client.util.TreeBuilder;
019: import net.mygwt.ui.client.widget.ContentPanel;
020: import net.mygwt.ui.client.widget.ThemeSelector;
021: import net.mygwt.ui.client.widget.ToolButton;
022: import net.mygwt.ui.client.widget.Viewport;
023: import net.mygwt.ui.client.widget.WidgetContainer;
024: import net.mygwt.ui.client.widget.layout.BorderLayout;
025: import net.mygwt.ui.client.widget.layout.BorderLayoutData;
026: import net.mygwt.ui.client.widget.layout.FillLayout;
027: import net.mygwt.ui.client.widget.layout.RowData;
028: import net.mygwt.ui.client.widget.layout.RowLayout;
029: import net.mygwt.ui.client.widget.tree.Tree;
030: import net.mygwt.ui.client.widget.tree.TreeItem;
031:
032: import com.google.gwt.core.client.EntryPoint;
033: import com.google.gwt.user.client.DOM;
034: import com.google.gwt.user.client.Element;
035: import com.google.gwt.user.client.ui.HorizontalPanel;
036: import com.google.gwt.user.client.ui.Label;
037:
038: public class Explorer implements EntryPoint {
039:
040: private Viewport viewport;
041:
042: private ContentPanel westPanel;
043: private ContentPanel centerPanel;
044:
045: private Tree tree;
046: private TreeItem current;
047:
048: private Page currentPage;
049: private List pages = new ArrayList();
050:
051: public Explorer() {
052: pages.add(new ButtonPage());
053: pages.add(new ContentPanelPage());
054: pages.add(new ExpandBarPage());
055: pages.add(new ShellPage());
056: pages.add(new DialogPage());
057: pages.add(new MessageBoxPage());
058: pages.add(new ToolBarPage());
059: pages.add(new ToolTipPage());
060:
061: pages.add(new TabFolderPage());
062:
063: pages.add(new ListPage());
064: pages.add(new CheckBoxListPage());
065: pages.add(new ListContextMenuPage());
066: pages.add(new ListViewerPage());
067: pages.add(new ListViewerFilterPage());
068:
069: pages.add(new DraggablePage());
070: pages.add(new FXPage());
071: pages.add(new ResizablePage());
072:
073: pages.add(new BorderLayoutPage());
074: pages.add(new NestedBorderLayoutPage());
075: pages.add(new RowLayoutPage());
076:
077: pages.add(new PercentageTablePage());
078: pages.add(new TablePage());
079: pages.add(new TableViewerPage());
080: pages.add(new TableViewerFilterPage());
081:
082: pages.add(new TreePage());
083: pages.add(new CheckBoxTreePage());
084: pages.add(new TreeContextMenuPage());
085: pages.add(new TreeViewerPage());
086: pages.add(new TreeViewerFilterPage());
087: pages.add(new AsyncTreeViewerPage());
088: pages.add(new TreeTableViewerPage());
089:
090: }
091:
092: private void show(TreeItem item) {
093: if (current == item) {
094: return;
095: }
096: current = item;
097: currentPage = null;
098: String pageId = item.getId();
099: for (int i = 0; i < pages.size(); i++) {
100: Page page = (Page) pages.get(i);
101: if (page.getId().equals(pageId)) {
102: currentPage = page;
103: break;
104: }
105: }
106:
107: StringBuffer sb = new StringBuffer();
108: while (!item.isRoot()) {
109: sb.insert(0, " / " + item.getText());
110: item = item.getParentItem();
111: }
112: centerPanel.setText(sb.substring(3));
113:
114: if (currentPage == null) {
115: centerPanel.removeAll();
116: centerPanel.layout(true);
117: return;
118: }
119:
120: if (!currentPage.initialized) {
121: currentPage.init();
122: }
123:
124: centerPanel.removeAll();
125: centerPanel.add(currentPage);
126: centerPanel.layout(true);
127: }
128:
129: public void onModuleLoad() {
130: viewport = new Viewport();
131: viewport.setStyleName("my-border-layout");
132:
133: viewport.setLayout(new RowLayout());
134: viewport.setBorders(false);
135:
136: HorizontalPanel header = new HorizontalPanel();
137: header.setStyleName("header");
138: Label lbl = new Label("MyGWT Explorer Demo");
139: lbl.setStyleName("title");
140: header.add(lbl);
141:
142: WidgetContainer main = new WidgetContainer();
143: main.setLayout(new BorderLayout());
144:
145: // create the tree contents
146: tree = new Tree(Style.SINGLE);
147: tree.setItemImageStyle("icon-list");
148:
149: // wrap tree to allow scrolling in content panel
150: WidgetContainer ct = new WidgetContainer();
151: ct.setScrollEnabled(true);
152: ct.add(tree);
153:
154: Element toc = DOM.getElementById("toc");
155: TreeBuilder.buildTree(tree, toc);
156: tree.addListener(Events.SelectionChange, new Listener() {
157: public void handleEvent(BaseEvent be) {
158: TreeItem item = (TreeItem) be.item;
159: if (item != null) {
160: show(item);
161: }
162: }
163: });
164:
165: BorderLayoutData westData = new BorderLayoutData(Style.WEST,
166: 200, 150, 300);
167: westPanel = new ContentPanel(Style.HEADER);
168: westPanel.setLayout(new FillLayout());
169: westPanel.setText("Navigation");
170:
171: ToolButton expandAll = new ToolButton("my-tool-plus");
172: expandAll.setToolTip("Expand All");
173: expandAll.addSelectionListener(new SelectionListener() {
174: public void widgetSelected(BaseEvent be) {
175: tree.expandAll();
176: }
177: });
178: westPanel.getHeader().addWidget(expandAll);
179:
180: ToolButton collapseAll = new ToolButton("my-tool-minus");
181: collapseAll.setToolTip("Collapse All");
182: collapseAll.addSelectionListener(new SelectionListener() {
183: public void widgetSelected(BaseEvent be) {
184: tree.collapseAll();
185: }
186: });
187: westPanel.getHeader().addWidget(collapseAll);
188: westPanel.add(ct);
189:
190: centerPanel = new ContentPanel(Style.HEADER);
191: centerPanel.getHeader().addWidget(new ThemeSelector());
192: centerPanel.setLayout(new FillLayout());
193:
194: main.add(westPanel, westData);
195: main.add(centerPanel, new BorderLayoutData(Style.CENTER));
196:
197: viewport.add(header, new RowData(RowData.FILL_HORIZONTAL));
198: viewport.add(main, new RowData(RowData.FILL_BOTH));
199: viewport.layout();
200:
201: viewport.hideLoadingPanel("loading");
202:
203: }
204:
205: }
|