use of cz.metacentrum.perun.webgui.tabs.facilitiestabs.CreateFacilityTabItem in project perun by CESNET.
the class FacilitiesTabItem method draw.
public Widget draw() {
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// TAB MENU
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// get RICH facilities request
final GetFacilities facilities = new GetFacilities(true);
// retrieve data (table)
final CellTable<Facility> table = facilities.getTable(new FieldUpdater<Facility, String>() {
public void update(int index, Facility object, String value) {
session.getTabManager().addTab(new FacilityDetailTabItem(object));
}
});
// add new facility button
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createFacility(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new CreateFacilityTabItem());
}
}));
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(facilities);
// add delete facilities button
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteFacilities());
tabMenu.addWidget(deleteButton);
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Facility> list = facilities.getTableSelectedList();
String text = "Following facilities will be deleted.";
UiElements.showDeleteConfirm(list, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
request.deleteFacility(list.get(i).getId());
} else {
DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton));
request.deleteFacility(list.get(i).getId());
}
}
}
});
}
});
// filter box
tabMenu.addFilterWidget(new ExtendedSuggestBox(facilities.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
facilities.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterFacilities());
deleteButton.setEnabled(false);
JsonUtils.addTableManagedButton(facilities, table, deleteButton);
// 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(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
firstTabPanel.setCellHeight(sp, "100%");
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations