use of cz.metacentrum.perun.webgui.json.servicesManager.RemoveRequiredAttribute in project perun by CESNET.
the class ServiceRequiredAttributesTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(service.getName()) + ": Required attributes");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// create new json call for required attributes of service with id=?
final GetServiceRequiredAttributes servReqAttr = new GetServiceRequiredAttributes(serviceId);
// menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
// custom event
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(servReqAttr);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addRequiredAttribute(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new AddRequiredAttributesTabItem(service), true);
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedRequiredAttributes());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
final ArrayList<AttributeDefinition> attrsForRemoving = servReqAttr.getTableSelectedList();
UiElements.showDeleteConfirm(attrsForRemoving, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < attrsForRemoving.size(); i++) {
if (i == attrsForRemoving.size() - 1) {
RemoveRequiredAttribute request = new RemoveRequiredAttribute(JsonCallbackEvents.disableButtonEvents(removeButton, events));
request.removeRequiredAttribute(serviceId, attrsForRemoving.get(i).getId());
} else {
RemoveRequiredAttribute request = new RemoveRequiredAttribute(JsonCallbackEvents.disableButtonEvents(removeButton));
request.removeRequiredAttribute(serviceId, attrsForRemoving.get(i).getId());
}
}
}
});
}
});
menu.addWidget(removeButton);
final ExtendedSuggestBox box = new ExtendedSuggestBox(servReqAttr.getOracle());
menu.addFilterWidget(box, new PerunSearchEvent() {
@Override
public void searchFor(String text) {
servReqAttr.filterTable(text);
}
}, "Filter required attributes by name");
vp.add(menu);
vp.setCellHeight(menu, "30px");
// get table = make call
CellTable<AttributeDefinition> reqAttrTable = servReqAttr.getTable();
// create scroll panel for table
reqAttrTable.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(reqAttrTable);
sp.addStyleName("perun-tableScrollPanel");
sp.setWidth("100%");
vp.add(sp);
vp.setCellHeight(sp, "100%");
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(servReqAttr, reqAttrTable, removeButton);
session.getUiElements().resizePerunTable(sp, 350, this);
// add tabs to the main panel
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations