public class EditAccountPanel extends FlexTable {
public EditAccountPanel(final IGenericCallback<User> callback, final User user) {
final TextBox usernameTextBox = new TextBox();
final PasswordTextBox passwordTextBox = new PasswordTextBox();
final TextBox passwordHintTextBox = new TextBox();
final TextBox firstnameTextBox = new TextBox();
final TextBox lastnameTextBox = new TextBox();
final TextBox emailTextBox = new TextBox();
Date birthday = new Date(user.getBirthday());
DefaultFormat format = new DefaultFormat(DateTimeFormat.getMediumDateFormat());
final DateBox birthdayPicker = new DateBox(new MyDatePicker(), birthday, format);
final CheckBox validatedCheckBox = new CheckBox("Validated");
final CheckBox administratorCheckBox = new CheckBox("Administrator");
usernameTextBox.setText(user.getUsername());
passwordHintTextBox.setText(user.getPasswordHint());
firstnameTextBox.setText(user.getFirstname());
lastnameTextBox.setText(user.getLastname());
emailTextBox.setText(user.getEmail());
validatedCheckBox.setValue(user.isValidated());
administratorCheckBox.setValue(user.isAdministrator());
birthdayPicker.setValue(birthday);
Button applyButton = new Button("Apply");
applyButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
user.setUsername(usernameTextBox.getText());
user.setPasswordHint(passwordHintTextBox.getText());
user.setFirstname(firstnameTextBox.getText());
user.setLastname(lastnameTextBox.getText());
user.setEmail(emailTextBox.getText());
user.setBirthday(birthdayPicker.getValue().getTime());
user.setAdministrator(administratorCheckBox.getValue());
user.setValidated(validatedCheckBox.getValue());
final AsyncCallback<User> loginCallback = new AsyncCallback<User>() {
public void onFailure(Throwable caught) {
MessageDialogBox dialog = new MessageDialogBox("Error", "Could not edit account.", true, true, true);
dialog.center();
}
public void onSuccess(User user) {
if (user == null) {
MessageDialogBox dialog = new MessageDialogBox("Error", "Could not edit account.", true, true, true);
dialog.center();
} else {
MessageDialogBox dialog = new MessageDialogBox("Success", "Account modified.", true, true, true);
dialog.center();
callback.invoke(user);
}
};
};
BaseServiceCache.getService().createOrEditAccount(user, passwordTextBox.getText(), null, loginCallback);
}
});
applyButton.setTitle("Apply Changes");
// build ui