summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-07 17:57:16 (EDT)
committerEike Stepper2007-10-07 17:57:16 (EDT)
commitb0a0bad621a40e24eed3688bee13d11e6cc2f464 (patch)
tree49859fb16cfccdebc571142cf0cd52adc003fbed
parentae53ed5b67f6affcb6458dac6e76f3ec585a8895 (diff)
downloadcdo-b0a0bad621a40e24eed3688bee13d11e6cc2f464.zip
cdo-b0a0bad621a40e24eed3688bee13d11e6cc2f464.tar.gz
cdo-b0a0bad621a40e24eed3688bee13d11e6cc2f464.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ChannelInjector.java1
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java2
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/bundle/OM.java4
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/preferences/BuddiesPreferencePage.java2
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java73
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java3
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java22
7 files changed, 97 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ChannelInjector.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ChannelInjector.java
index 6b6481e..160c617 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ChannelInjector.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ChannelInjector.java
@@ -46,7 +46,6 @@ public class ChannelInjector implements IElementProcessor
protected IConnector getConnector(IManagedContainer container, String description)
{
-
URI uri = URI.createURI(description);
String factoryType = uri.scheme();
if (StringUtil.isEmpty(factoryType))
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
index 2288e6b..9523ea4 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
@@ -16,6 +16,7 @@ import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
import org.eclipse.net4j.buddies.server.IBuddySession;
import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import java.util.HashMap;
import java.util.Map;
@@ -33,6 +34,7 @@ public class BuddyAdmin extends Lifecycle implements IBuddyAdmin
public BuddyAdmin()
{
+ LifecycleUtil.activate(this);
}
public Map<String, IBuddyAccount> getAccounts()
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/bundle/OM.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/bundle/OM.java
index 6c82613..e681339 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/bundle/OM.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/bundle/OM.java
@@ -34,10 +34,10 @@ public abstract class OM
public static final OMPreferences PREFS = BUNDLE.preferences();
public static final OMPreference<String> PREF_CONNECTOR_DESCRIPTION = //
- PREFS.initString("PREF_CONNECTOR_DESCRIPTION"); //$NON-NLS-1$
+ PREFS.init("PREF_CONNECTOR_DESCRIPTION", "tcp://localhost"); //$NON-NLS-1$
public static final OMPreference<String> PREF_USER_ID = //
- PREFS.initString("PREF_USER_ID"); //$NON-NLS-1$
+ PREFS.init("PREF_USER_ID", System.getProperty("user.name")); //$NON-NLS-1$
public static final OMPreference<String> PREF_PASSWORD = //
PREFS.initString("PREF_PASSWORD"); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/preferences/BuddiesPreferencePage.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/preferences/BuddiesPreferencePage.java
index b154f4b..5034bdd 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/preferences/BuddiesPreferencePage.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/preferences/BuddiesPreferencePage.java
@@ -58,7 +58,7 @@ public class BuddiesPreferencePage extends OMPreferencePage
composite.setLayout(grid);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- new Label(composite, SWT.NONE).setText("Connector description:");
+ new Label(composite, SWT.NONE).setText("Server:");
connectorDescription = new Text(composite, SWT.BORDER);
connectorDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
connectorDescription.addModifyListener(modifyListener);
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
index 7240c62..ffda3c5 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
@@ -1,23 +1,88 @@
package org.eclipse.net4j.buddies.internal.ui.views;
+import org.eclipse.net4j.IConnector;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buddies.BuddiesUtil;
+import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
import org.eclipse.net4j.util.ui.views.ContainerView;
import org.eclipse.jface.action.IToolBarManager;
-public class BuddiesView extends ContainerView
+public class BuddiesView extends ContainerView implements IListener
{
+ private IBuddySession session;
+
public BuddiesView()
{
+ String connectorDescription = OM.PREF_CONNECTOR_DESCRIPTION.getValue();
+ IConnector connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, connectorDescription);
+ if (connector == null)
+ {
+ throw new IllegalStateException("connector == null");
+ }
+
+ String userID = OM.PREF_USER_ID.getValue();
+ String password = OM.PREF_PASSWORD.getValue();
+ session = BuddiesUtil.openSession(connector, userID, password);
+ session.addListener(this);
+ }
+
+ @Override
+ public void dispose()
+ {
+ session.removeListener(this);
+ super.dispose();
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event.getSource() == session)
+ {
+ if (event instanceof ILifecycleEvent)
+ {
+ if (((ILifecycleEvent)event).getKind() == ILifecycleEvent.Kind.DEACTIVATED)
+ {
+ closeView();
+ }
+ }
+ }
+ }
+
+ protected void closeView()
+ {
+ try
+ {
+ getSite().getShell().getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ getSite().getPage().hideView(BuddiesView.this);
+ BuddiesView.this.dispose();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (Exception ignore)
+ {
+ }
}
@Override
- protected IManagedContainer getContainer()
+ protected IContainer<?> getContainer()
{
- return IPluginContainer.INSTANCE;
+ return session;
}
@Override
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java
index 99705d8..5ffcc4f 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java
@@ -1,7 +1,6 @@
package org.eclipse.net4j.util.ui.views;
import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.internal.ui.SharedIcons;
import org.eclipse.net4j.util.ui.actions.SafeAction;
@@ -124,7 +123,7 @@ public abstract class ContainerView extends ViewPart implements ISetSelectionTar
return null;
}
- protected abstract IManagedContainer getContainer();
+ protected abstract IContainer<?> getContainer();
protected void hookDoubleClick()
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
index 4bf7b52..9c17e0d 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j;
import org.eclipse.net4j.internal.util.security.RandomizerFactory;
+import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.internal.net4j.AcceptorFactory;
@@ -28,6 +29,8 @@ import java.util.concurrent.ExecutorService;
*/
public final class Net4jUtil
{
+ public static final String SCHEME_SEPARATOR = "://";
+
public static final short DEFAULT_BUFFER_CAPACITY = 4096;
private Net4jUtil()
@@ -62,6 +65,25 @@ public final class Net4jUtil
return (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, type, description);
}
+ public static IConnector getConnector(IManagedContainer container, String description)
+ {
+ int pos = description.indexOf(SCHEME_SEPARATOR);
+ if (pos <= 0)
+ {
+ throw new IllegalArgumentException("Connector type (scheme) missing: " + description);
+ }
+
+ String factoryType = description.substring(0, pos);
+
+ String connectorDescription = description.substring(pos + SCHEME_SEPARATOR.length());
+ if (StringUtil.isEmpty(connectorDescription))
+ {
+ throw new IllegalArgumentException("Illegal connector description: " + description);
+ }
+
+ return (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, factoryType, connectorDescription);
+ }
+
public static IBufferProvider getBufferProvider(Object object)
{
if (object instanceof IBufferProvider)