private static void deleteSearch(int id) {
    UserData user = GWTClient.getCurrentUser();
    userService.removeUserSearch(
        user.getId(),
        new Long(id),
        new AsyncCallback<Void>() {
          @Override
          public void onFailure(Throwable caught) {
            Window.alert("There was an error while removing your saved searches.");
          }

          @Override
          public void onSuccess(Void result) {
            refreshSearches();
          }
        });
  }
  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));
                  }
                });
          }
        });
  }