use of cz.metacentrum.perun.webgui.json.servicesManager.GetServicesPackages in project perun by CESNET.
the class ServicePackagesTabItem method draw.
public Widget draw() {
// create widget for the whole page
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
// create widget for menu on page
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// get services
final GetServicesPackages services = new GetServicesPackages();
services.setEditable(true);
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(services);
// get the table of services with custom field updater (lines are clickable and open service details)
CellTable<ServicesPackage> table = services.getTable(new FieldUpdater<ServicesPackage, String>() {
// when user click on a row -> open new tab
public void update(int index, ServicesPackage object, String value) {
session.getTabManager().addTabToCurrentTab(new ServicePackageDetailTabItem(object), true);
}
});
// create button
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createServicePackage(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new CreateServicePackageTabItem());
}
}));
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteSelectedServicePackages());
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get selected items
final ArrayList<ServicesPackage> itemsToRemove = services.getTableSelectedList();
UiElements.showDeleteConfirm(itemsToRemove, "Following services packages will be deleted.", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < itemsToRemove.size(); i++) {
DeleteServicePackage request;
if (i == itemsToRemove.size() - 1) {
request = new DeleteServicePackage(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
} else {
request = new DeleteServicePackage(JsonCallbackEvents.disableButtonEvents(deleteButton));
}
request.deleteServicePackage(itemsToRemove.get(i).getId());
}
}
});
}
});
tabMenu.addWidget(deleteButton);
tabMenu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
services.filterTable(text);
}
}, "Filter service package by name");
final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInServicesPackages());
save.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get selected items
final ArrayList<ServicesPackage> itemsToUpdate = services.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(itemsToUpdate)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < itemsToUpdate.size(); i++) {
UpdateServicePackage request;
if (i == itemsToUpdate.size() - 1) {
request = new UpdateServicePackage(JsonCallbackEvents.disableButtonEvents(save, events));
} else {
request = new UpdateServicePackage(JsonCallbackEvents.disableButtonEvents(save));
}
request.updateServicePackage(itemsToUpdate.get(i));
}
}
}
});
tabMenu.addWidget(save);
// add menu to page itself
mainTab.add(tabMenu);
mainTab.setCellHeight(tabMenu, "30px");
// add styling to table with services
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
mainTab.add(sp);
deleteButton.setEnabled(false);
save.setEnabled(false);
JsonUtils.addTableManagedButton(services, table, deleteButton);
JsonUtils.addTableManagedButton(services, table, save);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
Aggregations