Search in sources :

Example 1 with XMPPSID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPSID in project ecf by eclipse.

the class XMPPHyperlink method openContainer.

/**
 * @param presenceContainerAdapter
 */
private void openContainer(IContainer container) {
    final IPresenceContainerAdapter presenceContainerAdapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
    final IChatManager chatManager = presenceContainerAdapter.getChatManager();
    final IRosterManager rosterManager = presenceContainerAdapter.getRosterManager();
    if (chatManager != null && rosterManager != null) {
        try {
            // get local ID
            final XMPPID localID = (XMPPID) rosterManager.getRoster().getUser().getID();
            final Namespace ns = container.getConnectNamespace();
            // create target ID
            final XMPPID targetID = (isXMPPS) ? new XMPPSID(ns, getURI().getAuthority()) : new XMPPID(ns, getURI().getAuthority());
            // If they are same, just tell user and return
            if (localID.equals(targetID)) {
                MessageDialog.openError(null, Messages.XMPPHyperlink_MESSAGING_ERROR_TITLE, Messages.XMPPHyperlink_MESSAGING_ERROR_MESSAGE);
                return;
            } else {
                final String localHost = localID.getHostname();
                final String targetHost = targetID.getHostname();
                // it's pretty obvious that we wish to message to them
                if (localHost.equals(targetHost)) {
                    openMessagesView(chatManager, localID, targetID, targetID.getUsername());
                } else {
                    // Otherwise, ask the user whether messaging, or
                    // connecting is desired
                    final MessageDialog messageDialog = new MessageDialog(null, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_TITLE, null, NLS.bind(Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_MESSAGE, new Object[] { targetHost, localHost, targetID.getName(), localID.getName() }), MessageDialog.QUESTION, new String[] { Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_SEND_MESSAGE, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CONNECT, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CANCEL }, 2);
                    final int selected = messageDialog.open();
                    switch(selected) {
                        case 0:
                            openMessagesView(chatManager, localID, targetID, targetID.getUsername());
                            return;
                        case 1:
                            super.open();
                            return;
                        default:
                            return;
                    }
                }
            }
        } catch (final Exception e) {
            MessageDialog.openError(null, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_TITLE, NLS.bind(Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_MESSAGE, e.getLocalizedMessage()));
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_LOG_STATUS_MESSAGE, e));
        }
    }
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IRosterManager(org.eclipse.ecf.presence.roster.IRosterManager) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) Namespace(org.eclipse.ecf.core.identity.Namespace) XMPPSID(org.eclipse.ecf.provider.xmpp.identity.XMPPSID)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)1 IRosterManager (org.eclipse.ecf.presence.roster.IRosterManager)1 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)1 XMPPSID (org.eclipse.ecf.provider.xmpp.identity.XMPPSID)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1