private void buildRegistrationWindow(final String user, final String sessionId, final String password,
final AsyncCallback<Subject> callback) {
int fieldWidth = 120;
//Build registration window.
EnhancedVLayout column = new EnhancedVLayout();
column.setMargin(25);
HeaderItem header = new HeaderItem();
//Locate product info for registration screen.
if (productInfo != null) {
header.setValue(MSG.view_login_welcomeMsg(productInfo.getName()));
} else {//if not available, let registration continue. Errors already logged and no functionality lost.
header.setValue(MSG.view_login_welcomeMsg(""));
}
header.setWidth("100%");
//build ui elements for registration screen
first = new TextItem(FIRST, MSG.dataSource_users_field_firstName());
first.setRequired(true);
first.setWrapTitle(false);
first.setWidth(fieldWidth);
last = new TextItem(LAST, MSG.dataSource_users_field_lastName());
last.setWrapTitle(false);
last.setWidth(fieldWidth);
last.setRequired(true);
final TextItem username = new TextItem(USERNAME, MSG.common_title_username());
username.setValue(user);
username.setDisabled(true);
username.setWidth(fieldWidth);
email = new TextItem(EMAIL, MSG.dataSource_users_field_emailAddress());
email.setRequired(true);
email.setWidth(fieldWidth);
email.setWrapTitle(false);
phone = new TextItem(PHONE, MSG.dataSource_users_field_phoneNumber());
phone.setWidth(fieldWidth);
phone.setWrapTitle(false);
department = new TextItem(DEPARTMENT, MSG.dataSource_users_field_department());
department.setWidth(fieldWidth);
SpacerItem space = new SpacerItem();
space.setColSpan(1);
inputForm = new DynamicForm();
inputForm.setAutoFocus(true);
inputForm.setErrorOrientation(FormErrorOrientation.LEFT);
inputForm.setNumCols(4);
//moving header to it's own container for proper display. Didn't display right in production mode
inputForm.setFields(username, first, last, email, phone, department);
loadValidators(inputForm);
inputForm.setValidateOnExit(true);
DynamicForm headerWrapper = new DynamicForm();
headerWrapper.setFields(header);
column.addMember(headerWrapper);
column.addMember(inputForm);
HTMLFlow hr = new HTMLFlow("<br/><hr/><br/><br/>");
hr.setWidth(620);
hr.setAlign(Alignment.CENTER);
column.addMember(hr);
HStack row = new HStack();
row.setMembersMargin(5);
row.setAlign(VerticalAlignment.CENTER);
IButton okButton = new EnhancedIButton(MSG.common_button_ok());
okButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//F5 refresh check? If they've reloaded the form for some reason then bail.
boolean credentialsEmpty = ((user == null) || (user.trim().isEmpty()) || (password == null) || (password
.trim().isEmpty()));
//check for session timeout
if (UserSessionManager.isLoggedOut() || (credentialsEmpty)) {
resetLogin();
return;
}
//validation
if (inputForm.validate()) {
Log.trace("Successfully validated all data for user registration.");
//populate form
if (first.getValue() != null)
inputForm.setValue(FIRST, String.valueOf(first.getValue()));
if (last.getValue() != null)
inputForm.setValue(LAST, String.valueOf(last.getValue()));
inputForm.setValue(USERNAME, String.valueOf(username.getValue()));
if (email.getValue() != null)
inputForm.setValue(EMAIL, String.valueOf(email.getValue()));
if (phone.getValue() != null)
inputForm.setValue(PHONE, String.valueOf(phone.getValue()));
if (department.getValue() != null)
inputForm.setValue(DEPARTMENT, String.valueOf(department.getValue()));
inputForm.setValue(SESSIONID, sessionId);
inputForm.setValue(PASSWORD, password);
registerLdapUser(inputForm, callback);
}
}
});
row.addMember(okButton);
//prepopulate form from user details returned.
Subject subject = UserSessionManager.getSessionSubject();
first.setValue(subject.getFirstName());
last.setValue(subject.getLastName());
email.setValue(subject.getEmailAddress());
phone.setValue(subject.getPhoneNumber());
department.setValue(subject.getDepartment());
IButton resetButton = new EnhancedIButton(MSG.common_button_reset());
resetButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//F5 refresh check? If they've reloaded the form for some reason then bail.
boolean credentialsEmpty = ((user == null) || (user.trim().isEmpty()) || (password == null) || (password
.trim().isEmpty()));
if (UserSessionManager.isLoggedOut() || credentialsEmpty) {
resetLogin();
return;
}
//clear out all validation messages.
String empty = " ";
first.setValue(empty);
last.setValue(empty);
email.setValue("test@test.com");
inputForm.validate();
first.clearValue();
last.clearValue();
email.clearValue();
phone.clearValue();
department.clearValue();
}
});
row.addMember(resetButton);
IButton cancelButton = new EnhancedIButton(MSG.common_button_cancel());
cancelButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
UserSessionManager.logout();
resetLogin();
}
});
row.addMember(cancelButton);
Label logoutLabel = new Label(MSG.view_login_registerLater());
logoutLabel.setWrap(false);
row.addMember(logoutLabel);
column.addMember(row);
window = new Window();
window.setWidth(670);
window.setHeight(370);
window.setTitle(MSG.view_login_registerUser());