Search in sources :

Example 1 with IContainerListener

use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.

the class SharedModelFactory method createSharedDataSource.

public IMasterModel createSharedDataSource(ISharedObjectContainer container, final ID id, Object data, String updaterID) throws SharedObjectCreateException {
    final ISharedObjectManager mgr = container.getSharedObjectManager();
    final Object[] result = new Object[1];
    final Object monitor = new Object();
    IContainerListener listener = new IContainerListener() {

        public void handleEvent(IContainerEvent event) {
            if (event instanceof ISharedObjectActivatedEvent) {
                ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event;
                if (e.getActivatedID().equals(id)) {
                    result[0] = mgr.getSharedObject(id);
                    synchronized (monitor) {
                        monitor.notify();
                    }
                }
            }
        }
    };
    try {
        container.addListener(listener);
        /*			SharedObjectDescription desc = createLocalAgentDescription(id, container.getID(), data, updaterID);
			synchronized (monitor) {
				mgr.createSharedObject(desc);
				if (result[0] == null)
					monitor.wait(getCreationTimeout());
			}
*/
        synchronized (monitor) {
            addSharedObject(mgr, id, data, updaterID);
            if (result[0] == null)
                monitor.wait(getCreationTimeout());
        }
    } catch (InterruptedException e) {
        throw new SharedObjectCreateException(e);
    } finally {
        container.removeListener(listener);
    }
    return (IMasterModel) result[0];
}
Also used : ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) IContainerListener(org.eclipse.ecf.core.IContainerListener)

Example 2 with IContainerListener

use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.

the class SSLClientContainerConnectTest method testRemoveListener.

public void testRemoveListener() throws Exception {
    final IContainer client = getClients()[0];
    final IContainerListener l = createListener();
    client.addListener(l);
    client.removeListener(l);
    client.connect(createServerID(), null);
    assertTrue(clientConnectingEvents.size() == 0);
}
Also used : IContainerListener(org.eclipse.ecf.core.IContainerListener) IContainer(org.eclipse.ecf.core.IContainer)

Example 3 with IContainerListener

use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.

the class ChatRoomManagerUI method setupNewView.

private void setupNewView() throws Exception {
    IChatRoomInfo roomInfo = manager.getChatRoomInfo(null);
    Assert.isNotNull(roomInfo, Messages.ChatRoomManagerUI_EXCEPTION_NO_ROOT_CHAT_ROOM_MANAGER);
    final IChatRoomContainer managerChatRoom = roomInfo.createChatRoomContainer();
    chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID), ChatRoomManagerView.getHostnameFromID(targetID), managerChatRoom, this, createChatRoomViewCloseListener());
    chatroomview.setMessageRenderer(getDefaultMessageRenderer());
    // Add listener for container, so that if the container is spontaneously
    // disconnected,
    // then we will be able to have the UI respond by making itself inactive
    container.addListener(new IContainerListener() {

        public void handleEvent(final IContainerEvent evt) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    if (evt instanceof IContainerDisconnectedEvent || evt instanceof IContainerEjectedEvent) {
                        final ID departedContainerID = ((evt instanceof IContainerDisconnectedEvent) ? ((IContainerDisconnectedEvent) evt).getTargetID() : ((IContainerEjectedEvent) evt).getTargetID());
                        ID connectedID = targetID;
                        if (connectedID == null || connectedID.equals(departedContainerID)) {
                            chatroomview.disconnected();
                            isContainerConnected = false;
                        }
                    } else if (evt instanceof IContainerConnectedEvent) {
                        isContainerConnected = true;
                        chatroomview.setEnabled(true);
                        String[] roomsForTarget = getRoomsForTarget();
                        for (int i = 0; i < roomsForTarget.length; i++) {
                            IChatRoomInfo info = manager.getChatRoomInfo(roomsForTarget[i]);
                            chatroomview.joinRoom(info, getPasswordForChatRoomConnect(info));
                        }
                    }
                }
            });
        }
    });
    // Add listeners so that the new chat room gets
    // asynch notifications of various relevant chat room events
    managerChatRoom.addMessageListener(new IIMMessageListener() {

        public void handleMessageEvent(IIMMessageEvent messageEvent) {
            if (messageEvent instanceof IChatRoomMessageEvent) {
                IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent).getChatRoomMessage();
                chatroomview.handleMessage(m.getFromID(), m.getMessage());
            } else if (messageEvent instanceof IChatMessageEvent) {
                final IChatMessage chatMessage = ((IChatMessageEvent) messageEvent).getChatMessage();
                chatroomview.handleChatMessage(chatMessage);
            }
        }
    });
}
Also used : IContainerListener(org.eclipse.ecf.core.IContainerListener) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent) IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) IChatMessage(org.eclipse.ecf.presence.im.IChatMessage) ID(org.eclipse.ecf.core.identity.ID)

Example 4 with IContainerListener

use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.

the class ChatRoomManagerView method doJoinRoom.

protected void doJoinRoom(final IChatRoomInfo roomInfo, final String password) {
    final ID targetRoomID = roomInfo.getRoomID();
    final String targetRoomName = targetRoomID.getName();
    // first, check to see if we already have it open. If so just activate
    ChatRoom room = (ChatRoom) chatRooms.get(targetRoomName);
    if (room != null && room.isConnected()) {
        room.setSelected();
        return;
    }
    // Then we create a new chatRoomContainer from the roomInfo
    try {
        final IChatRoomContainer chatRoomContainer = roomInfo.createChatRoomContainer();
        // Setup new user interface (new tab)
        final ChatRoom chatroom = new ChatRoom(chatRoomContainer, new ChatRoomTab(rootTabFolder, targetRoomName));
        // setup message listener
        chatRoomContainer.addMessageListener(new IIMMessageListener() {

            public void handleMessageEvent(IIMMessageEvent messageEvent) {
                if (messageEvent instanceof IChatRoomMessageEvent) {
                    IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent).getChatRoomMessage();
                    chatroom.handleMessage(m.getFromID(), m.getMessage());
                }
            }
        });
        // setup participant listener
        chatRoomContainer.addChatRoomParticipantListener(new IChatRoomParticipantListener() {

            public void handlePresenceUpdated(ID fromID, IPresence presence) {
                chatroom.handlePresence(fromID, presence);
            }

            public void handleArrived(IUser participant) {
            // do nothing
            }

            public void handleUpdated(IUser updatedParticipant) {
            // do nothing
            }

            public void handleDeparted(IUser participant) {
            // do nothing
            }
        });
        chatRoomContainer.addListener(new IContainerListener() {

            public void handleEvent(IContainerEvent evt) {
                if (evt instanceof IContainerDisconnectedEvent || evt instanceof IContainerEjectedEvent) {
                    chatroom.disconnected();
                }
            }
        });
        // Now connect/join
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                try {
                    chatRoomContainer.connect(targetRoomID, ConnectContextFactory.createPasswordConnectContext(password));
                    chatRooms.put(targetRoomName, chatroom);
                } catch (Exception e) {
                    // $NON-NLS-1$
                    MessageDialog.openError(// $NON-NLS-1$
                    getSite().getShell(), // $NON-NLS-1$
                    "Connect Error", // $NON-NLS-1$
                    NLS.bind(// $NON-NLS-1$
                    "Could not connect to {0}.\n\nError is {1}.", targetRoomName, e.getLocalizedMessage()));
                }
            }
        });
    } catch (Exception e) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        getSite().getShell(), // $NON-NLS-1$
        "Container Create Error", // $NON-NLS-1$
        NLS.bind(// $NON-NLS-1$
        "Could not create chatRoomContainer for {0}.\n\nError is {1}.", targetRoomName, e.getLocalizedMessage()));
    }
}
Also used : IContainerListener(org.eclipse.ecf.core.IContainerListener) ECFException(org.eclipse.ecf.core.util.ECFException) URISyntaxException(java.net.URISyntaxException) IUser(org.eclipse.ecf.core.user.IUser) IChatID(org.eclipse.ecf.presence.im.IChatID)

Example 5 with IContainerListener

use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.

the class MSNConnectWizard method performFinish.

public boolean performFinish() {
    final String connectID = page.getEmail();
    final String password = page.getPassword();
    // Save combo text even if we don't successfully login
    page.saveComboText();
    connectContext = ConnectContextFactory.createPasswordConnectContext(password);
    try {
        targetID = container.getConnectNamespace().createInstance(new Object[] { connectID });
    } catch (final IDCreateException e) {
        new IDCreateErrorDialog(null, connectID, e).open();
        return false;
    }
    page.saveComboItems();
    final IPresenceContainerAdapter adapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
    container.addListener(new IContainerListener() {

        public void handleEvent(IContainerEvent event) {
            if (event instanceof IContainerConnectedEvent) {
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        openView();
                    }
                });
            }
        }
    });
    final IChatManager icm = adapter.getChatManager();
    icms = icm.getChatMessageSender();
    itms = icm.getTypingMessageSender();
    icm.addMessageListener(new IIMMessageListener() {

        public void handleMessageEvent(IIMMessageEvent e) {
            if (e instanceof IChatMessageEvent) {
                displayMessage((IChatMessageEvent) e);
            } else if (e instanceof ITypingMessageEvent) {
                displayTypingNotification((ITypingMessageEvent) e);
            }
        }
    });
    new AsynchContainerConnectAction(container, targetID, connectContext, null, new Runnable() {

        public void run() {
            cachePassword(connectID, password);
        }
    }).run();
    return true;
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IContainerListener(org.eclipse.ecf.core.IContainerListener) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent) IDCreateErrorDialog(org.eclipse.ecf.ui.dialogs.IDCreateErrorDialog) IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) ITypingMessageEvent(org.eclipse.ecf.presence.im.ITypingMessageEvent) AsynchContainerConnectAction(org.eclipse.ecf.ui.actions.AsynchContainerConnectAction) IChatManager(org.eclipse.ecf.presence.im.IChatManager)

Aggregations

IContainerListener (org.eclipse.ecf.core.IContainerListener)11 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)5 IContainerConnectedEvent (org.eclipse.ecf.core.events.IContainerConnectedEvent)3 IContainerDisconnectedEvent (org.eclipse.ecf.core.events.IContainerDisconnectedEvent)3 IContainer (org.eclipse.ecf.core.IContainer)2 ID (org.eclipse.ecf.core.identity.ID)2 IIMMessageEvent (org.eclipse.ecf.presence.IIMMessageEvent)2 IIMMessageListener (org.eclipse.ecf.presence.IIMMessageListener)2 IChatMessageEvent (org.eclipse.ecf.presence.im.IChatMessageEvent)2 URISyntaxException (java.net.URISyntaxException)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)1 SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)1 ISharedObjectActivatedEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent)1 IUser (org.eclipse.ecf.core.user.IUser)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)1 IChatID (org.eclipse.ecf.presence.im.IChatID)1 IChatManager (org.eclipse.ecf.presence.im.IChatManager)1 IChatMessage (org.eclipse.ecf.presence.im.IChatMessage)1