use of cz.metacentrum.perun.webgui.json.resourcesManager.CreateResource in project perun by CESNET.
the class CreateFacilityResourceTabItem method draw.
public Widget draw() {
titleWidget.setText("Create resource");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// form inputs
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final TextBox descriptionTextBox = new TextBox();
final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());
// local events fills the listbox of Vos and Slds
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// fill VOs listbox
vosDropDown.clear();
ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
vos = new TableSorter<VirtualOrganization>().sortByName(vos);
for (VirtualOrganization vo : vos) {
vosDropDown.addItem(vo);
}
if (!vos.isEmpty())
createButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
vosDropDown.clear();
vosDropDown.addItem("Loading...");
createButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
vosDropDown.clear();
vosDropDown.addItem("Error while loading");
createButton.setEnabled(false);
}
};
// load available VOs
final GetVos vos = new GetVos(event);
vos.setForceAll(true);
vos.retrieveData();
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// Add some standard form options
layout.setHTML(0, 0, "On facility:");
layout.setHTML(0, 1, facility.getName());
layout.setHTML(1, 0, "For VO:");
layout.setWidget(1, 1, vosDropDown);
layout.setHTML(2, 0, "Name:");
layout.setWidget(2, 1, nameTextBox);
layout.setHTML(3, 0, "Description:");
layout.setWidget(3, 1, descriptionTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setWidth("350px");
TabMenu menu = new TabMenu();
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setError("Name can't be empty.");
return false;
}
nameTextBox.setOk();
return true;
}
};
nameTextBox.setValidator(validator);
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// loads new tab when creating successful, also disable button
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onLoadingStart() {
(JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
}
public void onFinished(JavaScriptObject jso) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
Resource res = (Resource) jso;
session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceManageServicesTabItem(facility, res), true);
}
public void onError(PerunError error) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
}
};
if (validator.validateTextBox()) {
// request
CreateResource request = new CreateResource(localEvents);
request.createResource(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId());
}
}
});
menu.addWidget(createButton);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations