private void buildLessonTree(Response response) { TreeItem item = null; JsArray<LessonCategoryJS> lessonJSArray = JsonUtils.safeEval(response.getText()); for (int i = 0; i < lessonJSArray.length(); i++) { LessonCategoryJS lessonCategoryJS = lessonJSArray.get(i); TreeItem category = new TreeItem(); category.setText(lessonCategoryJS.getName()); JsArray<LessonJS> lessons = lessonCategoryJS.getChildren(); for (int j = 0; j < lessons.length(); j++) { LessonJS lesson = lessons.get(j); TreeItem lessonItem = new TreeItem(); Storage sessionStorage = Storage.getSessionStorageIfSupported(); String lastUrl = sessionStorage.getItem("lastUrl"); lessonItem.setText(lesson.getText()); category.addItem(lessonItem); lessonsTreeMap.put(lessonItem.getText(), lesson); if (lesson.getTechnology().equals(LessonTechnology.GWT.toString())) { addLessonToMap(lesson); } if (lastUrl != null && lastUrl.equals(lesson.getUrl())) { item = lessonItem; lessonPanel.setSelectedLesson(lesson); category.setState(true); } } lessonTree.addItem(category); } lessonTree.setSelectedItem(item); }
public static Splittable split(String payload) { char c = payload.charAt(0); boolean isSimple = c != '{' && c != '['; if (isSimple) { payload = "[" + payload + "]"; } Splittable toReturn = JsonUtils.safeEval(payload).<JsoSplittable>cast(); if (isSimple) { toReturn = toReturn.get(0); } return toReturn; }
private static void getSearches( final int start, final int length, final JavaScriptObject function) { GWTClient.callback( function, JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); displayedSearches.clear(); final UserData user = GWTClient.getCurrentUser(); userService.countUserSearches( user.getId(), new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting your saved searches."); } @Override public void onSuccess(final Integer total) { userService.scrollSearchesOfUser( start, length, user.getId(), new AsyncCallback<List<SearchData>>() { @Override public void onFailure(Throwable caught) { Window.alert("There was an error while getting your saved searches."); } @Override public void onSuccess(List<SearchData> result) { String json = "{\"aaData\": ["; for (SearchData search : result) { String advancedText = ""; Map<String, String> advanceds = search.getAdvanced(); if (advanceds != null && !advanceds.isEmpty()) { advancedText += "<i> ("; boolean first = true; List<String> keys = new ArrayList<String>(advanceds.keySet()); Collections.sort(keys); String lastKey = ""; for (String key : keys) { if ((lastKey + "End").equals(key)) { advancedText += " to " + advanceds.get(key); } else { if (key.endsWith("End")) { advancedText += (first ? "" : ", ") + key.substring(0, key.length() - 3) + ": * to " + advanceds.get(key); } else { advancedText += (first ? "" : ", ") + key + ": " + advanceds.get(key); } } first = false; lastKey = key; } advancedText += ")</i>"; } displayedSearches.put(search.getId(), search); json += "[\"" + search.getValue().replace("\"", "\\\"") + advancedText.replace("\"", "\\\"") + "\"," + search.getId() + "," + "{\"id\":" + search.getId() + ", \"notify\":" + search.isNotify() + "},\"" + search.getId() + "\"],"; } if (total >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; clearSearches .getElement() .setClassName(total >= 1 ? "button_black" : "button_disabled"); GWTClient.callback(function, JsonUtils.safeEval(json)); } }); } }); }
@Override public void start(AcceptsOneWidget panel, final EventBus eventBus) { view = clientFactory.getRestAreaView(); analytics = clientFactory.getAnalytics(); accessibility = clientFactory.getAccessibility(); this.eventBus = eventBus; view.setPresenter(this); Place place = clientFactory.getPlaceController().getWhere(); if (place instanceof RestAreaPlace) { RestAreaPlace restAreaPlace = (RestAreaPlace) place; int restAreaId = Integer.valueOf(restAreaPlace.getId()); String jsonString = AppBundle.INSTANCE.restAreaData().getText(); RestAreaFeed restAreas = JsonUtils.safeEval(jsonString); view.setTitle("Safety Rest Area"); SafeHtmlBuilder detailsHTMLBuilder = new SafeHtmlBuilder(); detailsHTMLBuilder.appendEscaped( restAreas.getRestAreas().get(restAreaId).getRoute() + " - " + restAreas.getRestAreas().get(restAreaId).getLocation()); detailsHTMLBuilder.appendHtmlConstant("<br>"); detailsHTMLBuilder.appendEscaped( "Milepost: " + restAreas.getRestAreas().get(restAreaId).getMilepost() + " - " + restAreas.getRestAreas().get(restAreaId).getDirection()); view.setDetails(detailsHTMLBuilder.toSafeHtml()); if (restAreas.getRestAreas().get(restAreaId).getNotes() == null) { view.hideNotesHeading(); view.setNotes(""); } else { view.showNotesHeading(); view.setNotes(restAreas.getRestAreas().get(restAreaId).getNotes()); } SafeHtmlBuilder amenitiesHTMLBuilder = new SafeHtmlBuilder(); amenitiesHTMLBuilder.appendHtmlConstant("<ul>"); for (int i = 0; i < restAreas.getRestAreas().get(restAreaId).getAmenities().length; i++) { amenitiesHTMLBuilder.appendHtmlConstant("<li>"); amenitiesHTMLBuilder.appendEscaped( restAreas.getRestAreas().get(restAreaId).getAmenities()[i]); amenitiesHTMLBuilder.appendHtmlConstant("</li>"); } if (restAreas.getRestAreas().get(restAreaId).getAmenities().length == 0) { view.hideAmenitiesHeading(); } else { view.showAmenitiesHeading(); } amenitiesHTMLBuilder.appendHtmlConstant("</ul>"); view.setAmenities(amenitiesHTMLBuilder.toSafeHtml()); view.setLatLon( Double.valueOf(restAreas.getRestAreas().get(restAreaId).getLatitude()), Double.valueOf(restAreas.getRestAreas().get(restAreaId).getLongitude())); view.refresh(); } panel.setWidget(view); accessibility.postScreenChangeNotification(); }
private JsArray<Worker> getJSONData(String json) { return JsonUtils.safeEval(json); }