public NewServerGroupWizard(final ServerGroupPresenter presenter, final List<ServerGroupRecord> existing) {
layout = new VerticalPanel();
layout.setStyleName("fill-layout-width");
layout.getElement().setAttribute("cellpadding", "10");
final Form<ServerGroupRecord> form = new Form(ServerGroupRecord.class);
TextBoxItem nameField = new TextBoxItem("groupName", "Group Name")
{
@Override
public boolean validate(String value) {
boolean hasValue = super.validate(value);
boolean hasWhitespace = value.contains(" ");
return hasValue && !hasWhitespace;
}
@Override
public String getErrMessage() {
return "Not empty, no whitespace";
}
};
final ComboBoxItem basedOnSelection = new ComboBoxItem("based-on", "Based On");
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);
Button submit = new DefaultButton("Save");
submit.getElement().setAttribute("style", "width:50px;height:18px");
submit.addClickHandler(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);
}
});
Label cancel = new Label("Cancel");
cancel.setStyleName("html-link");
cancel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
presenter.closeDialoge();
}
});
HorizontalPanel options = new HorizontalPanel();
options.getElement().setAttribute("style", "width:100%");
HTML spacer = new HTML(" ");
options.add(spacer);
//spacer.getElement().getParentElement().setAttribute("width", "100%");
options.add(submit);
options.add(spacer);
options.add(cancel);
cancel.getElement().getParentElement().setAttribute("style","vertical-align:middle");
submit.getElement().getParentElement().setAttribute("align", "right");
submit.getElement().getParentElement().setAttribute("width", "100%");
// ----------------------------------------
Widget formWidget = form.asWidget();
layout.add(new HTML("Create a new server group based on an existing one. " +
"The new group will inherit the properties of the selected group."));
layout.add(formWidget);