Ejemplo n.º 1
0
  @Override
  public void save() {
    clearValidationErrors();

    // Client-side validation including view/model data binding
    List<ValidationError> errors = flushView();
    if (errors.size() > 0) {
      bus.fireEvent(
          new NotifyEvent(
              new Message(Level.WARNING, "Can't save currency", "Please correct your input.")));
      showValidationErrors(errors);
      return;
    }

    service.store(
        pair,
        new AsyncCallback<Void>() {
          @Override
          public void onFailure(Throwable caught) {
            if (caught instanceof ValidationException) {
              ValidationException ex = (ValidationException) caught;

              // This is probably a FK violation
              if (!ex.hasErrors()) {
                bus.fireEvent(
                    new NotifyEvent(
                        new Message(
                            Level.WARNING,
                            "Can't save exchange rate, errors on server",
                            ex.getMessage())));
              }

              showValidationErrors(ex.getErrors());
            } else {
              bus.fireEvent(new ServerFailureNotifyEvent(caught));
            }
          }

          @Override
          public void onSuccess(Void result) {
            bus.fireEvent(
                new NotifyEvent(
                    new Message(
                        Level.INFO, "Exchange rate saved", "Modifications have been stored.")));
            bus.fireEvent(new CurrencyPairModified(pair));
          }
        });
  }
Ejemplo n.º 2
0
  @Override
  public void delete() {
    service.remove(
        pair,
        new AsyncCallback<Void>() {
          @Override
          public void onFailure(Throwable caught) {
            bus.fireEvent(new ServerFailureNotifyEvent(caught));
          }

          @Override
          public void onSuccess(Void result) {
            bus.fireEvent(
                new NotifyEvent(
                    new Message(
                        Level.INFO,
                        "Exchange rate deleted",
                        "The exchange rate has been permanently removed.")));
            bus.fireEvent(new CurrencyPairModified(pair));
          }
        });
  }