Search in sources :

Example 1 with AddSpecificUserOwner

use of cz.metacentrum.perun.webgui.json.usersManager.AddSpecificUserOwner in project perun by CESNET.

the class ConnectServiceIdentityTabItem method draw.

public Widget draw() {
    titleWidget.setText("Connect identity");
    VerticalPanel content = new VerticalPanel();
    content.setSize("100%", "100%");
    final TabItem tab = this;
    // add button
    final CustomButton addButton;
    if (user.isServiceUser() || user.isSponsoredUser()) {
        addButton = new CustomButton("Connect", "Add selected users to this identity", SmallIcons.INSTANCE.addIcon());
    } else {
        addButton = new CustomButton("Connect", "Add selected identities to user", SmallIcons.INSTANCE.addIcon());
    }
    TabMenu menu = new TabMenu();
    menu.addWidget(addButton);
    content.add(menu);
    content.setCellHeight(menu, "30px");
    final FindCompleteRichUsers call = new FindCompleteRichUsers("", null);
    if (user.isServiceUser()) {
        call.hideService(true);
    }
    if (user.isSponsoredUser()) {
        call.hideSponsored(true);
        call.hideService(true);
    }
    if (!user.isSpecificUser()) {
        call.hidePerson(true);
    }
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // close tab and refresh
            session.getTabManager().closeTab(tab, true);
        }
    }));
    // search textbox
    ExtendedTextBox searchBox = menu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            call.searchFor(text);
        }
    }, "");
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            ArrayList<User> list = call.getTableSelectedList();
            for (int i = 0; i < list.size(); i++) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                AddSpecificUserOwner req;
                if (i == list.size() - 1) {
                    req = new AddSpecificUserOwner(JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                } else {
                    req = new AddSpecificUserOwner(JsonCallbackEvents.disableButtonEvents(addButton));
                }
                if (user.isServiceUser() || user.isSponsoredUser()) {
                    // service user adds user
                    req.addSpecificUser(list.get(i), user);
                } else {
                    // user adds service users
                    req.addSpecificUser(user, list.get(i));
                }
            }
        }
    });
    FieldUpdater<User, String> fieldUpdater = null;
    if (session.isPerunAdmin()) {
        fieldUpdater = new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        };
    }
    CellTable<User> table = call.getTable(fieldUpdater);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(call, table, addButton);
    content.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(new SimplePanel(content));
    return getWidget();
}
Also used : User(cz.metacentrum.perun.webgui.model.User) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) ArrayList(java.util.ArrayList) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) AddSpecificUserOwner(cz.metacentrum.perun.webgui.json.usersManager.AddSpecificUserOwner) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 AddSpecificUserOwner (cz.metacentrum.perun.webgui.json.usersManager.AddSpecificUserOwner)1 FindCompleteRichUsers (cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers)1 User (cz.metacentrum.perun.webgui.model.User)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1