use of cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory in project perun by CESNET.
the class AllCategoriesTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final GetCategories callback = new GetCategories();
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new category", new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateCategoryTabItem());
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, "Delete selected categories");
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Category> delete = callback.getTableSelectedList();
String text = "Following categories will be deleted";
UiElements.showDeleteConfirm(delete, text, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < delete.size(); i++) {
if (i == delete.size() - 1) {
DeleteCategory request = new DeleteCategory(JsonCallbackEvents.disableButtonEvents(removeButton, events));
request.deleteCategory(delete.get(i).getId());
} else {
DeleteCategory request = new DeleteCategory(JsonCallbackEvents.disableButtonEvents(removeButton));
request.deleteCategory(delete.get(i).getId());
}
}
}
});
}
});
menu.addWidget(removeButton);
final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in category ranks");
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Category> list = callback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton, events));
request.updateCategory(list.get(i));
} else {
UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton));
request.updateCategory(list.get(i));
}
}
}
}
});
menu.addWidget(saveButton);
vp.add(menu);
vp.setCellHeight(menu, "30px");
CellTable<Category> table = callback.getTable();
removeButton.setEnabled(false);
saveButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeButton);
JsonUtils.addTableManagedButton(callback, table, saveButton);
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
// resize perun table to correct size on screen
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations