private void doSave() {
    if (validateFields()) {
      user.setUsername(Utils.safeString(usernameTextBox.getValue()));
      user.setFullname(Utils.safeString(fullnameTextBox.getValue()));
      user.setEmail(Utils.safeString(emailTextBox.getValue()));
      user.setActiveFlag(enabledCheckBox.getValue());
      user.updateAuthnPasswordValue(Utils.safeString(password1TextBox.getValue()));
      user.removeGroups();
      for (GroupData groupData : toGroupStore.getModels()) {
        Group group = (Group) groupData.get(Constants.GROUP);
        user.addGroup(group);
      }

      final AsyncCallback<Void> callback =
          new AsyncCallback<Void>() {
            @Override
            public void onFailure(Throwable caught) {
              WebPasswordSafe.handleServerFailure(caught);
            }

            @Override
            public void onSuccess(Void result) {
              Info.display(textMessages.status(), textMessages.userSaved());
              hide();
            }
          };
      if (user.getId() == 0) {
        final AsyncCallback<Boolean> callbackCheck =
            new AsyncCallback<Boolean>() {
              @Override
              public void onFailure(Throwable caught) {
                WebPasswordSafe.handleServerFailure(caught);
              }

              @Override
              public void onSuccess(Boolean result) {
                // true => username already taken, else go ahead and save
                if (result) {
                  MessageBox.alert(
                      textMessages.error(), textMessages.usernameAlreadyExists(), null);
                } else {
                  UserService.Util.getInstance().addUser(user, callback);
                }
              }
            };
        UserService.Util.getInstance().isUserTaken(user.getUsername(), callbackCheck);
      } else {
        UserService.Util.getInstance().updateUser(user, callback);
      }
    }
  }
  private void loadAvailableUsers() {
    AsyncCallback<List<User>> callback =
        new AsyncCallback<List<User>>() {
          @Override
          public void onFailure(Throwable caught) {
            WebPasswordSafe.handleServerFailure(caught);
          }

          @Override
          public void onSuccess(List<User> result) {
            refreshAvailableUsers(result);
          }
        };
    UserService.Util.getInstance().getUsers(false, callback);
  }
  private void doSave() {
    if (validateFields()) {
      group.setName(Utils.safeString(nameTextBox.getValue()));
      group.removeUsers();
      for (UserData userData : toUserStore.getModels()) {
        group.addUser((User) userData.get(Constants.USER));
      }

      final AsyncCallback<Boolean> callbackCheck =
          new AsyncCallback<Boolean>() {
            @Override
            public void onFailure(Throwable caught) {
              WebPasswordSafe.handleServerFailure(caught);
            }

            @Override
            public void onSuccess(Boolean result) {
              // true => group name already taken, else go ahead and save
              if (result) {
                MessageBox.alert(textMessages.error(), textMessages.groupNameAlreadyExists(), null);
              } else {
                AsyncCallback<Void> callback =
                    new AsyncCallback<Void>() {
                      @Override
                      public void onFailure(Throwable caught) {
                        WebPasswordSafe.handleServerFailure(caught);
                      }

                      @Override
                      public void onSuccess(Void result) {
                        Info.display(textMessages.status(), textMessages.groupSaved());
                        hide();
                      }
                    };
                if (group.getId() == 0) {
                  UserService.Util.getInstance().addGroup(group, callback);
                } else {
                  UserService.Util.getInstance().updateGroup(group, callback);
                }
              }
            }
          };
      UserService.Util.getInstance().isGroupTaken(group.getName(), group.getId(), callbackCheck);
    }
  }