use of cz.metacentrum.perun.webgui.json.resourcesManager.GetRichResources in project perun by CESNET.
the class AssignGroupTabItem method draw.
public Widget draw() {
// set tab name
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": assign to resource");
// main content
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
// callback
final GetRichResources callback = new GetRichResources(group.getVoId());
callback.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
for (RichResource rr : resources) {
callback.removeFromTable(rr);
}
ArrayList<RichResource> temp = new ArrayList<RichResource>();
temp.addAll(callback.getList());
callback.setList(temp);
}
});
CellTable<RichResource> table = callback.getTable();
// close tab event
final TabItem tab = this;
// filter box
menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
callback.filterTable(text);
// if single group, select
if (callback.getList().size() == 1) {
callback.getSelectionModel().setSelected(callback.getList().get(0), true);
}
}
}, ButtonTranslation.INSTANCE.filterResources());
// button
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignGroupToSelectedResources());
assignButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<RichResource> toAssign = callback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(toAssign)) {
AssignGroupToResources request = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
alreadyAddedList.addAll(toAssign);
for (RichResource r : toAssign) {
callback.getSelectionModel().setSelected(r, false);
}
rebuildAlreadyAddedWidget();
}
}));
request.assignGroupToResources(group, toAssign);
}
}
});
menu.addWidget(assignButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
assignButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, assignButton);
// add menu and the table to the main panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// do not use resizePerunTable() in overlay mode - calculated width is wrong
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
mainTab.add(menu);
mainTab.setCellHeight(menu, "30px");
rebuildAlreadyAddedWidget();
mainTab.add(alreadyAdded);
mainTab.add(sp);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.resourcesManager.GetRichResources in project perun by CESNET.
the class VoResourcesTabItem method draw.
public Widget draw() {
// set title
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources");
// main panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
// refresh
menu.addWidget(UiElements.getRefreshButton(this));
// get VO resources
final GetRichResources resources = new GetRichResources(voId);
if (!session.isVoAdmin(voId))
resources.setCheckable(false);
// custom events for viewResource
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(resources);
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteResource());
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<RichResource> resourcesForDeleting = resources.getTableSelectedList();
String text = "Following resources will be deleted and VO members won't be able to access them anymore.";
UiElements.showDeleteConfirm(resourcesForDeleting, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < resourcesForDeleting.size(); i++) {
DeleteResource request;
if (i == resourcesForDeleting.size() - 1) {
request = new DeleteResource(JsonCallbackEvents.disableButtonEvents(removeButton, events));
} else {
request = new DeleteResource(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.deleteResource(resourcesForDeleting.get(i).getId());
}
}
});
}
});
// add menu to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
// filter box
menu.addFilterWidget(new ExtendedSuggestBox(resources.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
resources.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterResources());
CellTable<RichResource> table = resources.getTable(new FieldUpdater<RichResource, String>() {
public void update(int index, RichResource object, String value) {
session.getTabManager().addTab(new ResourceDetailTabItem(object, 0));
}
});
removeButton.setEnabled(false);
if (session.isVoAdmin(voId))
JsonUtils.addTableManagedButton(resources, table, removeButton);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations