Search in sources :

Example 26 with User

use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.

the class FindUsers method onFinished.

/**
	 * Called, when operation finishes successfully.
	 */
public void onFinished(JavaScriptObject jso) {
    ArrayList<User> list = JsonUtils.jsoAsList(jso);
    for (User u : list) {
        if (hideService && u.isServiceUser()) {
        // if service hidden, skip service users
        } else if (hidePerson && !u.isServiceUser() && !u.isSponsoredUser()) {
        // if person hidden, skip person
        } else if (hideSponsored && !u.isSponsoredUser()) {
        // if person hidden, skip person
        } else {
            addToTable(u);
        }
    }
    sortTable();
    loaderImage.loadingFinished();
    session.getUiElements().setLogText("Users loaded: " + list.size());
    events.onFinished(jso);
}
Also used : User(cz.metacentrum.perun.webgui.model.User)

Example 27 with User

use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.

the class FindUsersByName method onFinished.

/**
	 * Called, when operation finishes successfully.
	 */
public void onFinished(JavaScriptObject jso) {
    for (User u : JsonUtils.<User>jsoAsList(jso)) {
        if (excludeService && u.isServiceUser()) {
        // skip service
        } else if (excludeSponsored && u.isSponsoredUser()) {
        // skip sponsored
        } else {
            addToTable(u);
        }
    }
    sortTable();
    session.getUiElements().setLogText("Users loaded: " + list.size());
    events.onFinished(jso);
    loaderImage.loadingFinished();
}
Also used : User(cz.metacentrum.perun.webgui.model.User)

Example 28 with User

use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.

the class GetRichUsersWithoutVo method getTable.

/**
	 * Returns table of users.
	 * @return
	 */
public CellTable<User> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<User>(list);
    // Cell table
    table = new PerunTable<User>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<User> columnSortHandler = new ListHandler<User>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<User>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // columns
    table.addCheckBoxColumn();
    table.addIdColumn("User ID", tableFieldUpdater);
    // NAME COLUMN
    Column<User, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User user) {
            return user.getFullName();
        }
    }, tableFieldUpdater);
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new Comparator<User>() {

        public int compare(User o1, User o2) {
            return o1.getLastName().compareToIgnoreCase(o2.getLastName());
        }
    });
    // SERVICE COLUMN
    Column<User, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User user) {
            if (user.isServiceUser()) {
                return "Service";
            } else if (user.isSponsoredUser()) {
                return "Sponsored";
            } else {
                return "Person";
            }
        }
    }, tableFieldUpdater);
    serviceColumn.setSortable(true);
    columnSortHandler.setComparator(serviceColumn, new Comparator<User>() {

        public int compare(User o1, User o2) {
            String type1 = "Person";
            if (o1.isServiceUser()) {
                type1 = "Service";
            } else if (o1.isSponsoredUser()) {
                type1 = "Sponsored";
            }
            String type2 = "Person";
            if (o2.isServiceUser()) {
                type2 = "Service";
            } else if (o2.isSponsoredUser()) {
                type2 = "Sponsored";
            }
            return type1.compareTo(type2);
        }
    });
    // Create organization column.
    Column<User, String> organizationColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:organization");
            if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
                return at.getValue();
            }
            return "";
        }
    }, this.tableFieldUpdater);
    // Create e-mail column.
    Column<User, String> emailColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
            if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
                return at.getValue().replace(",", " ");
            }
            return "";
        }
    }, this.tableFieldUpdater);
    // Create name column.
    Column<User, String> loginsColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            return object.getUserLogins();
        }
    }, this.tableFieldUpdater);
    organizationColumn.setSortable(true);
    columnSortHandler.setComparator(organizationColumn, new RichUserComparator(RichUserComparator.Column.ORGANIZATION));
    emailColumn.setSortable(true);
    columnSortHandler.setComparator(emailColumn, new RichUserComparator(RichUserComparator.Column.EMAIL));
    table.addColumn(nameColumn, "Name");
    table.addColumn(organizationColumn, "Organization");
    table.addColumn(emailColumn, "E-mail");
    table.addColumn(loginsColumn, "Logins");
    table.addColumn(serviceColumn, "User type");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) User(cz.metacentrum.perun.webgui.model.User) RichUserComparator(cz.metacentrum.perun.webgui.json.comparators.RichUserComparator) Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 29 with User

use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.

the class AddVoManagerTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add manager");
    final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
    this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            ArrayList<User> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                users.getSelectionModel().setSelected(list.get(0), true);
            }
        }
    }));
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // get the table
    final CellTable<User> table;
    if (session.isPerunAdmin()) {
        table = users.getTable(new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        });
    } else {
        table = users.getTable();
    }
    rebuildAlreadyAddedWidget();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToVo());
    final TabItem tab = this;
    // search textbox
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            startSearching(text);
            searchString = text;
        }
    }, searchButton);
    tabMenu.addWidget(addButton);
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<User> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // FIXME - Should have only one callback to core
                    final int n = i;
                    AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // put names to already added
                            alreadyAddedList.add(list.get(n));
                            rebuildAlreadyAddedWidget();
                            // unselect added person
                            users.getSelectionModel().setSelected(list.get(n), false);
                            // clear search
                            searchBox.getTextBox().setText("");
                        }
                    }));
                    request.addVoAdmin(vo, list.get(i));
                }
            }
        }
    });
    // if some text has been searched before
    if (!searchString.equals("")) {
        searchBox.getTextBox().setText(searchString);
        startSearching(searchString);
    }
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(alreadyAdded);
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) 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) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) AddAdmin(cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 30 with User

use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.

the class AddVoManagerTabItem method startSearching.

/**
	 * Starts the search for users
	 */
protected void startSearching(String text) {
    users.clearTable();
    // IS searched string IDs?
    if (JsonUtils.isStringWithIds(text)) {
        FindUsersByIdsNotInRpc req = new FindUsersByIdsNotInRpc(new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                ArrayList<User> usersList = JsonUtils.jsoAsList(jso);
                for (User u : usersList) {
                    users.addToTable(u);
                }
            }
        }, text);
        req.retrieveData();
        return;
    }
    users.searchFor(text);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) User(cz.metacentrum.perun.webgui.model.User) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ArrayList(java.util.ArrayList) FindUsersByIdsNotInRpc(cz.metacentrum.perun.webgui.json.usersManager.FindUsersByIdsNotInRpc)

Aggregations

User (cz.metacentrum.perun.webgui.model.User)48 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)22 ArrayList (java.util.ArrayList)20 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)19 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)19 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)18 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)18 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)17 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)15 UserDetailTabItem (cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem)15 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)13 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)9 FindCompleteRichUsers (cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers)8 Attribute (cz.metacentrum.perun.webgui.model.Attribute)6 PerunError (cz.metacentrum.perun.webgui.model.PerunError)6 FindUsersByIdsNotInRpc (cz.metacentrum.perun.webgui.json.usersManager.FindUsersByIdsNotInRpc)5 GetSpecificUsersByUser (cz.metacentrum.perun.webgui.json.usersManager.GetSpecificUsersByUser)5 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)4 AddAdmin (cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin)4 RemoveAdmin (cz.metacentrum.perun.webgui.json.authzResolver.RemoveAdmin)4