public void applyAlphaMapMaterial(Primitive primitive) { JSONObject uniforms = new JSONObject(); uniforms.put("image", new JSONString(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color.jpg")); uniforms.put("channel", new JSONString("r")); JSONObject alphaMaterial = new JSONObject(); alphaMaterial.put("type", new JSONString("AlphaMap")); alphaMaterial.put("uniforms", uniforms); JSONObject materials = new JSONObject(); materials.put("alphaMaterial", alphaMaterial); JSONObject components = new JSONObject(); components.put("diffuse", new JSONString("vec3(1.0)")); components.put("alpha", new JSONString("alphaMaterial.alpha")); JSONObject fabric = new JSONObject(); fabric.put("materials", materials); fabric.put("components", components); MaterialOptions materialOptions = new MaterialOptions(); materialOptions.fabric = JsonUtils.safeEval(fabric.toString()); primitive.appearance.material = new Material(materialOptions); }
public void applyWaterMaterial(Primitive primitive) { JSONObject uniforms = new JSONObject(); uniforms.put("specularMap", new JSONString(GWT.getModuleBaseURL() + "images/earthspec1k.jpg")); uniforms.put("normalMap", new JSONString(GWT.getModuleBaseURL() + "images/waterNormals.jpg")); uniforms.put("frequency", new JSONNumber(10000.0)); uniforms.put("animationSpeed", new JSONNumber(0.01)); uniforms.put("amplitude", new JSONNumber(1.0)); JSONObject fabric = new JSONObject(); fabric.put("type", new JSONString("Water")); fabric.put("uniforms", uniforms); MaterialOptions materialOptions = new MaterialOptions(); materialOptions.fabric = JsonUtils.safeEval(fabric.toString()); primitive.appearance.material = new Material(materialOptions); }
private void draw() { JsArrayMixed dataArray = JsonUtils.unsafeEval("[['Mon',20,28,38,45],['Tue',31,38,55,66],['Wed',50,55,77,80],['Thu',77,77,66,50],['Fri',68,66,22,15]]"); // Prepare the data DataTable dataTable = ChartHelper.arrayToDataTable(dataArray, true); // Set options CandlestickChartOptions options = CandlestickChartOptions.create(); BackgroundColor bgColor = BackgroundColor.create(); bgColor.setStroke("#2196f3"); bgColor.setFill("#90caf9"); bgColor.setStrokeWidth(2); options.setLegend(Legend.create(LegendPosition.NONE)); options.setFallingColor(bgColor); options.setRisingColor(bgColor); // Draw the chart chart.draw(dataTable, options); }
private void draw() { JsArrayMixed dataArray = JsonUtils .unsafeEval("[['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua Guinea', 'Rwanda', 'Average'],['2004/05', 165, 938, 522, 998, 450, 614.6],['2005/06', 135, 1120, 599, 1268, 288, 682],['2006/07', 157, 1167, 587, 807, 397, 623],['2007/08', 139, 1110, 615, 968, 215, 609.4],['2008/09', 136, 691, 629, 1026, 366, 569.6]]"); // Prepare the data DataTable dataTable = ChartHelper.arrayToDataTable(dataArray); // Set options ComboChartOptions options = ComboChartOptions.create(); options.setFontName("Tahoma"); options.setTitle("Monthly Coffee Production by Country"); options.setHAxis(HAxis.create("Cups")); options.setVAxis(VAxis.create("Month")); options.setSeriesType(SeriesType.BARS); ComboChartSeries series = ComboChartSeries.create(); series.setType(SeriesType.LINE); options.setSeries(5, series); // Draw the chart chart.draw(dataTable, options); }
@SuppressWarnings("unchecked") private JsoArray<Entry> getSavedItems() { Storage storage = getStorage(); if (storage != null) { String data = storage.getItem(SAVED_ITEMS); JsoArray<Entry> list = null; if (data != null) { list = JsonUtils.safeEval(data); } else { list = (JsoArray<Entry>) JavaScriptObject.createArray(); } return list; } else { return (JsoArray<Entry>) JavaScriptObject.createArray(); } }
/** Array of keys is accessible through the JSO. */ public void testDynamicJsArray_length() { DynamicJsArray arr = JsonUtils.safeEval("[1, \"a\", false]"); assertEquals(3, arr.length()); // Length can be increased arbitrarily, but items default to null. arr.setLength(6); assertEquals(6, arr.length()); assertNull(arr.get(3)); // Getting a non-existent element returns null. assertNull(arr.get(10)); assertNull(arr.typeofIndex(10)); // Array can be shortened, trimming items from the end. arr.setLength(1); assertEquals(1, arr.length()); assertEquals(1, arr.getInteger(0)); assertNull(arr.get(1)); }
/** shift() pops a value off the beginning of the array. */ public void testDynamicJsArray_shift() { DynamicJsArray arr = JsonUtils.safeEval("[false, 1.2, 12, \"a\", {\"a\":\"b\"}]"); assertEquals(5, arr.length()); assertFalse(arr.shiftBoolean()); assertEquals(4, arr.length()); assertEquals(1.2, arr.shiftDouble()); assertEquals(3, arr.length()); assertEquals(12, arr.shiftInteger()); assertEquals(2, arr.length()); assertEquals("a", arr.shiftString()); assertEquals(1, arr.length()); DynamicJso jso = arr.shift(); assertEquals(0, arr.length()); assertEquals(1, jso.keys().length()); assertEquals("b", jso.getString("a")); // With nothing remaining, shift() returns null. assertNull(arr.shift()); }
/** The type of data stored in the array is accessible as expected. */ public void testDynamicJsArray_typeof() { DynamicJsArray arr = JsonUtils.safeEval("[1.2, 12, \"foo\", false, [\"a\"], {\"fa\":\"bar\"}]"); assertEquals(JsType.NUMBER, arr.typeofIndex(0)); assertEquals(JsType.INTEGER, arr.typeofIndex(1)); assertEquals(JsType.STRING, arr.typeofIndex(2)); assertEquals(JsType.BOOLEAN, arr.typeofIndex(3)); assertEquals(JsType.ARRAY, arr.typeofIndex(4)); assertEquals(JsType.OBJECT, arr.typeofIndex(5)); }
/** Array of keys is accessible through the JSO. */ public void testDynamicJso_keys() { DynamicJso jso = JsonUtils.safeEval("{\"a\":{\"foo\":\"bar\"}}"); assertEquals(1, jso.keys().length()); assertEquals("a", jso.keys().get(0)); jso = JavaScriptObject.createObject().cast(); jso.set("a", true); jso.set("b", false); jso.set("c", 123); assertEquals(3, jso.keys().length()); assertEquals("a", jso.keys().get(0)); assertEquals("b", jso.keys().get(1)); assertEquals("c", jso.keys().get(2)); // Getting a non-existent key return null assertNull(jso.get("zzz")); assertNull(jso.typeofKey("zzz")); }
@Override @SuppressWarnings("unchecked") public <C extends Collection<T>> C deserializeAsCollection(Class<C> collectionType, String response, DeserializationContext context) { JsArray<T> jsArray = JsonUtils.safeEval(response); if (collectionType.equals(List.class) || collectionType.equals(Collection.class)) { return (C) new JsArrayList(jsArray); } else { C col = context.getContainerInstance(collectionType); for (int i = 0; i < jsArray.length(); i++) { T t = jsArray.get(i); col.add(t); } return col; } }
protected void test(String json, String sql, JsArrayMixed args, String msg) throws Throwable { RootPanel.get().getElement().setAttribute("id", "rqb"); try { if (json != null) { conf = (JsConfiguration) JsonUtils.unsafeEval(json); addHandlers(conf); } builder = RedQueryBuilder.configure(conf, sql, args); assertTrue(builder != null); if (msg != null) { fail("Was expecting the error message: " + msg); } } catch (Throwable th) { if (msg != null) { assertEquals(msg, th.getMessage()); } else { throw th; } } }
private void getRestAreas() { String jsonString = AppBundle.INSTANCE.restAreaData().getText(); RestAreaFeed restAreas = JsonUtils.safeEval(jsonString); RestAreaItem item; for (int i = 0; i < restAreas.getRestAreas().length(); i++){ item = new RestAreaItem(); item.setId(i); item.setRoute(restAreas.getRestAreas().get(i).getRoute()); item.setLocation(restAreas.getRestAreas().get(i).getLocation()); item.setDescription(restAreas.getRestAreas().get(i).getDescription()); item.setMilepost(restAreas.getRestAreas().get(i).getMilepost()); item.setDirection(restAreas.getRestAreas().get(i).getDirection()); item.setLatitude(restAreas.getRestAreas().get(i).getLatitude()); item.setLongitude(restAreas.getRestAreas().get(i).getLongitude()); item.setNotes(restAreas.getRestAreas().get(i).getNotes()); item.setHasDump(restAreas.getRestAreas().get(i).hasDump()); item.setOpen(restAreas.getRestAreas().get(i).isOpen()); item.setAmenities(restAreas.getRestAreas().get(i).getAmenities()); restAreaItems.add(item); } drawRestAreasLayer(); }
public void onSubmit(String results) { initForm(); JavaScriptObject jsResponse = JsonUtils.safeEval(results); if (jsResponse != null) { JSONObject response = new JSONObject(jsResponse); if (response.get("document") != null) { JSONObject document = response.get("document").isObject(); DocumentData data = new DocumentData(document.get("fileName").isString().stringValue(), new Double(document.get("size").isNumber().doubleValue()).longValue(), null); data.setContentId(document.get("contentId").isString().stringValue()); setValue(data, true); } else if (response.get("error").isNull() != null) { setValue(null, true); } } }
private List<Double> getNumberArrayAttribute(SliderOption option, List<Double> defaultValue) { // Get array attribute JsArrayNumber array = null; if (isAttached()) { array = getNumberArrayAttribute(getElement(), option.getName()); } else { String value = attributeMixin.getAttribute(option.getDataAttribute()); if (value != null && !value.isEmpty()) { array = JsonUtils.safeEval(value); } } // Attribute not set if (array == null) { return defaultValue; } // Put array to list List<Double> list = new ArrayList<Double>(array.length()); for (int i = 0; i < array.length(); i++) { list.add(array.get(i)); } return list; }
private List<String> getStringArrayAttribute(SliderOption option, List<String> defaultValue) { // Get array attribute JsArrayString array = null; if (isAttached()) { array = getStringArrayAttribute(getElement(), option.getName()); } else { String value = attributeMixin.getAttribute(option.getDataAttribute()); if (value != null && !value.isEmpty()) { array = JsonUtils.safeEval(value); } } // Attribute not set if (array == null) { return defaultValue; } // Put array to list List<String> list = new ArrayList<String>(array.length()); for (int i = 0; i < array.length(); i++) { list.add(array.get(i)); } return list; }
public void login(String userName, String password) { // if(true) { // welcome.hideProgressImage(); // welcome.hideDialog(); // SessionJSO session = JsonUtils.safeEval(SampleDataProvider.INSTANCE.session().getText()); // vehicleTool.setSession(session); // vehicleTool.onRelease(); // // return; // } sgfServiceAsync.login(userName, password, new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { messageDialogBuilder.createError("Error", UISgfMessages.INSTANCE.authError()).show(); welcome.hideProgressImage(); } @Override public void onSuccess(String sessionJson) { welcome.hideProgressImage(); welcome.hideDialog(); SessionJSO session = JsonUtils.safeEval(sessionJson); vehicleTool.setSession(session); vehicleTool.onRelease(); } }); }
private PointRegisterJSO getSamplePoint(VehicleJSO vehicleJSO) { String data = SampleDataProvider.INSTANCE.lastPointRegister() .getText(); PointRegisterListResponseJSO pointRegisterResponse = JsonUtils .safeEval(data); PointRegisterJSO point = pointRegisterResponse .getPointRegisterListEmbededJSO().getPointRegister()[0]; return point; }
private void getRequestRegisteredPoint(final VehicleJSO vehicle, final String startDate, final String endDate) { autoMessageBox.setProgressStatusMessage(UISgfMessages.INSTANCE.getGPSData()); RestClient.create(SGFRegisteredPointService.class, SGFServiceInfo.getURL(), new RemoteCallback<String>() { @Override public void callback(String pointRegisterListResponseJson) { PointRegisterListResponseJSO pointRegisterResponse = JsonUtils .safeEval(pointRegisterListResponseJson); PointRegisterJSO[] pointRegisters = pointRegisterResponse .getPointRegisterListEmbededJSO().getPointRegister(); List<PointRegisterJSO> points = Arrays.asList(pointRegisters); if(points.isEmpty()) { messageDialogBuilder.createInfo(UIMessages.INSTANCE.edtAlertDialogTitle(), UISgfMessages.INSTANCE.gpsDataNotFound()).show(); return; } createRouteLayer(vehicle, startDate, points); autoMessageBox.hide(); } }, new RestErrorCallback() { @Override public boolean error(Request message, Throwable throwable) { autoMessageBox.hide(); messageDialogBuilder.createInfo(UISgfMessages.INSTANCE.errorDetected(), throwable.getMessage()).show(); return false; } }, Response.SC_OK).getRegisteredPoints(session.getToken(), vehicle.getId(), startDate, endDate, REGISTERED_POINTS_TO_LOAD, "date,desc"); }
private void getSamplePoints(VehicleJSO vehicleJSO, String startDate, String endDate) { String plate = ""; if ("29085257".equals(vehicleJSO.getPlate())) { plate = SampleDataProvider.INSTANCE.list20RegisterPoint().getText(); } else if ("39213844".equals(vehicleJSO.getPlate())) { plate = SampleDataProvider.INSTANCE.list500RegisterPoint() .getText(); } PointRegisterListResponseJSO pointRegisterResponse = JsonUtils .safeEval(plate); PointRegisterJSO[] pointRegisters = pointRegisterResponse .getPointRegisterListEmbededJSO().getPointRegister(); List<PointRegisterJSO> points = Arrays.asList(pointRegisters); if (points.size() == 0) { messageDialogBuilder .createInfo("Atención", "No se encuentran datos registrados para la fecha especificada") .show(); return; } createRouteLayer(vehicleJSO, startDate, points); }
private void loadVehicles(String token, int companyId) { autoMessageBox = new ProgressBarDialog(false, UIMessages.INSTANCE.processing()); autoMessageBox.show(); RestClient.create(SGFVehicleService.class, SGFServiceInfo.getURL(), new RemoteCallback<String>() { @Override public void callback(String vehicleListResponseJson) { VehicleListResponseJSO vehicleListResponse = JsonUtils .safeEval(vehicleListResponseJson); List<VehicleJSO> vehicles = Arrays .asList(vehicleListResponse .getVehicleListEmbededJSO() .getVehicles()); vehicleDialog.setVehicle(vehicles); autoMessageBox.hide(); vehicleDialog.show(); } }, new RestErrorCallback() { @Override public boolean error(Request message, Throwable throwable) { autoMessageBox.hide(); messageDialogBuilder.createInfo( UISgfMessages.INSTANCE.errorDetected(), throwable.getMessage()).show(); return false; } }, Response.SC_OK).get(token, companyId, 100, "id"); }
public <V> V convert(Object object, Class<V> clazz) { if (object == null) { return null; } else if (object.getClass().equals(clazz)) { return (V) object; } else if (object instanceof String) { return read((String) object, clazz); } else if (object instanceof Collection) { Collection<?> objects = (Collection<?>) object; if (JavaScriptObject.class.equals(clazz)) { JsObjectArray<JavaScriptObject> jsArray = JsObjectArray.create(); for (Object o : objects) { jsArray.add(convert(o, JavaScriptObject.class)); } return (V) jsArray; } } else if (object instanceof JsonBuilder) { JsonBuilder jsonBuilder = (JsonBuilder) object; if (JavaScriptObject.class.equals(clazz)) { return jsonBuilder.getDataImpl(); } else { return convert(jsonBuilder.getDataImpl(), clazz); } } else if (object instanceof JavaScriptObject) { JavaScriptObject jso = (JavaScriptObject) object; if (JSONObject.class.equals(clazz)) { return (V) new JSONObject(jso); } else { return read(JsonUtils.stringify(jso), clazz); } } else if (clazz.equals(JavaScriptObject.class) && mappers.containsKey(object.getClass())) { return (V) JsonUtils.safeEval(write(object)); } throw new UnsupportedOperationException("Conversion not supported: object=" + String.valueOf(object) + ",clazz=" + String.valueOf(clazz)); }
public void applyImageMaterial(Primitive primitive) { JSONObject uniforms = new JSONObject(); uniforms.put("image", new JSONString(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color.jpg")); JSONObject fabric = new JSONObject(); fabric.put("type", new JSONString("Image")); fabric.put("uniforms", uniforms); MaterialOptions materialOptions = new MaterialOptions(); materialOptions.fabric = JsonUtils.safeEval(fabric.toString()); primitive.appearance.material = new Material(materialOptions); }
public void applyDiffuseMaterial(Primitive primitive) { JSONObject uniforms = new JSONObject(); uniforms.put("image", new JSONString(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color.jpg")); JSONObject fabric = new JSONObject(); fabric.put("type", new JSONString("DiffuseMap")); fabric.put("uniforms", uniforms); MaterialOptions materialOptions = new MaterialOptions(); materialOptions.fabric = JsonUtils.safeEval(fabric.toString()); primitive.appearance.material = new Material(materialOptions); }
public void applySpecularMapMaterial(Primitive primitive) { JSONObject uniforms = new JSONObject(); uniforms.put("image", new JSONString(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color.jpg")); uniforms.put("channel", new JSONString("r")); JSONObject fabric = new JSONObject(); fabric.put("type", new JSONString("SpecularMap")); fabric.put("uniforms", uniforms); MaterialOptions materialOptions = new MaterialOptions(); materialOptions.fabric = JsonUtils.safeEval(fabric.toString()); primitive.appearance.material = new Material(materialOptions); }
public static JsArrayIterable<Task> getTasks() { if (tasks == null && localStorage != null) { String tasksJson = localStorage.getItem("tasks"); if (tasksJson != null) { tasks = JsonUtils.<JsArrayIterable<Task>>safeEval(tasksJson); } } return tasks; }
public static void onTasksChanged() { if (localStorage != null) { if (tasks != null) { localStorage.setItem("tasks", JsonUtils.stringify(tasks)); } else { localStorage.removeItem("tasks"); } } }
private FileUploadResponse parseResponse(String results) { if (results != null) { // json is wrapped in <pre/> tag String resultConent = results.replaceAll("\\<[^>]*>", ""); if (JsonUtils.safeToEval(resultConent)) { return JsonUtils.<FileUploadResponseJso> safeEval(resultConent); } } return new FileUploadResponseDto(false, results); }
public void testRead() { library.fetch(); Ajax.Settings syncArgs = NetworkSyncStrategy.get().getSyncArgs(); assertEquals("/library", syncArgs.getUrl()); assertEquals("GET", syncArgs.getType()); assertEquals("json", syncArgs.getDataType()); String data = JsonUtils.stringify((JavaScriptObject) syncArgs.getData()); assertEquals("{}", data); // making sure it's an empty JSON string }
public void testPassingData() { library.fetch(O("data", O("a", "a", "one", 1))); Ajax.Settings syncArgs = NetworkSyncStrategy.get().getSyncArgs(); assertEquals("/library", syncArgs.getUrl()); String data = JsonUtils.stringify((JavaScriptObject) syncArgs.getData()); Options dataOptions = O(JSONParser.parseStrict(data)).get("data"); //TODO: Currently test is not passing... need to finish testing the whole Sync class //assertEquals("a", dataOptions.get("a")); //assertEquals(1, dataOptions.get("one")); }
public static JSONValue parse(String token) { try { if (JsonUtils.safeToEval(token)) { JSONValue jsonv = JSONParser.parseStrict(token); return jsonv; } } catch (Exception ex) { LOG.log(Level.SEVERE, token, ex); } return null; }
public static <T extends JavaScriptObject> void downloadJson(String url, final DownloadListener<T> listener, int timeoutMs) { downloadData(url, "application/json", listener, new DataConverter<T>() { @Override public T convert(String data) { return JsonUtils.<T> safeEval(data); } }, timeoutMs); }
/** Values stored in JSON strings are accessible through the JSO. */ public void testDynamicJsArray_getters() { DynamicJsArray arr = JsonUtils.safeEval("[\"a\"]"); assertEquals("a", arr.getString(0)); assertEquals(JsType.STRING, arr.typeofIndex(0)); arr = JsonUtils.safeEval("[42]"); assertEquals(42, arr.getInteger(0)); assertEquals(JsType.INTEGER, arr.typeofIndex(0)); arr = JsonUtils.safeEval("[1.2]"); assertEquals(1.2, arr.getDouble(0)); assertEquals(JsType.NUMBER, arr.typeofIndex(0)); arr = JsonUtils.safeEval("[false]"); assertFalse(arr.getBoolean(0)); assertEquals(JsType.BOOLEAN, arr.typeofIndex(0)); arr = JsonUtils.safeEval("[[1,2,3]]"); assertEquals(1, arr.length()); DynamicJsArray inner = arr.get(0); assertEquals(1, inner.getInteger(0)); assertEquals(2, inner.getInteger(1)); assertEquals(3, inner.getInteger(2)); assertEquals(JsType.ARRAY, arr.typeofIndex(0)); arr = JsonUtils.safeEval("[{\"foo\":\"bar\"}]"); assertEquals("bar", arr.<DynamicJso>get(0).getString("foo")); assertEquals(JsType.OBJECT, arr.typeofIndex(0)); }
/** Values stored in JSON strings are accessible through the JSO. */ public void testDynamicJso_getters() { DynamicJso jso = JsonUtils.safeEval("{\"a\":\"b\"}"); assertEquals("b", jso.getString("a")); assertEquals(JsType.STRING, jso.typeofKey("a")); jso = JsonUtils.safeEval("{\"a\":42}"); assertEquals(42, jso.getInteger("a")); assertEquals(JsType.INTEGER, jso.typeofKey("a")); jso = JsonUtils.safeEval("{\"a\":1.2}"); assertEquals(1.2, jso.getDouble("a")); assertEquals(JsType.NUMBER, jso.typeofKey("a")); jso = JsonUtils.safeEval("{\"a\":false}"); assertFalse(jso.getBoolean("a")); assertEquals(JsType.BOOLEAN, jso.typeofKey("a")); jso = JsonUtils.safeEval("{\"a\":[1,2,3]}"); JsArrayNumber arr = jso.get("a"); assertEquals(1.0, arr.get(0)); assertEquals(2.0, arr.get(1)); assertEquals(3.0, arr.get(2)); assertEquals(JsType.ARRAY, jso.typeofKey("a")); jso = JsonUtils.safeEval("{\"a\":{\"foo\":\"bar\"}}"); assertEquals("bar", jso.<DynamicJso>get("a").getString("foo")); assertEquals(JsType.OBJECT, jso.typeofKey("a")); }
/** The type of data stored in the object is accessible as expected. */ public void testDynamicJso_typeof() { DynamicJso jso = JsonUtils.safeEval( "{\"a\":1.2,\"b\":12,\"c\":\"foo\",\"d\":false,\"e\":[\"a\"],\"f\":{\"fa\":\"bar\"}}"); assertEquals(JsType.NUMBER, jso.typeofKey("a")); assertEquals(JsType.INTEGER, jso.typeofKey("b")); assertEquals(JsType.STRING, jso.typeofKey("c")); assertEquals(JsType.BOOLEAN, jso.typeofKey("d")); assertEquals(JsType.ARRAY, jso.typeofKey("e")); assertEquals(JsType.OBJECT, jso.typeofKey("f")); assertEquals(JsType.STRING, jso.<DynamicJso>get("f").typeofKey("fa")); }
private static ErrorCase getErrorMessage(ApiResponse response) { // This requires a try-catch because there is no way to proactively check // that the JSON is both present and valid without just trying to parse it. try { DynamicJso jso = JsonUtils.safeEval(response.getBodyAsString()); if (jso.get("error") != null) { return ErrorCase.forJsonString(response.getBodyAsString()); } } catch (IllegalArgumentException e) { // Not valid json, definitely not an error payload. } return null; }
/** * Entry point for the formatter. * * @param destination Destination GWT object where the results will be placed * @param jsonString String to format * @param linkFactory Which links factory should be used when generating links and navigation * menus. * @throws JsonFormatException when parsing the Json causes an error */ public static void prettify( ApiService service, Panel destination, String jsonString, PrettifierLinkFactory linkFactory) throws JsonFormatException { // Make sure the user set a style before invoking prettify. Preconditions.checkState(style != null, "Must call setStyle before using."); Preconditions.checkNotNull(service); Preconditions.checkNotNull(destination); // Don't bother syntax highlighting empty text. boolean empty = Strings.isNullOrEmpty(jsonString); destination.setVisible(!empty); if (empty) { return; } if (!GWT.isScript()) { // Syntax highlighting is *very* slow in Development Mode (~30s for large // responses), but very fast when compiled and run as JS (~30ms). For the // sake of my sanity, syntax highlighting is disabled in Development destination.add(new InlineLabel(jsonString)); } else { try { DynamicJso root = JsonUtils.<DynamicJso>safeEval(jsonString); Collection<ApiMethod> compatibleMethods = computeCompatibleMethods(root, service); Widget menuForMethods = createRequestMenu(compatibleMethods, service, root, linkFactory); JsObjectIterable rootObject = new JsObjectIterable(service, root, 1, linkFactory); Widget object = formatGroup(rootObject, "", 0, "{", "}", false, menuForMethods); destination.add(object); } catch (IllegalArgumentException e) { // JsonUtils will throw an IllegalArgumentException when it gets invalid // Json data. Rewrite as a checked exception and throw. throw new JsonFormatException("Invalid json.", e); } } }