Fix bugs in stock sample app
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7717 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java
index ed1538c..253a3a4 100644
--- a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java
+++ b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/BuySellPopup.java
@@ -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;
diff --git a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java
index 8aa7f65..4020467 100644
--- a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java
+++ b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/ChangeCell.java
@@ -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\">");
diff --git a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java
index 0ed535b..38ec5c2 100644
--- a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java
+++ b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/HighlightingTextCell.java
@@ -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;
+ }
}
}
diff --git a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java
index 9636868..66b4e49 100644
--- a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java
+++ b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/client/StockQueryWidget.java
@@ -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("[ ]+", "|");
diff --git a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java
index 600565f..95b47f6 100644
--- a/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java
+++ b/bikeshed/src/com/google/gwt/bikeshed/sample/stocks/server/StockServiceImpl.java
@@ -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);