Search in sources :

Example 26 with FieldUpdater

use of com.google.gwt.cell.client.FieldUpdater in project perun by CESNET.

the class MemberServiceUsersTabItem method draw.

public Widget draw() {
    if (member.getUser().isServiceUser()) {
        this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(member.getUser().getFullNameWithTitles().trim()) + ": associated users");
    } else {
        this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(member.getUser().getFullNameWithTitles().trim()) + ": service identities");
    }
    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));
    if (member.getUser().isServiceUser()) {
        // request
        final GetUsersBySpecificUser request = new GetUsersBySpecificUser(member.getUserId());
        request.setCheckable(false);
        // table
        CellTable<User> table;
        if (session.isPerunAdmin()) {
            table = request.getTable(new FieldUpdater<User, String>() {

                public void update(int i, User user, String s) {
                    session.getTabManager().addTab(new UserDetailTabItem(user));
                }
            });
        } else {
            table = request.getTable();
        }
        table.addStyleName("perun-table");
        table.setWidth("100%");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        vp.add(sp);
    } else {
        final GetSpecificUsersByUser request = new GetSpecificUsersByUser(member.getUserId());
        request.setCheckable(false);
        request.setHideSponsored(true);
        // table
        CellTable<User> table;
        if (session.isPerunAdmin()) {
            table = request.getTable(new FieldUpdater<User, String>() {

                public void update(int i, User user, String s) {
                    session.getTabManager().addTab(new UserDetailTabItem(user));
                }
            });
        } else {
            table = request.getTable();
        }
        table.addStyleName("perun-table");
        table.setWidth("100%");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        vp.add(sp);
    }
    contentWidget.setWidget(vp);
    return getWidget();
}
Also used : FieldUpdater(com.google.gwt.cell.client.FieldUpdater) GetUsersBySpecificUser(cz.metacentrum.perun.webgui.json.usersManager.GetUsersBySpecificUser) User(cz.metacentrum.perun.webgui.model.User) GetSpecificUsersByUser(cz.metacentrum.perun.webgui.json.usersManager.GetSpecificUsersByUser) GetSpecificUsersByUser(cz.metacentrum.perun.webgui.json.usersManager.GetSpecificUsersByUser) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) GetUsersBySpecificUser(cz.metacentrum.perun.webgui.json.usersManager.GetUsersBySpecificUser) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu)

Example 27 with FieldUpdater

use of com.google.gwt.cell.client.FieldUpdater in project perun by CESNET.

the class ResourceAssignedServicesTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": manage assigned services");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    final GetAssignedServices resourceServices = new GetAssignedServices(resourceId);
    final JsonCallbackEvents localEvents = JsonCallbackEvents.refreshTableEvents(resourceServices);
    CustomButton assignServicesButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignServiceToResource(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AssignServiceTabItem(resourceId), true);
        }
    });
    final CustomButton removeServicesButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeServiceFromResource());
    removeServicesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Service> servicesForRemoving = resourceServices.getTableSelectedList();
            String text = "Following services will be removed from resource.";
            UiElements.showDeleteConfirm(servicesForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD USE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < servicesForRemoving.size(); i++) {
                        if (i == servicesForRemoving.size() - 1) {
                            RemoveService request = new RemoveService(JsonCallbackEvents.disableButtonEvents(removeServicesButton, localEvents));
                            request.removeService(servicesForRemoving.get(i).getId(), resourceId);
                        } else {
                            RemoveService request = new RemoveService(JsonCallbackEvents.disableButtonEvents(removeServicesButton));
                            request.removeService(servicesForRemoving.get(i).getId(), resourceId);
                        }
                    }
                }
            });
        }
    });
    menu.addWidget(assignServicesButton);
    menu.addWidget(removeServicesButton);
    menu.addFilterWidget(new ExtendedSuggestBox(resourceServices.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            resourceServices.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterServices());
    // display menu only to facility admin
    if (session.isFacilityAdmin(resource.getFacilityId())) {
        resourceServices.setCheckable(true);
        vp.add(menu);
        vp.setCellHeight(menu, "30px");
    } else {
        resourceServices.setCheckable(false);
    }
    CellTable<Service> table;
    if (session.isPerunAdmin()) {
        table = resourceServices.getTable(new FieldUpdater<Service, String>() {

            public void update(int index, Service object, String value) {
                // load detail only for perun admin
                session.getTabManager().addTab(new ServiceDetailTabItem(object));
            }
        });
    } else {
        // not clickable
        table = resourceServices.getTable();
    }
    removeServicesButton.setEnabled(false);
    JsonUtils.addTableManagedButton(resourceServices, table, removeServicesButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 400, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ServiceDetailTabItem(cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.webgui.model.Service) RemoveService(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RemoveService(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 28 with FieldUpdater

use of com.google.gwt.cell.client.FieldUpdater in project perun by CESNET.

the class GroupMembersTabItem method draw.

public Widget draw() {
    // SET TAB NAME
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": members");
    // MAIN PANEL
    final VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // MENU
    final TabMenu tabMenu = new TabMenu();
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // DISABLED CHECKBOX
    final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
    disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
    disabled.setValue(wasDisabled);
    // CALLBACKS
    final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.GROUP, groupId, null);
    final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.GROUP, groupId, "", null);
    members.excludeDisabled(!wasDisabled);
    members.setIndirectCheckable(false);
    findMembers.setIndirectCheckable(false);
    final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInGroup());
    final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInGroup());
    if ((!session.isVoAdmin(group.getVoId()) && !session.isGroupAdmin(groupId)) || group.isCoreGroup()) {
        findMembers.setCheckable(false);
    }
    table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {

        // when user click on a row -> open new tab
        public void update(int index, RichMember object, RichMember value) {
            session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), groupId));
        }
    });
    tableWidget = table.getEmptyTableWidget();
    // refresh
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // ADD
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToGroup(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddMemberToGroupTabItem(groupId), true);
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        addButton.setEnabled(false);
    CustomButton inviteButton = new CustomButton("Invite member…", SmallIcons.INSTANCE.emailAddIcon(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new InviteUserTabItem(group.getVoId(), group));
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        inviteButton.setEnabled(false);
    // REMOVE
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromGroup());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        removeButton.setEnabled(false);
    if (!group.isCoreGroup()) {
        tabMenu.addWidget(addButton);
        tabMenu.addWidget(inviteButton);
        tabMenu.addWidget(removeButton);
    }
    // refreshMembers
    final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (search) {
                findMembers.searchFor(searchString);
            } else {
                findMembers.clearTable();
                members.retrieveData();
            }
        }
    };
    // add click handler for remove button
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // state specific events
            final ArrayList<RichMember> membersForRemoving = findMembers.getTableSelectedList();
            String text = "Following members will be removed from group. They will lose access to resources provided by this group.";
            UiElements.showDeleteConfirm(membersForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < membersForRemoving.size(); i++) {
                        RemoveMember request;
                        if (i == membersForRemoving.size() - 1) {
                            request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
                        } else {
                            request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.removeMemberFromGroup(group, membersForRemoving.get(i));
                    }
                }
            });
        }
    });
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        public void searchFor(String text) {
            table.setEmptyTableWidget(tableWidget);
            searchString = text;
            search = true;
            findMembers.searchFor(text);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // checkbox click handler
    disabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            wasDisabled = disabled.getValue();
            if (search) {
                // case when update but not triggered by button
                searchString = searchBox.getTextBox().getText();
                members.excludeDisabled(!disabled.getValue());
            } else {
                members.excludeDisabled(!disabled.getValue());
                members.retrieveData();
            }
        }
    });
    findMembers.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
            listAllButton.setEnabled(false);
            disabled.setVisible(false);
        }
    }));
    members.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(listAllButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // pass data to table handling callback
            findMembers.onFinished(jso);
            ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("Group has no members.");
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            // pass data to table handling callback
            findMembers.onError(error);
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            table.setEmptyTableWidget(tableWidget);
            searchBox.getTextBox().setEnabled(false);
            searchButton.setEnabled(false);
            disabled.setVisible(true);
            // to show progress when reloading
            ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
        }
    }));
    // LIST ALL BUTTON
    listAllButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            table.setEmptyTableWidget(tableWidget);
            search = false;
            searchString = "";
            searchBox.getTextBox().setText("");
            findMembers.clearTable();
            members.retrieveData();
        }
    });
    tabMenu.addWidget(listAllButton);
    tabMenu.addWidget(disabled);
    /* WHEN TAB RELOADS, CHECK THE STATE */
    if (search) {
        findMembers.searchFor(searchString);
    } else {
        GetGroupMembersCount count = new GetGroupMembersCount(groupId, new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                int membersCount = ((BasicOverlayType) jso.cast()).getInt();
                if (membersCount > 1000) {
                    FlexTable panel = new FlexTable();
                    panel.setSize("100%", "150px");
                    HTML label = new HTML();
                    label.setHTML("<h2>Group has " + membersCount + " members. We suggest you to use search instead.</h2><h2>You can search member by name, login, email or click List all to see all members.</h2>");
                    panel.setWidget(0, 0, label);
                    panel.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    table.setEmptyTableWidget(panel);
                } else {
                    // load all members
                    members.excludeDisabled(!disabled.getValue());
                    members.retrieveData();
                }
                onceAsked = true;
            }

            @Override
            public void onError(PerunError error) {
                // load all members
                members.excludeDisabled(!disabled.getValue());
                members.retrieveData();
            }

            @Override
            public void onLoadingStart() {
            }
        });
        if (!onceAsked) {
            count.retrieveData();
        } else {
            // load all members
            members.excludeDisabled(!disabled.getValue());
            members.retrieveData();
        }
    }
    ScrollPanel tableWrapper = new ScrollPanel();
    table.addStyleName("perun-table");
    tableWrapper.setWidget(table);
    tableWrapper.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(tableWrapper, 350, this);
    // add menu and the table to the main panel
    firstTabPanel.add(tableWrapper);
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, removeButton);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RemoveMember(cz.metacentrum.perun.webgui.json.groupsManager.RemoveMember) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) GetGroupMembersCount(cz.metacentrum.perun.webgui.json.groupsManager.GetGroupMembersCount) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) RichMember(cz.metacentrum.perun.webgui.model.RichMember) InviteUserTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.InviteUserTabItem) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers) AddMemberToGroupTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.AddMemberToGroupTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Aggregations

FieldUpdater (com.google.gwt.cell.client.FieldUpdater)28 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)19 ArrayList (java.util.ArrayList)19 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)17 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)17 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)16 User (cz.metacentrum.perun.webgui.model.User)15 UserDetailTabItem (cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem)15 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)10 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)8 Column (com.google.gwt.user.cellview.client.Column)6 FindCompleteRichUsers (cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers)6 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)6 RemoveAdmin (cz.metacentrum.perun.webgui.json.authzResolver.RemoveAdmin)5 AddAdmin (cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin)4 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)4 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)2 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)2