Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-05-15 17:07:22 +0000
committerslewis2007-05-15 17:07:22 +0000
commit1534c9c784e9a3f7465a475e9c2ed7a471e69839 (patch)
tree1030affc505d67a0d9d5e7f1790b77e309ce1077 /providers/bundles/org.eclipse.ecf.provider.xmpp.ui
parentea486fd9f1c92b1612afb6d2486eeeb1798c76b8 (diff)
downloadorg.eclipse.ecf-1534c9c784e9a3f7465a475e9c2ed7a471e69839.tar.gz
org.eclipse.ecf-1534c9c784e9a3f7465a475e9c2ed7a471e69839.tar.xz
org.eclipse.ecf-1534c9c784e9a3f7465a475e9c2ed7a471e69839.zip
Checking in changes/additions to hyperlink detector
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.xmpp.ui')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Activator.java30
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Messages.java15
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/hyperlink/XMPPHyperlink.java207
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/messages.properties7
4 files changed, 248 insertions, 11 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Activator.java b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Activator.java
index acfd88d00..bea9a99b5 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Activator.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Activator.java
@@ -1,7 +1,9 @@
package org.eclipse.ecf.internal.provider.xmpp.ui;
+import org.eclipse.ecf.core.IContainerManager;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
/**
* The activator class controls the plug-in life cycle
@@ -13,7 +15,11 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
-
+
+ private BundleContext context = null;
+
+ private ServiceTracker containerManagerTracker = null;
+
/**
* The constructor
*/
@@ -22,25 +28,33 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
+ *
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ this.context = context;
}
/*
* (non-Javadoc)
+ *
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ if (containerManagerTracker != null) {
+ containerManagerTracker.close();
+ containerManagerTracker = null;
+ }
plugin = null;
+ this.context = null;
super.stop(context);
}
/**
* Returns the shared instance
- *
+ *
* @return the shared instance
*/
public synchronized static Activator getDefault() {
@@ -50,4 +64,16 @@ public class Activator extends AbstractUIPlugin {
return plugin;
}
+ /**
+ * @return
+ */
+ public IContainerManager getContainerManager() {
+ if (containerManagerTracker == null) {
+ containerManagerTracker = new ServiceTracker(context,
+ IContainerManager.class.getName(), null);
+ containerManagerTracker.open();
+ }
+ return (IContainerManager) containerManagerTracker.getService();
+ }
+
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Messages.java b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Messages.java
index 435ec56ac..9e100588f 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Messages.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/Messages.java
@@ -20,6 +20,21 @@ public class Messages extends NLS {
public static String XMPPConnectWizardPage_WIZARD_DESCRIPTION;
public static String XMPPCompoundContributionItem_CHOOSE_FILE;
public static String XMPPConnectWizard_RECEIVE_ERROR_MESSAGE;
+
+ public static String XMPPHyperlink_CONNECT_ACCOUNT_DIALOG_MESSAGE;
+
+ public static String XMPPHyperlink_CONNECT_ACCOUNT_DIALOG_TITLE;
+
+ public static String XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_MESSAGE;
+
+ public static String XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_TITLE;
+
+ public static String XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_LOG_STATUS_MESSAGE;
+
+ public static String XMPPHyperlink_SELECT_ACCOUNT_MESSAGE;
+
+ public static String XMPPHyperlink_SELECT_ACCOUNT_TITLE;
+
public static String XMPPSConnectWizardPage_WIZARD_PAGE_TITLE;
public static String XMPPSConnectWizardPage_WIZARD_PAGE_USERID;
public static String XMPPSConnectWizardPage_WIZARD_PAGE_STATUS;
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/hyperlink/XMPPHyperlink.java b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/hyperlink/XMPPHyperlink.java
index 22e04ecd6..6daad7ba1 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/hyperlink/XMPPHyperlink.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/hyperlink/XMPPHyperlink.java
@@ -12,15 +12,42 @@
package org.eclipse.ecf.internal.provider.xmpp.ui.hyperlink;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.IContainerManager;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.internal.provider.xmpp.ui.Activator;
+import org.eclipse.ecf.internal.provider.xmpp.ui.Messages;
import org.eclipse.ecf.internal.provider.xmpp.ui.wizards.XMPPConnectWizard;
import org.eclipse.ecf.internal.provider.xmpp.ui.wizards.XMPPSConnectWizard;
+import org.eclipse.ecf.presence.IPresenceContainerAdapter;
+import org.eclipse.ecf.presence.im.IChatManager;
+import org.eclipse.ecf.presence.im.IChatMessageSender;
+import org.eclipse.ecf.presence.im.ITypingMessageSender;
+import org.eclipse.ecf.presence.roster.IRosterManager;
+import org.eclipse.ecf.presence.ui.MessagesView;
+import org.eclipse.ecf.provider.xmpp.XMPPContainer;
+import org.eclipse.ecf.provider.xmpp.XMPPSContainer;
+import org.eclipse.ecf.provider.xmpp.identity.XMPPID;
import org.eclipse.ecf.ui.IConnectWizard;
import org.eclipse.ecf.ui.hyperlink.AbstractURLHyperlink;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ListDialog;
/**
*
@@ -29,9 +56,171 @@ public class XMPPHyperlink extends AbstractURLHyperlink {
private static final String ECF_XMPP_CONTAINER_NAME = "ecf.xmpp.smack"; //$NON-NLS-1$
private static final String ECF_XMPPS_CONTAINER_NAME = "ecf.xmpps.smack"; //$NON-NLS-1$
+ private static final IContainer[] EMPTY = new IContainer[0];
boolean isXMPPS;
-
+
+ protected IContainer[] getContainers() {
+ IContainerManager manager = Activator.getDefault()
+ .getContainerManager();
+ if (manager == null)
+ return EMPTY;
+ List results = new ArrayList();
+ IContainer[] containers = manager.getAllContainers();
+ for (int i = 0; i < containers.length; i++) {
+ ID connectedID = containers[i].getConnectedID();
+ // Must be connected
+ if (connectedID != null) {
+ IPresenceContainerAdapter adapter = (IPresenceContainerAdapter) containers[i]
+ .getAdapter(IPresenceContainerAdapter.class);
+ // Must also be a presence container
+ if (adapter != null) {
+ // Must also be an XMPP/XMPPS Container
+ if ((isXMPPS && containers[i] instanceof XMPPSContainer)
+ || (!isXMPPS && containers[i] instanceof XMPPContainer))
+ results.add(containers[i]);
+ }
+ }
+ }
+ return (IContainer[]) results.toArray(EMPTY);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.ui.hyperlink.AbstractURLHyperlink#open()
+ */
+ public void open() {
+ IContainer[] containers = getContainers();
+ if (containers.length > 0)
+ chooseAccountAndOpenMessagesView(containers);
+ else {
+ if (MessageDialog
+ .openQuestion(
+ null,
+ Messages.XMPPHyperlink_CONNECT_ACCOUNT_DIALOG_TITLE,
+ NLS
+ .bind(
+ Messages.XMPPHyperlink_CONNECT_ACCOUNT_DIALOG_MESSAGE,
+ getURI().getAuthority()))) {
+ super.open();
+ }
+ }
+ }
+
+ /**
+ * @param adapters
+ */
+ private void chooseAccountAndOpenMessagesView(final IContainer[] containers) {
+ // If there's only one choice then use it
+ if (containers.length == 1) {
+ openMessagesView((IPresenceContainerAdapter) containers[0]
+ .getAdapter(IPresenceContainerAdapter.class));
+ return;
+ } else {
+ final IPresenceContainerAdapter[] adapters = new IPresenceContainerAdapter[containers.length];
+ for (int i = 0; i < containers.length; i++)
+ adapters[i] = (IPresenceContainerAdapter) containers[i]
+ .getAdapter(IPresenceContainerAdapter.class);
+ ListDialog dialog = new ListDialog(null);
+ dialog.setContentProvider(new IStructuredContentProvider() {
+
+ public Object[] getElements(Object inputElement) {
+ return adapters;
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+ });
+ dialog.setInput(adapters);
+ dialog.setAddCancelButton(true);
+ dialog.setBlockOnOpen(true);
+ dialog.setTitle(Messages.XMPPHyperlink_SELECT_ACCOUNT_TITLE);
+ dialog.setMessage(Messages.XMPPHyperlink_SELECT_ACCOUNT_MESSAGE);
+ dialog.setHeightInChars(adapters.length > 4 ? adapters.length : 4);
+ dialog
+ .setInitialSelections(new IPresenceContainerAdapter[] { adapters[0] });
+ dialog.setLabelProvider(new ILabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ IRosterManager manager = ((IPresenceContainerAdapter) element)
+ .getRosterManager();
+ if (manager == null)
+ return null;
+ return manager.getRoster().getUser().getID().getName();
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ });
+ int result = dialog.open();
+ if (result == ListDialog.OK) {
+ Object[] res = dialog.getResult();
+ if (res.length > 0)
+ openMessagesView((IPresenceContainerAdapter) res[0]);
+ }
+ }
+ }
+
+ /**
+ * @param presenceContainerAdapter
+ */
+ private void openMessagesView(
+ IPresenceContainerAdapter presenceContainerAdapter) {
+ IChatManager chatManager = presenceContainerAdapter.getChatManager();
+ IRosterManager rosterManager = presenceContainerAdapter
+ .getRosterManager();
+ if (chatManager != null && rosterManager != null) {
+ IChatMessageSender icms = chatManager.getChatMessageSender();
+ ITypingMessageSender itms = chatManager.getTypingMessageSender();
+ try {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ MessagesView view = (MessagesView) ww.getActivePage().showView(
+ MessagesView.VIEW_ID);
+ ID localID = rosterManager.getRoster().getUser().getID();
+ view.selectTab(icms, itms, localID, new XMPPID(localID
+ .getNamespace(), getURI().getAuthority()));
+ } catch (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));
+ }
+ }
+ }
+
/**
* Creates a new URL hyperlink.
*
@@ -40,8 +229,8 @@ public class XMPPHyperlink extends AbstractURLHyperlink {
*/
public XMPPHyperlink(IRegion region, URI uri) {
super(region, uri);
- isXMPPS = getURI().getScheme()
- .equalsIgnoreCase(XMPPHyperlinkDetector.XMPPS_PROTOCOL);
+ isXMPPS = getURI().getScheme().equalsIgnoreCase(
+ XMPPHyperlinkDetector.XMPPS_PROTOCOL);
}
/*
@@ -51,8 +240,10 @@ public class XMPPHyperlink extends AbstractURLHyperlink {
*/
protected IConnectWizard createConnectWizard() {
String auth = getURI().getAuthority();
- if (isXMPPS) return new XMPPSConnectWizard(auth);
- else return new XMPPConnectWizard(auth);
+ if (isXMPPS)
+ return new XMPPSConnectWizard(auth);
+ else
+ return new XMPPConnectWizard(auth);
}
/*
@@ -61,10 +252,8 @@ public class XMPPHyperlink extends AbstractURLHyperlink {
* @see org.eclipse.ecf.ui.hyperlink.AbstractURLHyperlink#createContainer()
*/
protected IContainer createContainer() throws ContainerCreateException {
- return ContainerFactory
- .getDefault()
- .createContainer((isXMPPS) ? ECF_XMPPS_CONTAINER_NAME
- : ECF_XMPP_CONTAINER_NAME);
+ return ContainerFactory.getDefault().createContainer(
+ (isXMPPS) ? ECF_XMPPS_CONTAINER_NAME : ECF_XMPP_CONTAINER_NAME);
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/messages.properties b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/messages.properties
index 0ab3fb227..4b6c360e9 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/messages.properties
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp.ui/src/org/eclipse/ecf/internal/provider/xmpp/ui/messages.properties
@@ -22,4 +22,11 @@ XMPPCompoundContributionItem_SEND_ERROR_MESSAGE=Error sending file {0}. Error:
XMPPSConnectWizardPage_WIZARD_PAGE_TEMPLATE=<user>@<xmppsserver>[:port]
XMPPSConnectWizardPage_WIZARD_PAGE_PASSWORD=Password:
XMPPCompoundContributionItem_FILE_SEND_REFUSED_TITLE=File Send Refused
+XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_TITLE=Error opening view
+XMPPHyperlink_CONNECT_ACCOUNT_DIALOG_MESSAGE=You are not currently connected so messages cannot be sent.\n\nDo you want to connect and login to {0}?
+XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_MESSAGE=Error opening view: {0}. See Error Log for Details
XMPPCompoundContributionItem_FILE_SEND_REFUSED_MESSAGE=Send of {0} refused by {1}
+XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_LOG_STATUS_MESSAGE=Error opening messages view
+XMPPHyperlink_SELECT_ACCOUNT_TITLE=Select Account
+XMPPHyperlink_SELECT_ACCOUNT_MESSAGE=Select Account to Use
+XMPPHyperlink_CONNECT_ACCOUNT_DIALOG_TITLE=Connect To Account

Back to the top