public Widget asWidget() {
VerticalPanel layout = new VerticalPanel();
layout.setStyleName("window-content");
final PojoForm<Role> form = new PojoForm<Role>();
final TextBoxItem nameItem = new TextBoxItem("name", Console.CONSTANTS.common_label_name());
final EnumFormItem<StandardRole> baseRoleItem = new EnumFormItem<StandardRole>("baseRole",
Console.CONSTANTS.administration_base_role());
baseRoleItem.setValues(UIHelper.enumFormItemsForStandardRole());
final EnumFormItem<Role.Type> typeItem = new EnumFormItem<Role.Type>("type",
Console.CONSTANTS.common_label_type());
typeItem.setDefaultToFirst(true);
typeItem.setValues(UIHelper.enumFormItemsForScopedRoleTyp());
final MultiselectListBoxItem scopeItem = new MultiselectListBoxItem("scope",
Console.CONSTANTS.administration_scope(), 3);
final CheckBoxItem includeAllItem = new CheckBoxItem("includeAll",
Console.CONSTANTS.administration_include_all());
form.setFields(nameItem, baseRoleItem, typeItem, scopeItem, includeAllItem);
layout.add(form.asWidget());
typeItem.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(final ChangeEvent event) {
Role.Type type = typeItem.getValue();
updateScope(type, scopeItem, form);
}
});
updateScope(typeItem.getValue(), scopeItem, form);
DialogueOptions options = new DialogueOptions(
new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
FormValidation validation = form.validate();
if (!validation.hasErrors()) {
Role scopedRole = new Role(nameItem.getValue(), nameItem.getValue(),
baseRoleItem.getValue(), typeItem.getValue(), scopeItem.getValue());
scopedRole.setIncludeAll(includeAllItem.getValue());
presenter.addScopedRole(scopedRole);
}
}