Methods Summary |
---|
private void | addChildren(com.google.gwt.user.client.ui.TreeItem treeItem, com.google.gwt.json.client.JSONValue jsonValue)
JSONArray jsonArray;
JSONObject jsonObject;
JSONString jsonString;
if ((jsonArray = jsonValue.isArray()) != null) {
for (int i = 0; i < jsonArray.size(); ++i) {
TreeItem child = treeItem.addItem(getChildText("["
+ Integer.toString(i) + "]"));
addChildren(child, jsonArray.get(i));
}
} else if ((jsonObject = jsonValue.isObject()) != null) {
Set keys = jsonObject.keySet();
for (Iterator iter = keys.iterator(); iter.hasNext();) {
String key = (String) iter.next();
TreeItem child = treeItem.addItem(getChildText(key));
addChildren(child, jsonObject.get(key));
}
} else if ((jsonString = jsonValue.isString()) != null) {
// Use stringValue instead of toString() because we don't want escaping
treeItem.addItem(jsonString.stringValue());
} else {
// JSONBoolean, JSONNumber, and JSONNull work well with toString().
treeItem.addItem(getChildText(jsonValue.toString()));
}
|
private void | displayError(java.lang.String responseText)
jsonTree.removeItems();
jsonTree.setVisible(true);
TreeItem treeItem = jsonTree.addItem("Failed to parse JSON response");
treeItem.addItem(responseText);
treeItem.setStyleName("JSON-JSONResponseObject");
treeItem.setState(true);
|
private void | displayJSONObject(com.google.gwt.json.client.JSONValue jsonValue)
jsonTree.removeItems();
jsonTree.setVisible(true);
TreeItem treeItem = jsonTree.addItem("JSON Response");
addChildren(treeItem, jsonValue);
treeItem.setStyleName("JSON-JSONResponseObject");
treeItem.setState(true);
|
private void | doFetchURL()
searchButton.setText(SEARCH_BUTTON_WAITING_TEXT);
if (!HTTPRequest.asyncGet(DEFAULT_SEARCH_URL, new JSONResponseTextHandler())) {
// Reset the caption.
//
searchButton.setText(SEARCH_BUTTON_DEFAULT_TEXT);
}
|
private java.lang.String | getChildText(java.lang.String text)
return "<span style='white-space:normal'>" + text + "</span>";
|
private void | initializeMainForm()Initialize the main form's layout and content.
searchButton.setStyleName("JSON-SearchButton");
searchButton.setText(SEARCH_BUTTON_DEFAULT_TEXT);
searchButton.addClickListener(new SearchButtonClickListener());
// Avoids showing an "empty" cell
jsonTree.setVisible(false);
// Find out where the host page wants the button.
//
RootPanel searchButtonSlot = RootPanel.get("search");
if (searchButtonSlot == null) {
Window.alert("Please define a container element whose id is 'search'");
return;
}
// Find out where the host page wants the tree view.
//
RootPanel treeViewSlot = RootPanel.get("tree");
if (treeViewSlot == null) {
Window.alert("Please define a container element whose id is 'tree'");
return;
}
// Add both widgets.
//
searchButtonSlot.add(searchButton);
treeViewSlot.add(jsonTree);
|
public void | onModuleLoad()Entry point for this simple application. Currently, we build the
application's form and wait for events.
initializeMainForm();
|