Search in sources :

Example 1 with OpenEvent

use of com.google.gwt.event.logical.shared.OpenEvent in project perun by CESNET.

the class SelfResourcesSettingsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Resources settings");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ScrollPanel scroll = new ScrollPanel();
    scroll.setWidget(vp);
    scroll.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(scroll, 350, this);
    scroll.setWidth("100%");
    final AjaxLoaderImage loader = new AjaxLoaderImage();
    // RETRIEVES ALL VOS WHERE USER IS A MEMBER
    GetVosWhereUserIsMember vosRequest = new GetVosWhereUserIsMember(userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vp.getWidget(1).removeFromParent();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            // if vos length = 1, load immediately all resources
            final boolean loadImmediately = (vos.size() == 1);
            // FOR EACH VO, FIND THE MEMBER
            for (final VirtualOrganization innerVo : vos) {
                final FlexTable header = new FlexTable();
                header.setWidth("100%");
                header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.buildingIcon()));
                header.getFlexCellFormatter().setWidth(0, 0, "40px");
                Anchor a = new Anchor("<p class=\"now-managing disclosurePanelHeader\">" + innerVo.getName() + "</p>", true);
                header.setWidget(0, 1, a);
                header.setTitle("Click to show resources for " + innerVo.getName());
                // disclosure panel
                final DisclosurePanel settings = new DisclosurePanel();
                settings.setWidth("100%");
                settings.setHeader(header);
                // load content on open
                settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {

                    public void onOpen(OpenEvent<DisclosurePanel> event) {
                        if (settings.getContent() == null) {
                            GetMemberByUser memberRequest = new GetMemberByUser(innerVo.getId(), userId, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    Member member = jso.cast();
                                    // set content
                                    settings.setContent(userSettingsForVo(innerVo, member));
                                }
                            });
                            memberRequest.retrieveData();
                        }
                    }
                });
                vp.add(settings);
                settings.setOpen((vos.size() == 1) || (vo != null && vo.getId() == innerVo.getId()));
            }
        }

        @Override
        public void onLoadingStart() {
            vp.add(loader);
        }

        @Override
        public void onError(PerunError error) {
            loader.loadingError(error);
        }
    });
    vosRequest.retrieveData();
    this.contentWidget.setWidget(scroll);
    return getWidget();
}
Also used : GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ArrayList(java.util.ArrayList) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) OpenHandler(com.google.gwt.event.logical.shared.OpenHandler) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) OpenEvent(com.google.gwt.event.logical.shared.OpenEvent)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 OpenEvent (com.google.gwt.event.logical.shared.OpenEvent)1 OpenHandler (com.google.gwt.event.logical.shared.OpenHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetMemberByUser (cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser)1 GetVosWhereUserIsMember (cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember)1 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1