public Widget asWidget() {
VerticalPanel layout = new VerticalPanel();
layout.setStyleName("window-content");
final Form<ServerGroupRecord> form = new Form(ServerGroupRecord.class);
TextBoxItem nameField = new TextBoxItem("groupName", Console.CONSTANTS.common_label_name())
{
@Override
public boolean validate(String value) {
boolean hasValue = super.validate(value);
boolean hasWhitespace = value.contains(" ");
return hasValue && !hasWhitespace;
}
@Override
public String getErrMessage() {
return Console.MESSAGES.common_validation_notEmptyNoSpace();
}
};
final ComboBoxItem basedOnSelection = new ComboBoxItem("based-on", Console.CONSTANTS.common_label_basedOn());
String[] exists = new String[existing.size()];
int i=0;
for(ServerGroupRecord rec : existing)
{
exists[i] = rec.getGroupName();
i++;
}
basedOnSelection.setDefaultToFirstOption(true);
basedOnSelection.setValueMap(exists);
form.setFields(nameField, basedOnSelection);
DialogueOptions options = new DialogueOptions(
// save
new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// merge base
ServerGroupRecord newGroup = form.getUpdatedEntity();
FormValidation validation = form.validate();
if(validation.hasErrors())
return;
ServerGroupRecord base = null;
for(ServerGroupRecord rec : existing)
{
if(rec.getGroupName().equals(basedOnSelection.getValue()))
{
base = rec;
break;
}
}
newGroup.setJvm(base.getJvm());
newGroup.setSocketBinding(base.getSocketBinding());
newGroup.setProfileName(base.getProfileName());
newGroup.setProperties(base.getProperties());
presenter.createNewGroup(newGroup);
}
},
// cancel
new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
presenter.closeDialoge();
}
}
);
// ----------------------------------------
Widget formWidget = form.asWidget();
StaticHelpPanel helpPanel = new StaticHelpPanel(
Console.MESSAGES.commmon_description_newServerGroup()
);