/** Runs all the waiting ready listeners. */
  private void invokeReadyCallbacks() {
    Exception error = null;
    if (failed) error = new Exception("Component creation failed.");
    else if (timer != null)
      error = new Exception("Timeout occured before component creation was completed.");

    // We'll do this async so we don't set up crazy locks.
    for (GenericCallback<Void> c : readyListeners) {
      if (error != null) CommonEvents.run(c, error);
      else CommonEvents.run(c);
    }
    readyListeners.clear();
  }
 @Override
 public void run() {
   CommonEvents.preventFormSubmit(root.getAsset("Url"));
   CommonEvents.attachClickListener(
       root.getAsset("Submit"),
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           submit();
         }
       });
   complete();
 }
  /** Handles a request for a new token. */
  private void submit() {
    String url = CommonEvents.value(root.getAsset("Url"));
    rpc()
        .createToken(
            url,
            new AsyncCallback<String>() {
              @Override
              public void onFailure(Throwable caught) {
                root.getAsset("Result").setInnerHTML("Error: " + caught.toString());
              }

              @Override
              public void onSuccess(String result) {
                root.getAsset("Result").setInnerHTML(result);
              }
            });
  }