Search in sources :

Example 1 with GetAllowedGroups

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

the class FacilityAllowedGroupsTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Allowed Groups");
    final ListBoxWithObjects<VirtualOrganization> vosListbox = new ListBoxWithObjects<VirtualOrganization>();
    final ListBoxWithObjects<Service> servicesListbox = new ListBoxWithObjects<Service>();
    final GetAllowedGroups jsonCallback = new GetAllowedGroups(facilityId);
    jsonCallback.setCheckable(false);
    // content
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(new HTML("<strong>Filter by VO:</strong>"));
    menu.addWidget(vosListbox);
    menu.addWidget(new HTML("<strong>Filter by service:</strong>"));
    menu.addWidget(servicesListbox);
    // get the table
    final GetAllowedVos vosCall = new GetAllowedVos(facilityId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosListbox.clear();
            vosListbox.removeAllOption();
            vosListbox.addAllItems(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
            vosListbox.addAllOption();
            if (lastSelectedVoId == 0) {
                vosListbox.setSelectedIndex(0);
            } else {
                for (VirtualOrganization vo : vosListbox.getAllObjects()) {
                    if (vo.getId() == lastSelectedVoId) {
                        vosListbox.setSelected(vo, true);
                        break;
                    }
                }
            }
            jsonCallback.setVos(vosListbox.getAllObjects());
            vosCallDone = true;
        }

        public void onLoadingStart() {
            vosListbox.removeAllOption();
            vosListbox.clear();
            vosListbox.addItem("Loading...");
            vosCallDone = false;
        }

        public void onError(PerunError error) {
            vosListbox.clear();
            vosListbox.removeAllOption();
            vosListbox.addItem("Error while loading");
            vosCallDone = false;
        }
    });
    vosCall.retrieveData();
    GetFacilityAssignedServices servCall = new GetFacilityAssignedServices(facilityId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            servicesListbox.clear();
            servicesListbox.removeAllOption();
            servicesListbox.addAllItems(new TableSorter<Service>().sortByName(JsonUtils.<Service>jsoAsList(jso)));
            servicesListbox.addAllOption();
            if (servicesListbox.isEmpty()) {
                servicesListbox.addItem("No service available on facility");
            }
            if (lastSelectedServiceId == 0) {
                // choose all
                servicesListbox.setSelectedIndex(0);
            } else {
                for (Service s : servicesListbox.getAllObjects()) {
                    if (s.getId() == lastSelectedServiceId) {
                        servicesListbox.setSelected(s, true);
                        break;
                    }
                }
            }
            callDone = true;
        }

        public void onLoadingStart() {
            servicesListbox.removeAllOption();
            servicesListbox.clear();
            servicesListbox.addItem("Loading...");
            callDone = false;
        }

        public void onError(PerunError error) {
            servicesListbox.clear();
            servicesListbox.removeAllOption();
            servicesListbox.addItem("Error while loading");
            callDone = false;
        }
    });
    servCall.retrieveData();
    Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {

        @Override
        public boolean execute() {
            if (vosCallDone && callDone) {
                jsonCallback.setVoId(lastSelectedVoId);
                jsonCallback.setServiceId(lastSelectedServiceId);
                jsonCallback.retrieveData();
                return false;
            } else {
                return true;
            }
        }
    }, 200);
    vosListbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (vosListbox.getSelectedIndex() > 0) {
                jsonCallback.setVoId(vosListbox.getSelectedObject().getId());
                lastSelectedVoId = vosListbox.getSelectedObject().getId();
            } else {
                jsonCallback.setVoId(0);
                lastSelectedVoId = 0;
            }
            jsonCallback.retrieveData();
        }
    });
    servicesListbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (servicesListbox.getSelectedIndex() > 0) {
                jsonCallback.setServiceId(servicesListbox.getSelectedObject().getId());
                lastSelectedServiceId = servicesListbox.getSelectedObject().getId();
            } else {
                jsonCallback.setServiceId(0);
                lastSelectedServiceId = 0;
            }
            jsonCallback.retrieveData();
        }
    });
    CellTable<Group> table = jsonCallback.getEmptyTable(new FieldUpdater<Group, String>() {

        @Override
        public void update(int i, Group group, String s) {
            if (session.isVoAdmin(group.getVoId()) || session.isGroupAdmin(group.getId())) {
                session.getTabManager().addTab(new GroupDetailTabItem(group));
            } else {
                // show alert
                UiElements.generateInfo("You are not VO / Group manager of this group", "You MUST be VO manager or Group manager of group: <strong>" + group.getName() + "</strong> to view it's details.");
            }
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : GetAllowedGroups(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedGroups) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Scheduler(com.google.gwt.core.client.Scheduler) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GetAllowedVos(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedVos) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetFacilityAssignedServices(cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Scheduler (com.google.gwt.core.client.Scheduler)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetAllowedGroups (cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedGroups)1 GetAllowedVos (cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedVos)1 GetFacilityAssignedServices (cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices)1 GroupDetailTabItem (cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1