Wednesday 14 September 2011

GWT Tut - gc

Development : in the "edit - refresh - view" cycle.

1.add the widgets to specific [div]
RootPanel rootPanel = RootPanel.get("stockList");
rootPanel.add(mainPanel);

2.Event
*Listen for mouse events on the Add button.
addStockButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {

3.Alert dialog box
Window.alert("'" + stockcode + "' not a valid code.");

4.Refer to widget value
String stockcode=newSymbolTextBox.getText().toUpperCase().trim();

5.Widget inside widget
Button removeStockButton = new Button("x");
stocksFlexTable.setWidget(row, 3, removeStockButton);

6.Timer
*Setup timer to refresh list automatically.
Timer refreshTimer = new Timer() {@Override
public void run() {

7.Generate random stock prices.
double price = Random.nextDouble() * MAX_PRICE;

8.From Double to String
String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice());

9.Last update date and time
lastUpdatedLabel.setText("Last update : "+ DateTimeFormat.getShortDateTimeFormat().format(new Date()));

10.Debug
Run as debug. Resume, Step over, Step into.

11.Apply css style
stocksFlexTable.getRowFormatter().addStyleName(0, "watchListHeader");
stocksFlexTable.getCellFormatter().addStyleName(row, 1, "watchListNumericColumn");

12.Creat sec. styles dependent on primary style
removeStockButton.addStyleDependentName("remove");

13.Dynamic style
Label changeWidget = (Label)stocksFlexTable.getWidget(row, 2);
changeWidget.setText...
+if (price.getChangePercent() < -0.1f) +{changeStyleName = "negativeChange"; changeWidget.setStyleName(changeStyleName) 14. Generate stock data in JSON(Server). +PrintWriter out = resp.getWriter(); +out.println('['); out.println(" {"); out.print(" \"symbol\": \""); C1-Use JavaScript Native Interface (JSNI) and GWT overlay types to work with the JSON data. class StockData extends JavaScriptObject {... JSNI methods to get stock data. public final native String getSymbol() C2-Make HTTP call to retrieve the JSON data(Client). private static final String JSON_URL = GWT.getModuleBaseURL() + "stockPrices?q="; use the HTTP client classes in the com.google.gwt.http.client package [inherits name="com.google.gwt.http.HTTP" />

No comments:

Post a Comment