Search in sources :

Example 1 with CanceledException

use of jetbrains.communicator.ide.CanceledException 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)

Example 2 with CanceledException

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

the class Helper method doGetProjectsData.

public static ProjectsData doGetProjectsData(final Transport transport, final User user, IDEFacade ideFacade) {
    final ProjectsData[] result = new ProjectsData[] { ProjectsData.NULL };
    if (user.isOnline()) {
        try {
            UIUtil.run(ideFacade, StringUtil.getMsg("ViewFilesCommand.title", user.getDisplayName()), new Runnable() {

                @Override
                public void run() {
                    final Semaphore semaphore = new Semaphore(1);
                    try {
                        semaphore.acquire();
                        transport.sendXmlMessage(user, new GetProjectsDataXmlMessage(result) {

                            @Override
                            public void processResponse(Element responseElement) {
                                super.processResponse(responseElement);
                                semaphore.release();
                            }
                        });
                        semaphore.tryAcquire(getWaitTimeout(), TimeUnit.MILLISECONDS);
                    } catch (InterruptedException ignored) {
                    }
                }
            });
        } catch (CanceledException ignored) {
        //
        }
    }
    return result[0];
}
Also used : CanceledException(jetbrains.communicator.ide.CanceledException) ProjectsData(jetbrains.communicator.core.vfs.ProjectsData) GetProjectsDataXmlMessage(jetbrains.communicator.core.transport.GetProjectsDataXmlMessage) Element(org.jdom.Element) Semaphore(java.util.concurrent.Semaphore)

Example 3 with CanceledException

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

the class Helper method fillVFileContent.

public static void fillVFileContent(final Transport transport, final User user, final VFile vFile, IDEFacade ideFacade) {
    if (user.isOnline()) {
        try {
            UIUtil.run(ideFacade, StringUtil.getMsg("GetVFileContents.title"), new Runnable() {

                @Override
                public void run() {
                    final Semaphore semaphore = new Semaphore(1);
                    try {
                        semaphore.acquire();
                        transport.sendXmlMessage(user, new GetVFileContentsXmlMessage(vFile) {

                            @Override
                            public void processResponse(Element responseElement) {
                                super.processResponse(responseElement);
                                semaphore.release();
                            }
                        });
                        semaphore.tryAcquire(getWaitTimeout(), TimeUnit.MILLISECONDS);
                    } catch (InterruptedException ignored) {
                    // noop
                    }
                }
            });
        } catch (CanceledException e) {
            LOG.info(e.getMessage(), e);
        }
        if (vFile.getContents() == null) {
            String secondParamForFailMessage = user.getDisplayName();
            String address = transport.getAddressString(user);
            if (!com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces(address)) {
                secondParamForFailMessage += " from " + address;
            }
            ideFacade.showMessage(StringUtil.FAILED_TITLE, StringUtil.getMsg("GetVFileContents.fail", vFile.getDisplayName(), secondParamForFailMessage));
        }
    }
}
Also used : CanceledException(jetbrains.communicator.ide.CanceledException) Element(org.jdom.Element) Semaphore(java.util.concurrent.Semaphore) GetVFileContentsXmlMessage(jetbrains.communicator.core.transport.GetVFileContentsXmlMessage)

Aggregations

CanceledException (jetbrains.communicator.ide.CanceledException)3 Semaphore (java.util.concurrent.Semaphore)2 Element (org.jdom.Element)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GetProjectsDataXmlMessage (jetbrains.communicator.core.transport.GetProjectsDataXmlMessage)1 GetVFileContentsXmlMessage (jetbrains.communicator.core.transport.GetVFileContentsXmlMessage)1 Transport (jetbrains.communicator.core.transport.Transport)1 User (jetbrains.communicator.core.users.User)1 ProjectsData (jetbrains.communicator.core.vfs.ProjectsData)1 IDEFacade (jetbrains.communicator.ide.IDEFacade)1 ProgressIndicator (jetbrains.communicator.ide.ProgressIndicator)1