use of cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency in project perun by CESNET.
the class AddDependencyTabItem method draw.
public Widget draw() {
// TITLE
titleWidget.setText("Add dependency");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
// fill listbox after callback finishes
final JsonCallbackEvents localEvents = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listBox.clear();
ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
if (execs != null && !execs.isEmpty()) {
execs = new TableSorter<ExecService>().sortByService(execs);
for (int i = 0; i < execs.size(); i++) {
listBox.addItem(execs.get(i));
if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
// preselect different type of exec service from same service
listBox.setSelected(execs.get(i), true);
}
}
addButton.setEnabled(true);
} else {
listBox.addItem("No exec service available");
}
}
@Override
public void onLoadingStart() {
listBox.clear();
listBox.addItem("Loading...");
addButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
listBox.addItem("Error while loading");
addButton.setEnabled(false);
}
};
// callback for all services
ListExecServices callback = new ListExecServices(0, localEvents);
callback.retrieveData();
// layout
layout.setHTML(0, 0, "ExecService:");
layout.setHTML(1, 0, "Depend On:");
layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
layout.setWidget(1, 1, listBox);
final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
CreateDependency request = new CreateDependency(closeTabEvents);
request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
}
});
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(addButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations