Search in sources :

Example 1 with GetHosts

use of cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts in project perun by CESNET.

the class AddFacilityDestinationTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add destination");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    layout.setWidth("350px");
    final ExtendedSuggestBox destination = new ExtendedSuggestBox();
    final ListBox type = new ListBox();
    type.addItem("HOST", "host");
    type.addItem("USER@HOST", "user@host");
    type.addItem("USER@HOST:PORT", "user@host:port");
    type.addItem("URL", "url");
    type.addItem("MAIL", "email");
    type.addItem("SIGNED MAIL", "semail");
    type.addItem("SERVICE SPECIFIC", "service-specific");
    final ListBoxWithObjects<Service> services = new ListBoxWithObjects<Service>();
    final CheckBox useHosts = new CheckBox(WidgetTranslation.INSTANCE.useFacilityHostnames(), false);
    useHosts.setTitle(WidgetTranslation.INSTANCE.useFacilityHostnamesTitle());
    final CheckBox onlyAssignedServices = new CheckBox("Show only services on facility", false);
    onlyAssignedServices.setTitle("Click to show all possible services");
    onlyAssignedServices.setValue(true);
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDestination());
    // fill oracle with hosts of facility
    GetHosts getHosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Host> ho = JsonUtils.jsoAsList(jso);
            for (Host h : ho) {
                hosts.addAll(ho);
                destination.getSuggestOracle().add(h.getName());
            }
        }
    });
    getHosts.retrieveData();
    JsonCallbackEvents fillAssignedServices = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            services.removeAllOption();
            services.clear();
            ArrayList<Service> ses = JsonUtils.jsoAsList(jso);
            if (ses != null && !ses.isEmpty()) {
                ses = new TableSorter<Service>().sortByName(ses);
                services.addAllItems(ses);
                services.addAllOption();
                services.setSelectedIndex(0);
            } else {
                services.addItem("No service available");
            }
            addButton.setEnabled(true);
            type.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            services.removeAllOption();
            services.clear();
            services.addItem("Error while loading");
            addButton.setEnabled(true);
            type.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            services.removeAllOption();
            services.clear();
            services.addItem("Loading...");
            addButton.setEnabled(false);
            type.setEnabled(false);
        }
    };
    final GetFacilityAssignedServices getAssignedServices = new GetFacilityAssignedServices(facility.getId(), fillAssignedServices);
    getAssignedServices.retrieveData();
    final GetServices getAllServices = new GetServices(fillAssignedServices);
    onlyAssignedServices.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (onlyAssignedServices.getValue() == false) {
                onlyAssignedServices.setTitle("Click to show only services on facility");
                getAllServices.retrieveData();
            } else {
                onlyAssignedServices.setTitle("Click to show all possible services");
                getAssignedServices.retrieveData();
            }
        }
    });
    final Label destinationLabel = new Label();
    destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
    final ExtendedSuggestBox.SuggestBoxValidator validator = new ExtendedSuggestBox.SuggestBoxValidator() {

        @Override
        public boolean validateSuggestBox() {
            if (destination.getSuggestBox().getText().trim().isEmpty() && useHosts.getValue() == false) {
                destination.setError("Destination value can't be empty.");
                return false;
            }
            // check as email
            if (type.getSelectedIndex() > 3 && type.getSelectedIndex() < 6) {
                if (!JsonUtils.isValidEmail(destination.getSuggestBox().getText().trim())) {
                    destination.setError("Not valid email address.");
                    return false;
                } else {
                    destination.setOk();
                    return true;
                }
            }
            destination.setOk();
            return true;
        }
    };
    destination.setValidator(validator);
    type.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // if hosts - checkbox visible
            if (type.getSelectedIndex() == 0) {
                useHosts.setVisible(true);
            } else {
                useHosts.setVisible(false);
                useHosts.setValue(false);
                destination.getSuggestBox().setEnabled(true);
            }
            if (type.getSelectedIndex() < 3) {
                destination.getSuggestOracle().clear();
                for (Host h : hosts) {
                    destination.getSuggestOracle().add(h.getName());
                }
            } else {
                destination.getSuggestOracle().clear();
            }
            // set label
            if (type.getSelectedIndex() == 0) {
                destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
            } else if (type.getSelectedIndex() == 1) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host:</strong>");
            } else if (type.getSelectedIndex() == 2) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host:port:</strong>");
            } else if (type.getSelectedIndex() == 3) {
                destinationLabel.getElement().setInnerHTML("<strong>URL:</strong>");
            } else if (type.getSelectedIndex() == 4) {
                destinationLabel.getElement().setInnerHTML("<strong>Mail:</strong>");
            } else if (type.getSelectedIndex() == 5) {
                destinationLabel.getElement().setInnerHTML("<strong>Signed mail:</strong>");
            } else if (type.getSelectedIndex() == 6) {
                destinationLabel.getElement().setInnerHTML("<strong>Service specific:</strong>");
            }
            // run validation
            validator.validateSuggestBox();
        }
    });
    useHosts.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (useHosts.getValue() == true) {
                destination.getSuggestBox().setEnabled(false);
                destination.setOk();
            } else {
                destination.getSuggestBox().setEnabled(true);
            }
        }
    });
    cellFormatter.setColSpan(0, 0, 2);
    HTML text = new HTML("Please add destinations for service configuration delivery. New service configuration can be performed directly on facility (dest. type HOST) or sent to URL or by an email.");
    text.setStyleName("inputFormInlineComment");
    layout.setWidget(0, 0, text);
    layout.setHTML(1, 0, "Service:");
    layout.setWidget(1, 1, services);
    layout.setWidget(2, 1, onlyAssignedServices);
    layout.setHTML(3, 0, "Type:");
    layout.setWidget(3, 1, type);
    layout.setWidget(4, 0, destinationLabel);
    layout.setWidget(4, 1, destination);
    layout.setWidget(5, 1, useHosts);
    for (int i = 1; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    menu.addWidget(addButton);
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (services.isEmpty()) {
                // no services available
                addButton.setEnabled(false);
            }
            if (validator.validateSuggestBox()) {
                if (services.getSelectedIndex() == 0) {
                    // selected all
                    if (useHosts.getValue() == true) {
                        // auto by hosts
                        AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestinationByHosts(services.getAllObjects());
                    } else {
                        // default
                        AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getAllObjects());
                    }
                } else {
                    // selected one
                    if (useHosts.getValue() == true) {
                        // auto by hosts
                        AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestinationByHosts(services.getSelectedObject());
                    } else {
                        // default
                        AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getSelectedObject());
                    }
                }
            }
        }
    });
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) TableSorter(cz.metacentrum.perun.webgui.client.resources.TableSorter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Service(cz.metacentrum.perun.webgui.model.Service) Host(cz.metacentrum.perun.webgui.model.Host) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 2 with GetHosts

use of cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts in project perun by CESNET.

the class FacilityHostsSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
    // main panel
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    final GetAttributesV2 attrs = new GetAttributesV2();
    final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
    // refresh attributes for hosts
    listbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (listbox.getSelectedObject() != null) {
                lastSelectedHostId = listbox.getSelectedObject().getId();
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            } else {
                lastSelectedHostId = 0;
            }
        }
    });
    // retrieve hosts
    final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listbox.clear();
            ArrayList<Host> result = JsonUtils.jsoAsList(jso);
            if (result != null && !result.isEmpty()) {
                for (Host h : result) {
                    listbox.addItem(h);
                    if (h.getId() == lastSelectedHostId) {
                        listbox.setSelected(h, true);
                    }
                }
                if (lastSelectedHostId == 0) {
                    lastSelectedHostId = listbox.getSelectedObject().getId();
                }
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            }
        }

        @Override
        public void onError(PerunError error) {
            listbox.clear();
            listbox.addItem("Error while loading");
        }

        @Override
        public void onLoadingStart() {
            listbox.clear();
            listbox.addItem("Loading...");
        }
    });
    hosts.retrieveData();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
    // menu
    TabMenu menu = new TabMenu();
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("host", lastSelectedHostId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
        }
    }));
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Select host:</strong>"));
    menu.addWidget(listbox);
    // attrs table
    CellTable<Attribute> table = attrs.getEmptyTable();
    // 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) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) Host(cz.metacentrum.perun.webgui.model.Host) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 3 with GetHosts

use of cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts 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)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetHosts (cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts)3 Host (cz.metacentrum.perun.webgui.model.Host)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ArrayList (java.util.ArrayList)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 TableSorter (cz.metacentrum.perun.webgui.client.resources.TableSorter)1 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)1 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)1 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)1 RemoveHosts (cz.metacentrum.perun.webgui.json.facilitiesManager.RemoveHosts)1 Attribute (cz.metacentrum.perun.webgui.model.Attribute)1