use of cz.metacentrum.perun.webgui.json.facilitiesManager.RemoveHosts in project perun by CESNET.
the class FacilityHostsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts");
// main panel
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
final GetHosts hosts = new GetHosts(facilityId);
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(hosts);
// menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addHost(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new AddHostsTabItem(facility));
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeHosts());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Host> hostsForRemoving = hosts.getTableSelectedList();
String text = "<span class=\"serverResponseLabelError\"><strong>Removing host(s) won't stop services propagation. For this please remove proper 'Services destinations'.</strong></span><p>Following hosts will be removed from facility.";
UiElements.showDeleteConfirm(hostsForRemoving, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < hostsForRemoving.size(); i++) {
if (i == hostsForRemoving.size() - 1) {
RemoveHosts request = new RemoveHosts(facilityId, JsonCallbackEvents.disableButtonEvents(removeButton, events));
request.removeHost(hostsForRemoving.get(i).getId());
} else {
RemoveHosts request = new RemoveHosts(facilityId, JsonCallbackEvents.disableButtonEvents(removeButton));
request.removeHost(hostsForRemoving.get(i).getId());
}
}
}
});
}
});
menu.addWidget(removeButton);
menu.addFilterWidget(new ExtendedSuggestBox(hosts.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
hosts.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterHosts());
// Hosts table
CellTable<Host> table = hosts.getTable(new FieldUpdater<Host, String>() {
@Override
public void update(int index, Host object, String value) {
session.getTabManager().addTab(new FacilityHostsSettingsTabItem(facility, object));
}
});
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(hosts, table, removeButton);
// 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);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations