Search in sources :

Example 16 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class AddGroupManagerGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add manager group");
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    final TabMenu tabMenu = new TabMenu();
    final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
    // pass empty items to menu to ensure drawing of rest
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    tabMenu.addWidget(new HTML(""));
    tabMenu.addWidget(new HTML(""));
    tabMenu.addWidget(3, new HTML("<strong>Select VO:</strong>"));
    tabMenu.addWidget(4, box);
    // get the table
    final ScrollPanel sp = new ScrollPanel();
    sp.addStyleName("perun-tableScrollPanel");
    box.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
        }
    });
    if (box.getAllObjects().isEmpty()) {
        GetVos vos = new GetVos(new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                box.clear();
                ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
                if (list != null && !list.isEmpty()) {
                    box.addAllItems(list);
                    sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
                } else {
                    box.addItem("No VOs found");
                }
            }

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

            @Override
            public void onLoadingStart() {
                box.clear();
                box.addItem("Loading...");
            }
        });
        vos.retrieveData();
    }
    final TabItem tab = this;
    tabMenu.addWidget(2, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (refreshEvents != null)
                refreshEvents.onFinished(null);
            session.getTabManager().closeTab(tab, false);
        }
    }));
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "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) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 17 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class FacilityManagersTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Managers");
    // content
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // HORIZONTAL MENU
    final TabMenu menu = new TabMenu();
    final ListBox box = new ListBox();
    box.addItem("Users");
    box.addItem("Groups");
    box.setSelectedIndex(selectedDropDownIndex);
    final ScrollPanel sp = new ScrollPanel();
    sp.addStyleName("perun-tableScrollPanel");
    // request
    final GetRichAdminsWithAttributes admins = new GetRichAdminsWithAttributes(PerunEntity.FACILITY, facilityId, null);
    final GetAdminGroups adminGroups = new GetAdminGroups(PerunEntity.FACILITY, facilityId);
    box.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (box.getSelectedIndex() == 0) {
                selectedDropDownIndex = 0;
                sp.setWidget(fillContentUsers(admins, menu));
            } else {
                selectedDropDownIndex = 1;
                sp.setWidget(fillContentGroups(adminGroups, menu));
            }
        }
    });
    if (selectedDropDownIndex == 0) {
        sp.setWidget(fillContentUsers(admins, menu));
    } else {
        sp.setWidget(fillContentGroups(adminGroups, menu));
    }
    menu.addWidget(3, new HTML("<strong>Select mode: </strong>"));
    menu.addWidget(4, box);
    menu.addWidget(5, new Image(SmallIcons.INSTANCE.helpIcon()));
    menu.addWidget(6, new HTML("<strong>People with privilege to manage this facility in Perun. They aren't automatically \"roots\" on machine.</strong>"));
    session.getUiElements().resizePerunTable(sp, 350, this);
    // add menu and the table to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : GetRichAdminsWithAttributes(cz.metacentrum.perun.webgui.json.authzResolver.GetRichAdminsWithAttributes) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GetAdminGroups(cz.metacentrum.perun.webgui.json.authzResolver.GetAdminGroups) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu)

Example 18 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent 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)

Example 19 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class UserDetailTabItem method loadMemberSubContent.

private void loadMemberSubContent(final SimplePanel subContent, final Hyperlink voLabel, final ListBoxWithObjects<VirtualOrganization> listbox) {
    subContent.setWidget(new AjaxLoaderImage());
    final GetMemberByUser gmbu = new GetMemberByUser(listbox.getSelectedObject().getId(), user.getId());
    JsonCallbackEvents loadEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // get member
            final Member member = jso.cast();
            // create content panel and put it on page
            final VerticalPanel entryPanel = new VerticalPanel();
            entryPanel.setStyleName("perun-table");
            entryPanel.setSize("100%", "100%");
            subContent.setWidget(entryPanel);
            voLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + listbox.getSelectedObject().getName() + "</h2>"));
            voLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new VoDetailTabItem(listbox.getSelectedObject())));
            // detail header
            Widget memberHeader = new HTML("<h2>" + "Member details" + "</h2>");
            entryPanel.add(memberHeader);
            entryPanel.setCellHeight(memberHeader, "30px");
            // detail content
            FlexTable layout = new FlexTable();
            layout.setCellSpacing(6);
            // Add some standard form options
            layout.setHTML(0, 0, "<strong>Member&nbsp;ID:</strong>");
            layout.setHTML(0, 1, String.valueOf(member.getId()));
            ImageResource ir = null;
            // member status
            if (member.getStatus().equalsIgnoreCase("VALID")) {
                ir = SmallIcons.INSTANCE.acceptIcon();
            } else if (member.getStatus().equalsIgnoreCase("INVALID")) {
                ir = SmallIcons.INSTANCE.flagRedIcon();
            } else if (member.getStatus().equalsIgnoreCase("SUSPENDED")) {
                ir = SmallIcons.INSTANCE.stopIcon();
            } else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
                ir = SmallIcons.INSTANCE.flagYellowIcon();
            } else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
                ir = SmallIcons.INSTANCE.binClosedIcon();
            }
            HTML status = new HTML("<a>" + member.getStatus() + " " + new Image(ir) + "</a>");
            layout.setHTML(1, 0, "<strong>Member status: </strong>");
            layout.setWidget(1, 1, status);
            // member status - on click action
            status.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    FlexTable widget = new FlexTable();
                    final ListBox lb = new ListBox(false);
                    lb.addItem("VALID", "VALID");
                    lb.addItem("INVALID", "INVALID");
                    lb.addItem("SUSPENDED", "SUSPENDED");
                    lb.addItem("EXPIRED", "EXPIRED");
                    lb.addItem("DISABLED", "DISABLED");
                    widget.setHTML(0, 0, "<strong>Status: </strong>");
                    widget.setWidget(0, 1, lb);
                    // pick which one is already set
                    for (int i = 0; i < lb.getItemCount(); i++) {
                        if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
                            lb.setSelectedIndex(i);
                        }
                    }
                    Confirm conf = new Confirm("Change member's status", widget, true);
                    conf.setCancelButtonText("Cancel");
                    conf.setOkButtonText("Change status");
                    conf.setOkClickHandler(new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            SetStatus call = new SetStatus(member.getId(), new JsonCallbackEvents() {

                                @Override
                                public void onLoadingStart() {
                                    subContent.setWidget(new AjaxLoaderImage());
                                }

                                public void onFinished(JavaScriptObject jso) {
                                    subContent.setWidget(entryPanel);
                                    gmbu.retrieveData();
                                }

                                public void onError(PerunError error) {
                                    subContent.setWidget(entryPanel);
                                    gmbu.retrieveData();
                                }
                            });
                            call.setStatus(lb.getValue(lb.getSelectedIndex()));
                        }
                    });
                    conf.show();
                }
            });
            final ListBoxWithObjects<Resource> resList = new ListBoxWithObjects<Resource>();
            GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    resList.clear();
                    ArrayList<Resource> list = JsonUtils.jsoAsList(jso);
                    if (list == null || list.isEmpty()) {
                        resList.addItem("No resources found");
                    } else {
                        list = new TableSorter<Resource>().sortByName(list);
                        resList.addNotSelectedOption();
                        resList.addAllItems(list);
                    }
                }

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

                @Override
                public void onLoadingStart() {
                    resList.clear();
                    resList.addItem("Loading...");
                }
            });
            res.retrieveData();
            // link to member's detail
            Hyperlink link = new Hyperlink();
            link.setText("View detail");
            layout.setHTML(2, 0, "<strong>Member's detail page:</strong>");
            layout.setWidget(2, 1, link);
            link.setTargetHistoryToken(session.getTabManager().getLinkForTab(new MemberDetailTabItem(member.getId(), 0)));
            // wrap the content in a DecoratorPanel
            DecoratorPanel decPanel = new DecoratorPanel();
            decPanel.setWidget(layout);
            entryPanel.add(decPanel);
            entryPanel.setCellHeight(decPanel, "50px");
            // tables
            // detail header
            Widget groupHeader = new HTML("<h2>" + "Member groups" + "</h2>");
            entryPanel.add(groupHeader);
            entryPanel.setCellHeight(groupHeader, "30px");
            final GetMemberGroups groups = new GetMemberGroups(member.getId());
            groups.setCheckable(false);
            groups.setEditable(false);
            CellTable<Group> table = groups.getTable();
            table.addStyleName("perun-table");
            table.setWidth("100%");
            entryPanel.add(table);
            // detail header
            Widget attrHeader = new HTML("<h2>" + "Member / Member-resource attributes" + "</h2>");
            entryPanel.add(attrHeader);
            entryPanel.setCellHeight(attrHeader, "30px");
            final GetAttributesV2 attributes = new GetAttributesV2();
            attributes.getMemberAttributes(member.getId());
            resList.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    if (resList.getSelectedIndex() == 0) {
                        attributes.getMemberAttributes(member.getId());
                        attributes.retrieveData();
                    } else {
                        attributes.getMemberResourceAttributes(member.getId(), resList.getSelectedObject().getId());
                        attributes.retrieveData();
                    }
                }
            });
            TabMenu menu = new TabMenu();
            final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for member");
            saveAttrButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    ArrayList<Attribute> list = attributes.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        Map<String, Integer> ids = new HashMap<String, Integer>();
                        ids.put("member", member.getId());
                        if (resList.getSelectedIndex() > 0) {
                            ids.put("resource", resList.getSelectedObject().getId());
                        }
                        SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
                        request.setAttributes(ids, list);
                    }
                }
            });
            menu.addWidget(saveAttrButton);
            menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes for member", new ClickHandler() {

                public void onClick(ClickEvent event) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("member", member.getId());
                    if (resList.getSelectedIndex() > 0) {
                        ids.put("resource", resList.getSelectedObject().getId());
                    }
                    session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
                }
            }));
            final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from member");
            removeAttrButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    ArrayList<Attribute> list = attributes.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        Map<String, Integer> ids = new HashMap<String, Integer>();
                        ids.put("member", member.getId());
                        if (resList.getSelectedIndex() > 0) {
                            ids.put("resource", resList.getSelectedObject().getId());
                        }
                        RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
                        request.removeAttributes(ids, list);
                    }
                }
            });
            menu.addWidget(removeAttrButton);
            menu.addWidget(new HTML("<strong>Resource:</strong>"));
            menu.addWidget(resList);
            entryPanel.add(menu);
            CellTable<Attribute> attrTable = attributes.getTable();
            attrTable.addStyleName("perun-table");
            attrTable.setWidth("100%");
            entryPanel.add(attrTable);
        }

        @Override
        public void onError(PerunError error) {
            subContent.setWidget(new AjaxLoaderImage().loadingError(error));
        }
    };
    // set events & load data
    gmbu.setEvents(loadEvent);
    gmbu.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) ImageResource(com.google.gwt.resources.client.ImageResource) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetStatus(cz.metacentrum.perun.webgui.json.membersManager.SetStatus) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ImageResource(com.google.gwt.resources.client.ImageResource) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) GetAssignedResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources) HashMap(java.util.HashMap) Map(java.util.Map) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 20 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class ResourceMemberSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": member settings");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ListBoxWithObjects<RichMember> memberListBox = new ListBoxWithObjects<>();
    final ListBoxWithObjects<Service> serviceListBox = new ListBoxWithObjects<>();
    // load
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    // to get attributes for all services
    final GetResourceRequiredAttributesV2 resReqAttrs = new GetResourceRequiredAttributesV2();
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(resReqAttrs));
    // puts first table
    final CellTable<Attribute> table = resReqAttrs.getEmptyTable();
    // get assigned members
    final GetAssignedRichMembers members = new GetAssignedRichMembers(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            memberListBox.removeAllOption();
            memberListBox.clear();
            ArrayList<RichMember> grp = JsonUtils.jsoAsList(jso);
            grp = new TableSorter<RichMember>().sortByName(grp);
            if (grp == null || grp.isEmpty()) {
                memberListBox.addItem("No members assigned");
                lastSelectedMember = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see member-resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            memberListBox.addAllItems(grp);
            for (RichMember g : memberListBox.getAllObjects()) {
                if (lastSelectedMember != 0 && g.getId() == lastSelectedMember)
                    memberListBox.setSelected(g, true);
            }
            memberCallDone = true;
            if (lastSelectedService == 0) {
                // load resource-required
                if (servCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                // load resource-service-member
                if (servCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            memberListBox.removeAllOption();
            memberListBox.clear();
            memberListBox.addItem("Error while loading");
            memberCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            memberListBox.removeAllOption();
            memberListBox.clear();
            memberListBox.addItem("Loading...");
            memberCallDone = false;
        }
    });
    members.retrieveData();
    GetAssignedServices services = new GetAssignedServices(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            if (srv == null || srv.isEmpty()) {
                serviceListBox.addItem("No services assigned");
                lastSelectedService = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see member-resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            serviceListBox.addAllItems(srv);
            serviceListBox.addAllOption();
            if (lastSelectedService == 0)
                serviceListBox.setSelectedIndex(0);
            for (Service s : serviceListBox.getAllObjects()) {
                if (lastSelectedService != 0 && s.getId() == lastSelectedService)
                    serviceListBox.setSelected(s, true);
            }
            servCallDone = true;
            if (lastSelectedService == 0) {
                if (memberCallDone) {
                    // load resource-required
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (memberCallDone) {
                    // load resource-service-member
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Error while loading");
            servCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Loading...");
            servCallDone = false;
        }
    });
    services.retrieveData();
    ChangeHandler changeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (memberCallDone && servCallDone) {
                if (memberListBox.getSelectedObject() != null) {
                    lastSelectedMember = memberListBox.getSelectedObject().getId();
                } else {
                    lastSelectedMember = 0;
                }
                if (serviceListBox.getSelectedIndex() > 0) {
                    lastSelectedService = serviceListBox.getSelectedObject().getId();
                } else {
                    lastSelectedService = 0;
                }
                if (lastSelectedService == 0) {
                    // load resource-required
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                } else {
                    // load resource-service-member
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("member", memberListBox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }
    };
    memberListBox.addChangeHandler(changeHandler);
    serviceListBox.addChangeHandler(changeHandler);
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resReqAttrs);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resReqAttrs.setCheckable(false);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("member", memberListBox.getSelectedObject().getId());
                ids.put("workWithUserAttributes", 1);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            ids.put("member", memberListBox.getSelectedObject().getId());
            ids.put("user", memberListBox.getSelectedObject().getUserId());
            ids.put("facility", resource.getFacilityId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, resReqAttrs.getList()), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    menu.addWidget(setNewAttributeButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("member", memberListBox.getSelectedObject().getId());
                ids.put("facility", resource.getFacilityId());
                ids.put("user", memberListBox.getSelectedObject().getUserId());
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add member selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;member: </strong>"));
    menu.addWidget(memberListBox);
    // add service selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
    menu.addWidget(serviceListBox);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) 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) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAssignedRichMembers(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedRichMembers) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)58 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)58 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)31 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)31 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)31 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)28 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)27 ArrayList (java.util.ArrayList)21 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)20 PerunError (cz.metacentrum.perun.webgui.model.PerunError)16 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)15 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)13 HashMap (java.util.HashMap)10 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)8 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)8 Map (java.util.Map)7 GetVos (cz.metacentrum.perun.webgui.json.vosManager.GetVos)6 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)6 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)6 ListBox (com.google.gwt.user.client.ui.ListBox)5