예제 #1
0
  @UiHandler("btnOk")
  void saveChanges(ClickEvent e) {
    if (separator.isVisible()) {
      editMode(false);
    }

    if (removedRecs.size() > 0) {

      final InputItem rec = removedRecs.entrySet().iterator().next().getValue();

      MethodCallback<Void> cb =
          new MethodCallback<Void>() {
            @Override
            public void onFailure(Method method, Throwable exception) {
              askRetry(rec, "Error removing record " + rec.getName() + ". Retry ?");
            }

            @Override
            public void onSuccess(Method method, Void response) {
              removedRecs.remove(rec.getId());
              saveChanges(null);
            }
          };

      md.info(MDS, "Removing record " + rec.getName());
      clientApi.iitemsApi().delete(rec.getId(), cb);

    } else if (changedRecs.size() > 0) {

      final InputItem rec = changedRecs.entrySet().iterator().next().getValue();

      MethodCallback<Void> cb =
          new MethodCallback<Void>() {
            @Override
            public void onFailure(Method method, Throwable exception) {
              askRetry(rec, "Error updating user " + rec.getName() + ". Retry ?");
            }

            @Override
            public void onSuccess(Method method, Void response) {
              changedRecs.remove(rec.getId());
              saveChanges(null);
            }
          };

      if (rec.getId() == 0) {
        md.info(MDS, "Creating user " + rec);
        clientApi.iitemsApi().create(rec, cb);
      } else {
        md.info(MDS, "Updating user " + rec);
        clientApi.iitemsApi().update(rec.getId(), rec, cb);
      }

    } else {
      refreshRecords(e);
      md.clear(MDS);
    }
  }
예제 #2
0
 @UiHandler("btnCancel")
 void cancelChanges(ClickEvent e) {
   recordStore.getList().clear();
   changedRecs.clear();
   removedRecs.clear();
   editMode(false);
   refreshRecords(e);
   md.clear(MDS);
 }
예제 #3
0
 private void markChange(InputItem rec) {
   if (!changedRecs.containsKey(rec.getId())) {
     changedRecs.put(rec.getId(), rec);
     if (!separator.isVisible()) {
       md.info(
           MDS, "Some data has been changed. Click 'Save' or 'Cancel' when editing is finished.");
       editMode(true);
     }
     dataGrid.redraw();
   }
 }