Search in sources :

Example 1 with IChatMessageEvent

use of org.eclipse.ecf.presence.im.IChatMessageEvent in project ecf by eclipse.

the class XMPPChatClient method setupPresence.

public void setupPresence() throws ECFException {
    if (presence == null) {
        presence = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
        if (presence == null)
            throw new ECFException("adapter is null");
        sender = presence.getChatManager().getChatMessageSender();
        presence.getChatManager().addMessageListener(new IIMMessageListener() {

            public void handleMessageEvent(IIMMessageEvent messageEvent) {
                if (messageEvent instanceof IChatMessageEvent) {
                    IChatMessage m = ((IChatMessageEvent) messageEvent).getChatMessage();
                    if (receiver != null) {
                        receiver.handleMessage(m);
                    }
                }
            }
        });
        if (presenceListener != null) {
            presence.getRosterManager().addPresenceListener(presenceListener);
        }
    }
}
Also used : IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) ECFException(org.eclipse.ecf.core.util.ECFException) IChatMessage(org.eclipse.ecf.presence.im.IChatMessage) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent)

Example 2 with IChatMessageEvent

use of org.eclipse.ecf.presence.im.IChatMessageEvent 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 3 with IChatMessageEvent

use of org.eclipse.ecf.presence.im.IChatMessageEvent in project ecf by eclipse.

the class XMPPChatRoomClient method setupPresenceAdapter.

protected void setupPresenceAdapter() {
    // Get presence adapter off of container
    presence = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
    // Get sender interface
    sender = presence.getChatManager().getChatMessageSender();
    // Setup message requestListener to handle incoming messages
    presence.getChatManager().addMessageListener(new IIMMessageListener() {

        public void handleMessageEvent(IIMMessageEvent messageEvent) {
            if (messageEvent instanceof IChatMessageEvent) {
                final IChatMessage m = ((IChatMessageEvent) messageEvent).getChatMessage();
                receiver.handleMessage(m);
            }
        }
    });
}
Also used : IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) IChatMessage(org.eclipse.ecf.presence.im.IChatMessage) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent)

Example 4 with IChatMessageEvent

use of org.eclipse.ecf.presence.im.IChatMessageEvent 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)

Example 5 with IChatMessageEvent

use of org.eclipse.ecf.presence.im.IChatMessageEvent in project ecf by eclipse.

the class ChatRoomMessageHandler method preContainerConnect.

public void preContainerConnect(IContainer container, ID targetID) {
    File file = new File(Platform.getInstanceLocation().getURL().getPath(), "password.properties");
    if (file.exists()) {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(file));
            password = properties.getProperty("password");
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
    }
    this.container = container;
    IChatRoomContainer chatRoomContainer = (IChatRoomContainer) container.getAdapter(IChatRoomContainer.class);
    chatMessageSender = chatRoomContainer.getPrivateMessageSender();
    chatRoomContainer.addMessageListener(new IIMMessageListener() {

        public void handleMessageEvent(IIMMessageEvent e) {
            if (e instanceof IChatMessageEvent) {
                IChatMessageEvent event = (IChatMessageEvent) e;
                String msg = event.getChatMessage().getBody();
                switch(msg.charAt(0)) {
                    case '~':
                    case '!':
                        handleMessage(event.getFromID(), event.getFromID(), msg.substring(1).trim());
                        break;
                    default:
                        handleMessage(event.getFromID(), event.getFromID(), msg.trim());
                        break;
                }
            }
        }
    });
}
Also used : IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) FileNotFoundException(java.io.FileNotFoundException) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent)

Aggregations

IChatMessageEvent (org.eclipse.ecf.presence.im.IChatMessageEvent)6 IIMMessageEvent (org.eclipse.ecf.presence.IIMMessageEvent)5 IIMMessageListener (org.eclipse.ecf.presence.IIMMessageListener)5 IChatMessage (org.eclipse.ecf.presence.im.IChatMessage)4 IContainerListener (org.eclipse.ecf.core.IContainerListener)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 List (java.util.List)1 Properties (java.util.Properties)1 IContainerConnectedEvent (org.eclipse.ecf.core.events.IContainerConnectedEvent)1 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)1 ID (org.eclipse.ecf.core.identity.ID)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)1 IIMMessageHandlerEntry (org.eclipse.ecf.presence.bot.IIMMessageHandlerEntry)1 IChatRoomContainer (org.eclipse.ecf.presence.chatroom.IChatRoomContainer)1 IChatManager (org.eclipse.ecf.presence.im.IChatManager)1