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();
// If the hosts are the same for the target and local
// accounts,
// it's pretty obvious that we wish to message to them
if (localHost.equals(targetHost)) {
openMessagesView(chatManager, localID, targetID);
} 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);
return;