use of cz.metacentrum.perun.webgui.json.resourcesManager.UpdateResourceTag in project perun by CESNET.
the class VoResourcesTagsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources tags");
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
// refresh
menu.addWidget(UiElements.getRefreshButton(this));
// members request
final GetAllResourcesTags resTags = new GetAllResourcesTags(PerunEntity.VIRTUAL_ORGANIZATION, voId);
if (!session.isVoAdmin(voId))
resTags.setCheckable(false);
if (session.isVoAdmin(voId))
resTags.setEditable(true);
// Events for reloading when finished
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(resTags);
CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createResourceTag(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateVoResourceTagTabItem(voId));
}
});
menu.addWidget(addButton);
if (!session.isVoAdmin(voId))
addButton.setEnabled(false);
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteResourceTag());
if (!session.isVoAdmin(voId))
removeButton.setEnabled(false);
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<ResourceTag> tagsToRemove = resTags.getTableSelectedList();
String text = "Following tags will be deleted and won't be used to tag VO resources.";
UiElements.showDeleteConfirm(tagsToRemove, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < tagsToRemove.size(); i++) {
DeleteResourceTag request;
if (i == tagsToRemove.size() - 1) {
request = new DeleteResourceTag(JsonCallbackEvents.disableButtonEvents(removeButton, events));
} else {
request = new DeleteResourceTag(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.deleteResourceTag(tagsToRemove.get(i));
}
}
});
}
});
menu.addFilterWidget(new ExtendedSuggestBox(resTags.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
resTags.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterTags());
final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.updateResourceTag());
menu.addWidget(saveButton);
if (!session.isVoAdmin(voId))
saveButton.setEnabled(false);
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<ResourceTag> tagsToUpdate = resTags.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(tagsToUpdate)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < tagsToUpdate.size(); i++) {
UpdateResourceTag request;
if (i == tagsToUpdate.size() - 1) {
request = new UpdateResourceTag(JsonCallbackEvents.disableButtonEvents(saveButton, events));
} else {
request = new UpdateResourceTag(JsonCallbackEvents.disableButtonEvents(saveButton));
}
request.updateResourceTag(tagsToUpdate.get(i));
}
}
}
});
// get the table
CellTable<ResourceTag> table = resTags.getTable();
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// add menu and the table to the main panel
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.add(sp);
removeButton.setEnabled(false);
if (session.isVoAdmin(voId))
JsonUtils.addTableManagedButton(resTags, table, removeButton);
saveButton.setEnabled(false);
if (session.isVoAdmin(voId))
JsonUtils.addTableManagedButton(resTags, table, saveButton);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations