Open GoogleCodeExporter opened 9 years ago
When the new tutorial (I don't have a link for it yet) is published this will
be resolved because it uses JSNI and
overlay types instead. The new updateTable method is as follows.
/**
* Update the Price and Change fields all the rows in the stock table.
*
* @param prices Stock data for all rows.
*
*/
private void updateTable(JsArray<StockData> prices) {
for (int i = 0; i < prices.length(); i++) {
updateTable(prices.get(i));
}
// Display timestamp showing last refresh.
lastUpdatedLabel.setText("Last update : "
+ DateTimeFormat.getMediumDateTimeFormat().format(new Date()));
// Clear any errors.
errorMsgLabel.setVisible(false);
}
/**
* Update a single row in the stock table.
*
* @param price Stock data for a single row.
*/
private void updateTable(StockData price) {
// Make sure the stock is still in the stock table.
if (!stocks.contains(price.getSymbol())) {
return;
}
int row = stocks.indexOf(price.getSymbol()) + 1;
// Format the data in the Price and Change fields.
String priceText = NumberFormat.getFormat("#,##0.00").format(
price.getPrice());
NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
String changeText = changeFormat.format(price.getChange());
String changePercentText = changeFormat.format(price.getChangePercent());
// Populate the Price and Change fields with new data.
stocksFlexTable.setText(row, 1, priceText);
Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2);
changeWidget.setText(changeText + " (" + changePercentText + "%)");
// Change the color of text in the Change field based on its value.
String changeStyleName = "noChange";
if (price.getChangePercent() < -0.1f) {
changeStyleName = "negativeChange";
} else if (price.getChangePercent() > 0.1f) {
changeStyleName = "positiveChange";
}
changeWidget.setStyleName(changeStyleName);
}
Original comment by msinclai...@gmail.com
on 9 Dec 2008 at 1:37
Original issue reported on code.google.com by
reuben.sivan
on 27 Nov 2008 at 5:00