use of cz.metacentrum.perun.webgui.json.servicesManager.AddRequiredAttribute in project perun by CESNET.
the class AddRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText("Add required attributes");
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
final GetAttributesDefinition attrDefs = new GetAttributesDefinition();
attrDefs.setEditable(false);
CellTable<AttributeDefinition> table = attrDefs.getTable();
TabMenu menu = new TabMenu();
final TabItem tab = this;
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedRequiredAttribute());
final ExtendedSuggestBox box = new ExtendedSuggestBox(attrDefs.getOracle());
menu.addFilterWidget(box, new PerunSearchEvent() {
@Override
public void searchFor(String text) {
attrDefs.filterTable(text);
if (attrDefs.getList().size() == 1) {
attrDefs.getSelectionModel().setSelected(attrDefs.getList().get(0), true);
}
}
}, ButtonTranslation.INSTANCE.filterAttributeDefinition());
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<AttributeDefinition> attributesToAdd = attrDefs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(attributesToAdd)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < attributesToAdd.size(); i++) {
final int n = i;
AddRequiredAttribute request = new AddRequiredAttribute(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// unselect added attribute
attrDefs.getSelectionModel().setSelected(attributesToAdd.get(n), false);
alreadyAddedList.add(attributesToAdd.get(n));
rebuildAlreadyAddedWidget();
// clear search
box.getSuggestBox().setText("");
}
}));
request.addRequiredAttribute(serviceId, attributesToAdd.get(i).getId());
}
}
}
});
menu.addWidget(addButton);
// cancel button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(attrDefs, table, addButton);
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
mainTab.add(menu);
mainTab.setCellHeight(menu, "30px");
mainTab.add(alreadyAdded);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
// add tabs to the main panel
this.contentWidget.setWidget(mainTab);
return getWidget();
}
Aggregations