Search in sources :

Example 1 with RemoveDestination

use of cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination in project perun by CESNET.

the class FacilityDestinationsTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Destinations");
    // main content
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    final TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    //callback
    final GetAllRichDestinations callback = new GetAllRichDestinations(facility, null);
    // do not make callback yet
    final CellTable<Destination> table = callback.getTable();
    // refresh table events
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
    // style table
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    menu.addWidget(UiElements.getRefreshButton(this));
    // buttons
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addDestination(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddFacilityDestinationTabItem(facility));
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDestinations());
    menu.addWidget(removeButton);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Destination> destForRemoving = callback.getTableSelectedList();
            String text = "<span class=\"serverResponseLabelError\"><strong>Removing destination will stop propagation of service's configuration for this destination/service.</strong></span><p>Following destinations will be removed.";
            UiElements.showDeleteConfirm(destForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < destForRemoving.size(); i++) {
                        if (i == destForRemoving.size() - 1) {
                            RemoveDestination request = new RemoveDestination(facility.getId(), destForRemoving.get(i).getService().getId(), JsonCallbackEvents.disableButtonEvents(removeButton, events));
                            request.removeDestination(destForRemoving.get(i).getDestination(), destForRemoving.get(i).getType());
                        } else {
                            RemoveDestination request = new RemoveDestination(facility.getId(), destForRemoving.get(i).getService().getId(), JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.removeDestination(destForRemoving.get(i).getDestination(), destForRemoving.get(i).getType());
                        }
                    }
                }
            });
        }
    });
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    // filter box
    menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            callback.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterDestination());
    menu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
    menu.addWidget(new HTML("<strong>Destinations define, where service's configuration is propagated.</strong>"));
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RemoveDestination(cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination) Destination(cz.metacentrum.perun.webgui.model.Destination) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllRichDestinations(cz.metacentrum.perun.webgui.json.servicesManager.GetAllRichDestinations) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) RemoveDestination(cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination)

Example 2 with RemoveDestination

use of cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination in project perun by CESNET.

the class ServiceDestinationsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Service destinations");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // Adds menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // buttons
    final CustomButton addDestButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addDestination());
    final CustomButton removeDestButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDestinations());
    menu.addWidget(addDestButton);
    menu.addWidget(removeDestButton);
    menu.addWidget(new HTML("<strong>Selected facility:</strong>"));
    // listbox with facilities
    final ListBoxWithObjects<Facility> ls = new ListBoxWithObjects<Facility>();
    menu.addWidget(ls);
    // get empty table used for destinations
    final GetAllRichDestinations callback = new GetAllRichDestinations(null, service);
    callback.showFacilityColumn(true);
    callback.showServiceColumn(false);
    // do not make callback yet
    final CellTable<Destination> table = callback.getEmptyTable();
    if (lastSelectedFacilityId == 0) {
        callback.retrieveData();
    }
    // refresh events called when selection changes or callback ends
    final JsonCallbackEvents refreshEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            if (ls.getSelectedIndex() == 0) {
                // fills table with destinations of all facilities
                callback.clearTable();
                callback.retrieveData();
            } else {
                callback.clearTable();
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
                // fills table with destinations of selected facility
                JsonCallbackEvents localEvents = new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        JsArray<Destination> dst = JsonUtils.jsoAsArray(jso);
                        for (int i = 0; i < dst.length(); i++) {
                            callback.addToTable(dst.get(i));
                        }
                        ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                    }

                    public void onError(PerunError error) {
                        ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
                    }
                };
                final GetDestinations callback = new GetDestinations(ls.getSelectedObject(), service, localEvents);
                callback.retrieveData();
            }
        }
    };
    // fills listbox and table with dest. for all service facilities
    JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            ls.clear();
            ArrayList<Facility> facs = JsonUtils.jsoAsList(jso);
            facs = new TableSorter<Facility>().sortByName(facs);
            // if no facility
            if (facs.size() == 0) {
                ls.addItem("No facility available");
                return;
            }
            for (int i = 0; i < facs.size(); i++) {
                ls.addItem(facs.get(i));
                if (facs.get(i).getId() == lastSelectedFacilityId) {
                    ls.setSelected(facs.get(i), true);
                }
            }
            ls.addAllOption();
            if (lastSelectedFacilityId == 0) {
                // select all
                ls.setItemSelected(0, true);
            } else {
                // was selected
                addDestButton.setEnabled(true);
                refreshEvents.onFinished(null);
            }
        }

        public void onError(PerunError error) {
            ls.addItem("Error while loading");
            addDestButton.setEnabled(false);
        }

        public void onLoadingStart() {
            ls.clear();
            ls.addItem("Loading...");
            addDestButton.setEnabled(false);
        }
    };
    final GetAssignedFacilities assignedFacilities = new GetAssignedFacilities(PerunEntity.SERVICE, serviceId, events);
    assignedFacilities.retrieveData();
    ls.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            if (ls.getSelectedIndex() > 0) {
                // store last selected facility id
                addDestButton.setEnabled(true);
                lastSelectedFacilityId = ls.getSelectedObject().getId();
            } else {
                addDestButton.setEnabled(false);
                lastSelectedFacilityId = 0;
            }
            refreshEvents.onFinished(null);
        }
    });
    // CLICK HANDLERS FOR BUTTONS
    addDestButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddFacilityDestinationTabItem(ls.getSelectedObject()));
        }
    });
    removeDestButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // get
            final ArrayList<Destination> destsToRemove = callback.getTableSelectedList();
            UiElements.showDeleteConfirm(destsToRemove, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < destsToRemove.size(); i++) {
                        if (i == destsToRemove.size() - 1) {
                            RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton, refreshEvents));
                            request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
                        } else {
                            RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton));
                            request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
                        }
                    }
                }
            });
        }
    });
    // filter box
    menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            callback.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterDestinationByFacility());
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    removeDestButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeDestButton);
    // add tabs to the main panel
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RemoveDestination(cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination) Destination(cz.metacentrum.perun.webgui.model.Destination) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllRichDestinations(cz.metacentrum.perun.webgui.json.servicesManager.GetAllRichDestinations) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAssignedFacilities(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAssignedFacilities) AddFacilityDestinationTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.AddFacilityDestinationTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Facility(cz.metacentrum.perun.webgui.model.Facility) PerunError(cz.metacentrum.perun.webgui.model.PerunError) GetDestinations(cz.metacentrum.perun.webgui.json.servicesManager.GetDestinations) RemoveDestination(cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 GetAllRichDestinations (cz.metacentrum.perun.webgui.json.servicesManager.GetAllRichDestinations)2 RemoveDestination (cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination)2 Destination (cz.metacentrum.perun.webgui.model.Destination)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 ArrayList (java.util.ArrayList)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 GetAssignedFacilities (cz.metacentrum.perun.webgui.json.facilitiesManager.GetAssignedFacilities)1 GetDestinations (cz.metacentrum.perun.webgui.json.servicesManager.GetDestinations)1 Facility (cz.metacentrum.perun.webgui.model.Facility)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 AddFacilityDestinationTabItem (cz.metacentrum.perun.webgui.tabs.facilitiestabs.AddFacilityDestinationTabItem)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1