Search in sources :

Example 1 with RemoveHosts

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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RemoveHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.RemoveHosts) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Host(cz.metacentrum.perun.webgui.model.Host) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetHosts (cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts)1 RemoveHosts (cz.metacentrum.perun.webgui.json.facilitiesManager.RemoveHosts)1 Host (cz.metacentrum.perun.webgui.model.Host)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1