Revision: 7704
Author: [email protected]
Date: Thu Mar 11 08:39:56 2010
Log: Lots of prettier styles for the stock sample.

http://code.google.com/p/google-web-toolkit/source/detail?r=7704

Added:
 /trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/EllipsisCell.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/FavoritesWidget.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/FavoritesWidget.ui.xml /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.ui.xml /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.ui.xml
 /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/common.css
 /trunk/bikeshed/war/bg.png
 /trunk/bikeshed/war/blueborder.png
 /trunk/bikeshed/war/border.png
Modified:
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/StockSample.gwt.xml /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/Columns.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.java
 /trunk/bikeshed/war/Stocks.css

=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/cells/client/EllipsisCell.java Thu Mar 11 08:39:56 2010
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.bikeshed.cells.client;
+
+public class EllipsisCell extends Cell<String> {
+
+  @Override
+  public void render(String value, StringBuilder sb) {
+ sb.append("<div style='overflow:hidden; white-space:nowrap; text-overflow:ellipsis;'>");
+    sb.append(value);
+    sb.append("</div>");
+  }
+}
=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/FavoritesWidget.java Thu Mar 11 08:39:56 2010
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.bikeshed.sample.stocks.client;
+
+import com.google.gwt.bikeshed.list.client.PagingTableListView;
+import com.google.gwt.bikeshed.list.client.TextHeader;
+import com.google.gwt.bikeshed.list.shared.ListModel;
+import com.google.gwt.bikeshed.sample.stocks.shared.StockQuote;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiFactory;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Widget;
+
+public class FavoritesWidget extends Composite {
+
+  interface Binder extends UiBinder<Widget, FavoritesWidget> { }
+  private static final Binder binder = GWT.create(Binder.class);
+
+  @UiField PagingTableListView<StockQuote> listView;
+
+  private final ListModel<StockQuote> model;
+
+  public FavoritesWidget(ListModel<StockQuote> model) {
+    this.model = model;
+    initWidget(binder.createAndBindUi(this));
+
+    listView.addColumn(Columns.tickerColumn, new TextHeader("ticker"));
+    listView.addColumn(Columns.priceColumn, new TextHeader("price"));
+    listView.addColumn(Columns.changeColumn, new TextHeader("change"));
+    listView.addColumn(Columns.sharesColumn, new TextHeader("shares"));
+    listView.addColumn(Columns.dollarsColumn, new TextHeader("value"));
+    listView.addColumn(Columns.buyColumn);
+    listView.addColumn(Columns.sellColumn);
+  }
+
+  @UiFactory
+  PagingTableListView<StockQuote> createListView() {
+    return new PagingTableListView<StockQuote>(model, 10);
+  }
+}
=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/FavoritesWidget.ui.xml Thu Mar 11 08:39:56 2010
@@ -0,0 +1,19 @@
+<ui:UiBinder
+  xmlns:ui='urn:ui:com.google.gwt.uibinder'
+  xmlns:g='urn:import:com.google.gwt.user.client.ui'
+  xmlns:l='urn:import:com.google.gwt.bikeshed.list.client'
+  xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
+  xmlns:s='urn:import:com.google.gwt.bikeshed.sample.stocks.client'>
+
+  <ui:style field='common' src='common.css'/>
+
+  <g:DockLayoutPanel unit='EM'>
+    <g:north size='2'>
+ <g:Label styleName='{common.header-left}'>Portfolio / Favorites</g:Label>
+    </g:north>
+
+    <g:center>
+ <l:PagingTableListView ui:field='listView' styleName='{common.table}'/>
+    </g:center>
+  </g:DockLayoutPanel>
+</ui:UiBinder>
=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.ui.xml Thu Mar 11 08:39:56 2010
@@ -0,0 +1,19 @@
+<ui:UiBinder
+  xmlns:ui='urn:ui:com.google.gwt.uibinder'
+  xmlns:g='urn:import:com.google.gwt.user.client.ui'
+  xmlns:l='urn:import:com.google.gwt.bikeshed.list.client'
+  xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
+  xmlns:s='urn:import:com.google.gwt.bikeshed.sample.stocks.client'>
+
+  <ui:style field='common' src='common.css'/>
+
+  <g:DockLayoutPanel unit='EM'>
+    <g:north size='2'>
+ <g:HTMLPanel><span class='{common.header-left}'>Enter query:</span> <g:TextBox ui:field='queryField'/></g:HTMLPanel>
+    </g:north>
+
+    <g:center>
+ <l:PagingTableListView ui:field='listView' styleName='{common.table}'/>
+    </g:center>
+  </g:DockLayoutPanel>
+</ui:UiBinder>
=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.ui.xml Thu Mar 11 08:39:56 2010
@@ -0,0 +1,60 @@
+<ui:UiBinder
+  xmlns:ui='urn:ui:com.google.gwt.uibinder'
+  xmlns:g='urn:import:com.google.gwt.user.client.ui'
+  xmlns:l='urn:import:com.google.gwt.bikeshed.list.client'
+  xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
+  xmlns:s='urn:import:com.google.gwt.bikeshed.sample.stocks.client'>
+
+  <ui:style field='common' src='common.css'/>
+
+  <g:DockLayoutPanel unit='EM'>
+    <g:north size='4'>
+ <g:HTML styleName='{common.bg} {common.header-main}'>Day Trader</g:HTML>
+    </g:north>
+
+    <g:west size='16'>
+      <g:DockLayoutPanel unit='EM'>
+        <g:north size='12'>
+          <g:HTMLPanel styleName='{common.bg}'>
+            <div class='{common.header}'>Your Stats</div>
+            <table>
+ <tr><td>Available cash:</td><td><g:InlineLabel ui:field='cashLabel'/></td></tr> + <tr><td>Net worth:</td><td><g:InlineLabel ui:field='netWorthLabel'/></td></tr>
+            </table>
+          </g:HTMLPanel>
+        </g:north>
+
+        <g:center>
+          <g:ScrollPanel styleName='{common.bg}'>
+            <g:HTMLPanel>
+              <div class='{common.header}'>Everyone Else</div>
+              <table>
+                <tr><td>Dan Rice</td><td>$10000</td></tr>
+                <tr><td>Joel Webber</td><td>$10000</td></tr>
+                <tr><td>John Labanca</td><td>$10000</td></tr>
+              </table>
+            </g:HTMLPanel>
+          </g:ScrollPanel>
+        </g:center>
+      </g:DockLayoutPanel>
+    </g:west>
+
+    <g:north size="18">
+      <g:ScrollPanel styleName='{common.bg}'>
+        <t:SideBySideTreeView ui:field='transactionTree'/>
+      </g:ScrollPanel>
+    </g:north>
+
+    <g:center>
+      <g:DockLayoutPanel unit='PCT'>
+        <g:west size="50">
+ <s:StockQueryWidget styleName='{common.bg}' ui:field='queryWidget'/>
+        </g:west>
+
+        <g:center>
+ <s:FavoritesWidget styleName='{common.bg}' ui:field='favoritesWidget'/>
+        </g:center>
+      </g:DockLayoutPanel>
+    </g:center>
+  </g:DockLayoutPanel>
+</ui:UiBinder>
=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/common.css Thu Mar 11 08:39:56 2010
@@ -0,0 +1,47 @@
+/* text-overflow: ellipsis; */
+
+.bg {
+  border: 8px solid white;
+  border-right: 12px solid white;
+  border-bottom: 14px solid white;
+  -webkit-border-image: url(border.png) 8 12 14 8 round round;
+  -gecko-border-image: url(border.png) 8 12 14 8 round round;
+}
+
+.header {
+  font-weight: light;
+  font-size: 12pt;
+  text-align: center;
+  margin-bottom: 0.5em;
+}
+
+.header-left {
+  font-weight: light;
+  font-size: 12pt;
+  margin-bottom: 0.5em;
+}
+
+.header-main {
+  font-weight: light;
+  font-size: 18pt;
+}
+
+.table {
+  width: 100%;
+  font-size: 8pt;
+  border-spacing: 0px 0px;
+  border-collapse: collapse;
+}
+
+.table th {
+  border-bottom: 1px solid #ccc;
+}
+
+.table td {
+  border-left: 1px solid #ccc;
+  border-right: 1px solid #ccc;
+}
+
+.table tfoot th {
+  border-width: 0px;
+}
=======================================
--- /dev/null
+++ /trunk/bikeshed/war/bg.png  Thu Mar 11 08:39:56 2010
@@ -0,0 +1,5 @@
+‰PNG
+ + +IHDR L #±Jl tEXtSoftware Adobe ImageReadyqÉe< EIDATxÚŒN[ + ’î gÛ ÖZT ¢L'‚ä `PMÕq# ]X³4¯³wTÞr7ïÕ ÛœOÛrcë(¿?]‹Ÿ § EÊj-Oöºµ IEND®B`‚
=======================================
--- /dev/null
+++ /trunk/bikeshed/war/blueborder.png  Thu Mar 11 08:39:56 2010
@@ -0,0 +1,15 @@
+‰PNG
+ + +IHDR ÔôU tEXtSoftware Adobe ImageReadyqÉe< ÖIDATxÚä–1KÃ@ Ç/¹¤µj­n –JÅÁA*è7 ô ˆ«³è7ðC8 ] +tu–Š[7E Š8X ¦(‚‚•ÖÖ$wÞ•»ð</˜¶éäƒ?I.ð~yï]Þ;ã¨\Í9¯æÉm½¹Ôêø êà ³c÷ ·¶¾»¹ú(–¨FÈzx1Jõ·Ïùíµ ´’Ÿè t...@Çåç9”š=e ᘀ+
`cÿ†^× t »¸ §[Å
+w:É”aJ3 2%™l&ÌdZœ_鴄 ¶Ì2ÒlwK `ò
+`
+ù;j¡x-)@ž Àú ÀIЯM 7,¡DDD¤Æ0"³ È— CˆÄ
+...@Ýh͘a € $PÜ0C ‘/ã†A( +-²Ðþ:¬Èþ#Œ ‰A¬â4a¥h(Œ >6 ÐeµÑ èî©
+Šg Z˜¶
+0Ç~ Í 7ò       Ë ßAÉÉ‹1Ñ“  `š ÂÎùáÞ  –D  [5!zš-î“Br=  ) {B_L
+¦¶¸º\XÓÃLå_15_¬Ê r Ô ë + ¤€ä”õ# Ü¿`H)( ‡ /‚Ü g_f kÚ u...@z +¦ ûÅš´Qå æk À &2ªlÝ(õ
+ƒ ~t‘éN´Qv#    ƒH¿ß   bBWv㮋»    IEND®B`‚
=======================================
--- /dev/null   
+++ /trunk/bikeshed/war/border.png      Thu Mar 11 08:39:56 2010
Binary file, no diff available.
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/StockSample.gwt.xml Fri Feb 26 09:32:06 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/StockSample.gwt.xml Thu Mar 11 08:39:56 2010
@@ -6,20 +6,10 @@
   <inherits name='com.google.gwt.bikeshed.list.List'/>
   <inherits name='com.google.gwt.bikeshed.tree.Tree'/>

-  <!-- Inherit the default GWT style sheet.  You can change       -->
-  <!-- the theme of your GWT application by uncommenting          -->
-  <!-- any one of the following lines.                            -->
-  <inherits name='com.google.gwt.user.theme.standard.Standard'/>
-  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
-  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->
-
-  <!-- Other module inherits                                      -->
-
   <!-- Specify the app entry point class.                         -->
<entry-point class='com.google.gwt.bikeshed.sample.stocks.client.StockSample'/>

   <!-- Specify the paths for translatable code                    -->
   <source path='client'/>
   <source path='shared'/>
-
 </module>
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/Columns.java Thu Mar 11 03:44:25 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/Columns.java Thu Mar 11 08:39:56 2010
@@ -18,6 +18,7 @@
 import com.google.gwt.bikeshed.cells.client.ButtonCell;
 import com.google.gwt.bikeshed.cells.client.CheckboxCell;
 import com.google.gwt.bikeshed.cells.client.CurrencyCell;
+import com.google.gwt.bikeshed.cells.client.EllipsisCell;
 import com.google.gwt.bikeshed.cells.client.ProfitLossCell;
 import com.google.gwt.bikeshed.cells.client.TextCell;
 import com.google.gwt.bikeshed.list.client.Column;
@@ -62,7 +63,7 @@
   };

   static Column<StockQuote, String> nameColumn =
-    new Column<StockQuote, String>(new TextCell()) {
+    new Column<StockQuote, String>(new EllipsisCell()) {
     @Override
     protected String getValue(StockQuote object) {
       return object.getName();
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java Wed Mar 10 08:48:25 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java Thu Mar 11 08:39:56 2010
@@ -19,57 +19,59 @@
 import com.google.gwt.bikeshed.list.client.TextHeader;
 import com.google.gwt.bikeshed.list.shared.ListModel;
 import com.google.gwt.bikeshed.sample.stocks.shared.StockQuote;
-import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.event.dom.client.KeyUpEvent;
 import com.google.gwt.event.dom.client.KeyUpHandler;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiFactory;
+import com.google.gwt.uibinder.client.UiField;
 import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.DockLayoutPanel;
-import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.ScrollPanel;
 import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;

 /**
  * A widget containing a search box and a results table.
  */
 public class StockQueryWidget extends Composite {

-  private final TextBox queryField = new TextBox();
-  private PagingTableListView<StockQuote> resultsTable;
-
- public StockQueryWidget(ListModel<StockQuote> searchListModel, final Updater updater) {
-    // Create the results table.
- resultsTable = new PagingTableListView<StockQuote>(searchListModel, 10);
-    resultsTable.addColumn(Columns.favoriteColumn);
-    resultsTable.addColumn(Columns.tickerColumn, new TextHeader("ticker"));
-    resultsTable.addColumn(Columns.nameColumn, new TextHeader("name"));
-    resultsTable.addColumn(Columns.priceColumn, new TextHeader("price"));
-    resultsTable.addColumn(Columns.buyColumn);
-
+  interface Binder extends UiBinder<Widget, StockQueryWidget> { }
+  private static final Binder binder = GWT.create(Binder.class);
+
+  @UiField TextBox queryField = new TextBox();
+  @UiField PagingTableListView<StockQuote> listView;
+
+  private final ListModel<StockQuote> model;
+
+ public StockQueryWidget(ListModel<StockQuote> model, final Updater updater) {
+    this.model = model;
+    initWidget(binder.createAndBindUi(this));
+
+    listView.addColumn(Columns.favoriteColumn);
+    listView.addColumn(Columns.tickerColumn, new TextHeader("ticker"));
+    listView.addColumn(Columns.nameColumn, new TextHeader("name"));
+    listView.addColumn(Columns.changeColumn, new TextHeader("change"));
+    listView.addColumn(Columns.priceColumn, new TextHeader("price"));
+    listView.addColumn(Columns.buyColumn);
+
     // Focus the cursor on the name field when the app loads
     queryField.setFocus(true);
     queryField.selectAll();
     queryField.setText("G");
-
+
     // Add a handler to send the name to the server
     queryField.addKeyUpHandler(new KeyUpHandler() {
       public void onKeyUp(KeyUpEvent event) {
         updater.update();
       }
     });
-
-    DockLayoutPanel layoutPanel = new DockLayoutPanel(Unit.EM);
-
-    HorizontalPanel panel = new HorizontalPanel();
-    panel.add(new Label("Enter query: "));
-    panel.add(queryField);
-    layoutPanel.addNorth(panel, 2.0);
-    layoutPanel.add(new ScrollPanel(resultsTable));
-
-    initWidget(layoutPanel);
-  }
-
+  }
+
   public String getSearchQuery() {
     return queryField.getText();
   }
-}
+
+  @UiFactory
+  PagingTableListView<StockQuote> createListView() {
+    return new PagingTableListView<StockQuote>(model, 10);
+  }
+}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.java Thu Mar 11 03:44:25 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockSample.java Thu Mar 11 08:39:56 2010
@@ -16,8 +16,6 @@
 package com.google.gwt.bikeshed.sample.stocks.client;

 import com.google.gwt.bikeshed.cells.client.FieldUpdater;
-import com.google.gwt.bikeshed.list.client.PagingTableListView;
-import com.google.gwt.bikeshed.list.client.TextHeader;
 import com.google.gwt.bikeshed.list.shared.AsyncListModel;
 import com.google.gwt.bikeshed.list.shared.ListListModel;
 import com.google.gwt.bikeshed.list.shared.Range;
@@ -32,21 +30,18 @@
 import com.google.gwt.bikeshed.tree.client.TreeNode;
 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.event.logical.shared.CloseEvent;
 import com.google.gwt.event.logical.shared.CloseHandler;
 import com.google.gwt.i18n.client.NumberFormat;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiFactory;
+import com.google.gwt.uibinder.client.UiField;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.DockLayoutPanel;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.PopupPanel;
 import com.google.gwt.user.client.ui.RootLayoutPanel;
-import com.google.gwt.user.client.ui.ScrollPanel;
-import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;

 import java.util.HashMap;
@@ -67,38 +62,30 @@
     return NumberFormat.getCurrencyFormat("USD").format(price / 100.0);
   }

-  /**
-   * The popup used to purchase stock.
-   */
-  private BuySellPopup buySellPopup = new BuySellPopup();
-
-  private final Label cashLabel = new Label();
-
-  /**
-   * The {...@link StockService} used to retrieve data.
-   */
private final StockServiceAsync dataService = GWT.create(StockService.class);

-  private AsyncListModel<StockQuote> favoritesListModel;
-
-  private PagingTableListView<StockQuote> favoritesTable;
-
-  private final Label netWorthLabel = new Label();
-
-  private StockQueryWidget queryWidget;
-
-  private AsyncListModel<StockQuote> searchListModel;
-
private Map<String, ListListModel<Transaction>> transactionListListModelsByTicker =
     new HashMap<String, ListListModel<Transaction>>();
-
+  private List<Transaction> transactions;
+
+  private AsyncListModel<StockQuote> favoritesListModel;
+  private AsyncListModel<StockQuote> searchListModel;
   private ListListModel<Transaction> transactionListModel;
-
-  private List<Transaction> transactions;
-
-  private SideBySideTreeView transactionTree;
-
-  private TransactionTreeViewModel treeModel;
+  private TransactionTreeViewModel treeModel;
+
+  interface Binder extends UiBinder<Widget, StockSample> { }
+  private static final Binder binder = GWT.create(Binder.class);
+
+  @UiField Label cashLabel;
+  @UiField Label netWorthLabel;
+  @UiField FavoritesWidget favoritesWidget;
+  @UiField StockQueryWidget queryWidget;
+  @UiField SideBySideTreeView transactionTree;
+
+  /**
+   * The popup used to purchase stock.
+   */
+  private BuySellPopup buySellPopup = new BuySellPopup();

   /**
    * The timer used to update the stock quotes.
@@ -114,8 +101,8 @@
    * This is the entry point method.
    */
   public void onModuleLoad() {
-
-    // Create the list models
+ // Create the various models. Do this before binding the UI, because some
+    // of the UiFactories need the models to instantiate their widgets.
     searchListModel = new AsyncListModel<StockQuote>(
         new DataSource<StockQuote>() {
           public void requestData(AsyncListModel<StockQuote> listModel) {
@@ -130,24 +117,16 @@
           }
         });

+    treeModel = new TransactionTreeViewModel(this,
+        favoritesListModel, transactionListListModelsByTicker);
+
     transactionListModel = new ListListModel<Transaction>();
     transactions = transactionListModel.getList();

-    // Create the favorites table.
- favoritesTable = new PagingTableListView<StockQuote>(favoritesListModel, 10); - favoritesTable.addColumn(Columns.tickerColumn, new TextHeader("ticker"));
-    favoritesTable.addColumn(Columns.priceColumn, new TextHeader("price"));
- favoritesTable.addColumn(Columns.changeColumn, new TextHeader("change")); - favoritesTable.addColumn(Columns.sharesColumn, new TextHeader("shares")); - favoritesTable.addColumn(Columns.dollarsColumn, new TextHeader("value")); - favoritesTable.addColumn(Columns.profitLossColumn, new TextHeader("profit"));
-    favoritesTable.addColumn(Columns.buyColumn);
-    favoritesTable.addColumn(Columns.sellColumn);
-
-    treeModel = new TransactionTreeViewModel(this,
-        favoritesListModel, transactionListListModelsByTicker);
-    transactionTree = new SideBySideTreeView(treeModel, null, 200, 200);
-
+    // Now create the UI.
+    RootLayoutPanel.get().add(binder.createAndBindUi(this));
+
+    // Hook up handlers to columns and the buy/sell popup.
Columns.favoriteColumn.setFieldUpdater(new FieldUpdater<StockQuote, Boolean>() {
       public void update(StockQuote object, Boolean value) {
         setFavorite(object.getTicker(), value);
@@ -172,81 +151,46 @@
       public void onClose(CloseEvent<PopupPanel> event) {
         Transaction t = buySellPopup.getTransaction();
         if (t != null) {
-          dataService.transact(t, new AsyncCallback<Transaction>() {
-            public void onFailure(Throwable caught) {
-              Window.alert("Error: " + caught.getMessage());
-            }
-
-            public void onSuccess(Transaction result) {
-              recordTransaction(result);
-              update();
-            }
-
-            /**
-             * Update transactions (list of all transactions),
-             * transactionTickers (set of all tickers involved in
-             * transactions), and transactionsByTicker (map from
-             * ticker to lists of transactions for that ticker).
-             */
-            private void recordTransaction(Transaction result) {
-              transactions.add(0, result);
-              String ticker = result.getTicker();
-
-              // Update the next level of the transaction tree
-              // for the given ticker
-              ListListModel<Transaction> t =
-                transactionListListModelsByTicker.get(ticker);
-              if (t == null) {
-                t = new ListListModel<Transaction>();
-                transactionListListModelsByTicker.put(ticker, t);
-              }
-              t.getList().add(result);
-            }
-          });
-       }
+          transact(t);
+        }
       }
     });

-    // Add components to the page.
-
-    Widget headerWidget = new HTML("<b>Stock Game</b>");
-
-    HorizontalPanel cashPanel = new HorizontalPanel();
-    cashPanel.add(new HTML("<b>Available cash:</b>"));
-    cashPanel.add(cashLabel);
-    HorizontalPanel netWorthPanel = new HorizontalPanel();
-    netWorthPanel.add(new HTML("<b>Net worth:</b>"));
-    netWorthPanel.add(netWorthLabel);
-    VerticalPanel moneyPanel = new VerticalPanel();
-    moneyPanel.add(cashPanel);
-    moneyPanel.add(netWorthPanel);
-
-    DockLayoutPanel westPanel = new DockLayoutPanel(Unit.PCT);
-    westPanel.addNorth(moneyPanel, 25.0);
-    westPanel.add(new HTML("<table>" +
-        "<tr><td>Dan Rice</td><td>$10000</td></tr>" +
-        "<tr><td>Joel Webber</td><td>$10000</td></tr>" +
-        "<tr><td>John Labanca</td><td>$10000</td></tr>" +
-        "</table>"));
-
-    DockLayoutPanel layoutPanel = new DockLayoutPanel(Unit.EM);
-    layoutPanel.addNorth(headerWidget, 4.0);
-    layoutPanel.addWest(westPanel, 15.0);
-    layoutPanel.addNorth(transactionTree, 18.0);
-
-    DockLayoutPanel innerLayoutPanel = new DockLayoutPanel(Unit.PCT);
-    this.queryWidget = new StockQueryWidget(searchListModel, this);
-    innerLayoutPanel.addWest(queryWidget, 60.0);
-
-    DockLayoutPanel favoritesLayoutPanel = new DockLayoutPanel(Unit.EM);
-    favoritesLayoutPanel.addNorth(new Label("Portfolio / Favorites"), 2.0);
-    favoritesLayoutPanel.add(new ScrollPanel(favoritesTable));
-    innerLayoutPanel.add(favoritesLayoutPanel);
-    layoutPanel.add(innerLayoutPanel);
-
-    RootLayoutPanel.get().add(layoutPanel);
-
-    update();
+    update();
+  }
+
+  public void transact(Transaction t) {
+    dataService.transact(t, new AsyncCallback<Transaction>() {
+      public void onFailure(Throwable caught) {
+        Window.alert("Error: " + caught.getMessage());
+      }
+
+      public void onSuccess(Transaction result) {
+        recordTransaction(result);
+        update();
+      }
+
+      /**
+       * Update transactions (list of all transactions),
+       * transactionTickers (set of all tickers involved in
+       * transactions), and transactionsByTicker (map from
+       * ticker to lists of transactions for that ticker).
+       */
+      private void recordTransaction(Transaction result) {
+        transactions.add(0, result);
+        String ticker = result.getTicker();
+
+        // Update the next level of the transaction tree
+        // for the given ticker
+        ListListModel<Transaction> t =
+          transactionListListModelsByTicker.get(ticker);
+        if (t == null) {
+          t = new ListListModel<Transaction>();
+          transactionListListModelsByTicker.put(ticker, t);
+        }
+        t.getList().add(result);
+      }
+    });
   }

   /**
@@ -345,7 +289,7 @@
    *
    * @param response the stock response
    */
-  private void processStockResponse(StockResponse response) {
+  public void processStockResponse(StockResponse response) {
     // Update the search list.
     StockQuoteList searchResults = response.getSearchResults();
     searchListModel.updateDataSize(response.getNumSearchResults(), true);
@@ -367,7 +311,7 @@
     updateTimer.schedule(UPDATE_DELAY);
   }

-  private void updateFavorites(StockResponse response) {
+  public void updateFavorites(StockResponse response) {
     // Update the favorites list.
     StockQuoteList favorites = response.getFavorites();
     favoritesListModel.updateDataSize(response.getNumFavorites(), true);
@@ -375,7 +319,7 @@
         favorites.size(), favorites);
   }

-  private void updateSector(StockResponse response) {
+  public void updateSector(StockResponse response) {
     // Update the sector list.
     StockQuoteList sectorList = response.getSector();
     if (sectorList != null) {
@@ -385,4 +329,19 @@
           sectorList.size(), sectorList);
     }
   }
-}
+
+  @UiFactory
+  FavoritesWidget createFavoritesWidget() {
+    return new FavoritesWidget(favoritesListModel);
+  }
+
+  @UiFactory
+  StockQueryWidget createQueryWidget() {
+    return new StockQueryWidget(searchListModel, this);
+  }
+
+  @UiFactory
+  SideBySideTreeView createTransactionTree() {
+    return new SideBySideTreeView(treeModel, null, 200, 200);
+  }
+}
=======================================
--- /trunk/bikeshed/war/Stocks.css      Fri Mar  5 07:05:48 2010
+++ /trunk/bikeshed/war/Stocks.css      Thu Mar 11 08:39:56 2010
@@ -1,4 +1,16 @@
-/** Add css rules here for your application. */
+body {
+  background: url(bg.png) repeat-x;
+  background-color: rgb(216, 220, 224);
+  color: black;
+  margin: 8px;
+  margin-top: 3px;
+}
+
+body, table {
+  font-family: Helvetica Neue Light, Helvetica, Arial, sans-serif; */
+  font-weight: light;
+  font-size: small;
+}

 div.gwt-sstree-column {
   overflow-y: scroll;
@@ -7,7 +19,6 @@
 }

 div.gwt-sstree {
-  border: 2px solid black;
 }

 div.gwt-sstree-selectedItem {
@@ -53,3 +64,19 @@
 #closeButton {
   margin: 15px 6px 6px;
 }
+
+.gwt-DialogBox {
+  border: 8px solid white;
+  border-right: 11px solid white;
+  border-bottom: 11px solid white;
+  -webkit-border-image: url(blueborder.png) 8 11 11 8 round round;
+  -gecko-border-image: url(blueborder.png) 8 11 11 8 round round;
+}
+
+.gwt-DialogBox .Caption {
+  font-weight: light;
+  font-size: 12pt;
+  text-align: center;
+  margin-bottom: 0.5em;
+  border-bottom: 1px solid #ccc;
+}

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to