Revision: 7717
Author: [email protected]
Date: Fri Mar 12 06:22:00 2010
Log: Fix bugs in stock sample app

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

Modified:
/trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java

=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java Thu Mar 11 11:11:10 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java Fri Mar 12 06:22:00 2010
@@ -35,7 +35,7 @@
  */
 public class BuySellPopup extends DialogBox {

-
+  // Row numbers for popup fields
   private static final int TICKER = 0;
   private static final int NAME = 1;
   private static final int PRICE = 2;
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java Thu Mar 11 03:44:25 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java Fri Mar 12 06:22:00 2010
@@ -24,6 +24,9 @@

   @Override
   public void render(String value, StringBuilder sb) {
+    if (value == null || value.length() == 0) {
+      return;
+    }
     sb.append("<span style=\"color:");
     if (value.charAt(0) == '-') {
       sb.append("red\">");
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java Thu Mar 11 09:45:33 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java Fri Mar 12 06:22:00 2010
@@ -25,24 +25,25 @@
  */
 public class HighlightingTextCell extends Cell<String> {

-  private String highlightRegex;
+  private RegExp highlightRegex;

   @Override
   public void render(String value, StringBuilder sb) {
- sb.append("<div style='overflow:hidden; white-space:nowrap; text-overflow:ellipsis;'>");
-    if (highlightRegex == null || highlightRegex.length() == 0) {
+ // sb.append("<div style='overflow:hidden; white-space:nowrap; text-overflow:ellipsis;'>");
+    sb.append("<div>");
+    if (highlightRegex == null) {
       sb.append(value);
       sb.append("</div>");
       return;
     }

-    RegExp regExp = RegExp.compile(highlightRegex, "gi");
     int fromIndex = 0;
     int length = value.length();
     MatchResult result;
+    highlightRegex.setLastIndex(0);
     while (fromIndex < length) {
       // Find the next match of the highlight regex
-      result = regExp.exec(value);
+      result = highlightRegex.exec(value);
       if (result == null) {
         // No more matches
         break;
@@ -58,7 +59,7 @@
       sb.append("</b>");
       // Skip past the matched string
       fromIndex = index + match.length();
-      regExp.setLastIndex(fromIndex);
+      highlightRegex.setLastIndex(fromIndex);
     }
     // Append the tail of the string
     if (fromIndex < length) {
@@ -67,7 +68,11 @@
     sb.append("</div>");
   }

-  public void setHighlightRegex(String highlightRegex) {
-    this.highlightRegex = highlightRegex;
+  public void setHighlightRegex(String highlightText) {
+    if (highlightText != null && highlightText.length() > 0) {
+      highlightRegex = RegExp.compile(highlightText, "gi");
+    } else {
+      highlightRegex = null;
+    }
   }
 }
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java Thu Mar 11 11:11:10 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java Fri Mar 12 06:22:00 2010
@@ -78,7 +78,7 @@

   private String normalize(String input) {
     String output = input;
-    output = output.replaceAll("\\|+", "|");
+    output = output.replaceAll("\\|+", " ");
     output = output.replaceAll("^[\\| ]+", "");
     output = output.replaceAll("[\\| ]+$", "");
     output = output.replaceAll("[ ]+", "|");
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java Thu Mar 11 09:45:33 2010 +++ /trunk/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java Fri Mar 12 06:22:00 2010
@@ -299,7 +299,7 @@
       }
     }

-    return new Result(toRet, symbols.size());
+    return new Result(toRet, toRet.size());
   }

   // If a query is alpha-only ([A-Za-z]+), return stocks for which:
@@ -339,7 +339,9 @@
       }

       // (2)
-      getTickersByNameRegex(pattern, symbols);
+      if (query.length() > 2) {
+        getTickersByNameRegex(pattern, symbols);
+      }
     }

     return getQuotes(symbols, searchRange);

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

Reply via email to