Search in sources :

Example 1 with Transport

use of jetbrains.communicator.core.transport.Transport 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 Transport

use of jetbrains.communicator.core.transport.Transport in project intellij-plugins by JetBrains.

the class IDEtalkToolWindow method initializeTransports.

private void initializeTransports(String projectName) {
    java.util.List transports = Pico.getInstance().getComponentInstancesOfType(Transport.class);
    for (Object transport1 : transports) {
        Transport transport = (Transport) transport1;
        transport.initializeProject(projectName, myContainer);
    }
}
Also used : Transport(jetbrains.communicator.core.transport.Transport)

Example 3 with Transport

use of jetbrains.communicator.core.transport.Transport in project intellij-plugins by JetBrains.

the class UserActivityMonitor method run.

@Override
public void run() {
    try {
        myThreadDisposed = false;
        while (!myStop) {
            UserPresence userPresence = calculatePresence();
            LOG.debug("Calculated own presence: " + userPresence);
            for (Object o : Pico.getInstance().getComponentInstancesOfType(Transport.class)) {
                Transport transport = (Transport) o;
                if (transport.isOnline()) {
                    transport.setOwnPresence(userPresence);
                }
            }
            synchronized (myMonitor) {
                myMonitor.wait(myRefreshInterval);
            }
        }
    } catch (InterruptedException e) {
        LOG.info("Interrupted");
    } finally {
        myThreadDisposed = true;
    }
}
Also used : UserPresence(jetbrains.communicator.core.users.UserPresence) Transport(jetbrains.communicator.core.transport.Transport)

Example 4 with Transport

use of jetbrains.communicator.core.transport.Transport in project intellij-plugins by JetBrains.

the class FindUsersCommandTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myUserModelMock = mock(UserModel.class);
    myTransportMock = mock(Transport.class);
    myTransportMock1 = mock(Transport.class);
    myIDEFacade = new MockIDEFacade();
    myUserModelMock.stubs().method("getBroadcaster").will(returnValue(getBroadcaster()));
    myCommand = new FindUsersCommand((UserModel) myUserModelMock.proxy(), new Transport[] { (Transport) myTransportMock.proxy(), (Transport) myTransportMock1.proxy() }, myIDEFacade);
    assertTrue(myCommand.isEnabled());
    assertNotNull(myCommand.getName());
}
Also used : UserModel(jetbrains.communicator.core.users.UserModel) MockIDEFacade(jetbrains.communicator.mock.MockIDEFacade) Transport(jetbrains.communicator.core.transport.Transport)

Example 5 with Transport

use of jetbrains.communicator.core.transport.Transport in project intellij-plugins by JetBrains.

the class TestUtil method testSendXmlMessage_Functional.

public static void testSendXmlMessage_Functional(BaseTestCase testCase, User self, final boolean checkResponse) {
    final String[] log = new String[] { "" };
    log[0] = "";
    final String comment = "��� mes&&<>sage";
    MockXmlMessage message = new MockXmlMessage("tagName", "myNamespace") {

        @Override
        public boolean needsResponse() {
            return checkResponse;
        }

        @Override
        public void fillRequest(Element element) {
            element.setText(comment);
        }

        @Override
        public void processResponse(Element responseElement) {
            log[0] += responseElement.getAttributeValue("foo");
        }
    };
    final MockXmlResponseProvider mockXmlResponseProvider = new MockXmlResponseProvider("tagName", "myNamespace", testCase.getBroadcaster()) {

        @Override
        public boolean processAndFillResponse(Element response, Element request, Transport transport, String remoteUser) {
            log[0] += remoteUser + " " + request.getName() + " " + request.getText();
            assertEquals("root element expected", "tagName", request.getName());
            response.setAttribute("foo", "gar");
            return true;
        }
    };
    Pico.getInstance().registerComponentInstance(mockXmlResponseProvider);
    testCase.disposeOnTearDown(new Disposable() {

        @Override
        public void dispose() {
            Pico.getInstance().unregisterComponentByInstance(mockXmlResponseProvider);
        }
    });
    self.sendXmlMessage(message);
    new WaitFor(500) {

        @Override
        protected boolean condition() {
            if (checkResponse) {
                return log[0].endsWith("gar");
            } else {
                return log[0].length() > 0;
            }
        }
    };
    String expectedLog = self.getName() + " tagName " + comment;
    expectedLog += checkResponse ? "gar" : "";
    assertEquals("Message expected", expectedLog, log[0]);
}
Also used : Disposable(org.picocontainer.Disposable) WaitFor(jetbrains.communicator.util.WaitFor) Element(org.jdom.Element) MockXmlMessage(jetbrains.communicator.p2p.MockXmlMessage) Transport(jetbrains.communicator.core.transport.Transport) MockXmlResponseProvider(jetbrains.communicator.p2p.MockXmlResponseProvider)

Aggregations

Transport (jetbrains.communicator.core.transport.Transport)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 User (jetbrains.communicator.core.users.User)1 UserModel (jetbrains.communicator.core.users.UserModel)1 UserPresence (jetbrains.communicator.core.users.UserPresence)1 CanceledException (jetbrains.communicator.ide.CanceledException)1 IDEFacade (jetbrains.communicator.ide.IDEFacade)1 ProgressIndicator (jetbrains.communicator.ide.ProgressIndicator)1 MockIDEFacade (jetbrains.communicator.mock.MockIDEFacade)1 MockXmlMessage (jetbrains.communicator.p2p.MockXmlMessage)1 MockXmlResponseProvider (jetbrains.communicator.p2p.MockXmlResponseProvider)1 WaitFor (jetbrains.communicator.util.WaitFor)1 Element (org.jdom.Element)1 Disposable (org.picocontainer.Disposable)1