Search in sources :

Example 1 with ProgressIndicator

use of jetbrains.communicator.ide.ProgressIndicator in project intellij-plugins by JetBrains.

the class FindUsersCommand method execute.

public void execute() {
    final List<User>[] finalUsers = new List[1];
    try {
        myIdeFacade.runLongProcess(StringUtil.getMsg("FindUsersCommand.dialog.title"), new IDEFacade.Process() {

            public void run(ProgressIndicator indicator) {
                List<User> result = new ArrayList<>();
                for (Transport transport : myTransports) {
                    result.addAll(Arrays.asList(transport.findUsers(indicator)));
                }
                finalUsers[0] = result;
            }
        });
    } catch (CanceledException e) {
        return;
    }
    List<User> users = finalUsers[0];
    if (users == null)
        return;
    for (Iterator<User> it = users.iterator(); it.hasNext(); ) {
        User user = it.next();
        if (user.isSelf() || myUserModel.hasUser(user)) {
            it.remove();
        }
    }
    if (users.size() < 1) {
        showNoUsersFoundMessage();
        return;
    }
    UsersInfo usersInfo = myIdeFacade.chooseUsersToBeAdded(users, myUserModel.getGroups());
    User[] toBeAdded = usersInfo.getUsers();
    for (User user : toBeAdded) {
        String group = usersInfo.getGroup();
        if (UserModel.AUTO_GROUP.equals(group)) {
            String[] userProjects = user.getProjects();
            group = userProjects.length > 0 ? userProjects[0] : UserModel.DEFAULT_GROUP;
        }
        user.setGroup(group, myUserModel);
        myUserModel.addUser(user);
    }
}
Also used : CanceledException(jetbrains.communicator.ide.CanceledException) User(jetbrains.communicator.core.users.User) ProgressIndicator(jetbrains.communicator.ide.ProgressIndicator) ArrayList(java.util.ArrayList) List(java.util.List) Transport(jetbrains.communicator.core.transport.Transport) IDEFacade(jetbrains.communicator.ide.IDEFacade)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Transport (jetbrains.communicator.core.transport.Transport)1 User (jetbrains.communicator.core.users.User)1 CanceledException (jetbrains.communicator.ide.CanceledException)1 IDEFacade (jetbrains.communicator.ide.IDEFacade)1 ProgressIndicator (jetbrains.communicator.ide.ProgressIndicator)1