use of cz.metacentrum.perun.webgui.json.facilitiesManager.AddHosts in project perun by CESNET.
the class AddHostsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": add hosts");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final ExtendedTextArea newHosts = new ExtendedTextArea();
newHosts.getTextArea().setSize("335px", "150px");
final ExtendedTextArea.TextAreaValidator validator = new ExtendedTextArea.TextAreaValidator() {
@Override
public boolean validateTextArea() {
if (newHosts.getTextArea().getText().trim().isEmpty()) {
newHosts.setError("Please enter at least one hostname to add it to facility.");
return false;
} else {
newHosts.setOk();
return true;
}
}
};
newHosts.setValidator(validator);
final CustomButton addHostsButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addHost());
// close tab, disable button
final TabItem tab = this;
addHostsButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextArea()) {
String hostnames = newHosts.getTextArea().getText().trim();
String[] hosts = hostnames.split("\n");
// trim whitespace
for (int i = 0; i < hosts.length; i++) {
hosts[i] = hosts[i].trim();
}
AddHosts request = new AddHosts(facility.getId(), JsonCallbackEvents.closeTabDisableButtonEvents(addHostsButton, tab, true));
request.addHosts(hosts);
}
}
});
TabMenu menu = new TabMenu();
menu.addWidget(addHostsButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
// layout
final FlexTable layout = new FlexTable();
layout.setWidth("350px");
layout.setStyleName("inputFormFlexTable");
FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
layout.setHTML(0, 0, "Hostnames:");
layout.setWidget(1, 0, newHosts);
cellFormatter.addStyleName(0, 0, "itemName");
layout.setHTML(2, 0, "Enter one host per line. You can use \"[x-y]\" in hostname to generate hosts with numbers from x to y. This replacer can be specified multiple times in one hostname to generate MxN combinations.");
cellFormatter.addStyleName(2, 0, "inputFormInlineComment");
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations