/** Removes the script tag with the given id from the document. */
 private static void removeScriptTag(String id) {
   Document document = Document.get();
   Element element = document.getElementById(id);
   if (element != null) {
     document.getElementsByTagName("body").getItem(0).removeChild(element);
   }
 }
 @Override
 public void onReset() {
   // super.onReset();
   String folderId = AppClientFactory.getPlaceManager().getRequestParameter("folderid");
   String userId = AppClientFactory.getPlaceManager().getRequestParameter("id");
   if (!(userId == version) || (folderId == null)) {
     Document doc = Document.get();
     doc.getElementById("uvTab").getStyle().setDisplay(Display.BLOCK);
     version = userId;
   }
 }
Esempio n. 3
0
  @Test
  public void checkGetElementByIdInBody() {
    // Setup
    AnchorElement a = Document.get().createAnchorElement();
    a.setId("myId");
    DivElement div = Document.get().createDivElement();
    div.appendChild(a);
    d.getBody().appendChild(div);

    // Test
    Element result = d.getElementById("myId");

    // Assert
    Assert.assertEquals(a, result);
  }
  /**
   * Sends a JSONP request by embedding a SCRIPT tag into the document.
   *
   * @param id the id used for the script tag and to identify the callback
   * @param request the request to be made
   * @param parameters the parameters for the request
   * @param function a function that transforms the response into the type that the callback needs
   * @param callback the callback that should be called with the transformed response
   */
  private <T> void sendJsonpRequest(
      String id,
      String request,
      Map<String, Object> parameters,
      final Function<String, ? extends T> function,
      final AsyncCallback<T> callback) {
    Preconditions.checkNotNull(id);

    // Prepare an intermediate callback that converts the String result to T.
    if (callback != null) {
      Preconditions.checkNotNull(function);
      CALLBACKS.put(
          id,
          new AsyncCallback<String>() {
            @Override
            public void onSuccess(String jsonResult) {
              T result;
              try {
                result = function.apply(jsonResult);
              } catch (RuntimeException e) {
                callback.onFailure(e);
                return;
              }
              callback.onSuccess(result);
            }

            @Override
            public void onFailure(Throwable caught) {
              callback.onFailure(caught);
            }
          });
    }

    // Insert a script tag into the document.
    Document document = Document.get();
    ScriptElement script = document.createScriptElement();
    String uri = makeURI(request, parameters, id);
    script.setSrc(uri);
    script.setId(id);
    Element bodyElement = document.getElementsByTagName("body").getItem(0);
    Element previous = document.getElementById(id);
    if (previous != null) {
      bodyElement.replaceChild(script, previous);
    } else {
      bodyElement.appendChild(script);
    }
  }
Esempio n. 5
0
  @Test
  public void checkGetElementByIdNotFound() {
    // Setup
    AnchorElement a1 = Document.get().createAnchorElement();
    AnchorElement a2 = Document.get().createAnchorElement();
    AnchorElement a3 = Document.get().createAnchorElement();
    DivElement d1 = Document.get().createDivElement();
    d.appendChild(a1);
    d.appendChild(a1);
    d.appendChild(a2);
    a2.appendChild(a3);
    d.appendChild(d1);

    // Test
    Element result = d.getElementById("myId");

    // Assert
    Assert.assertNull(result);
  }