summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-08 03:57:45 (EDT)
committerEike Stepper2007-10-08 03:57:45 (EDT)
commit814e122440c2d100e3a44f7ea090f2e97ca5c0b5 (patch)
tree2ab5df00b92bedf3cf9228bc7f3a38630aeb99c6
parent3f2fa2c6a6a58b40e7531ac07869ddaae78e5839 (diff)
downloadcdo-814e122440c2d100e3a44f7ea090f2e97ca5c0b5.zip
cdo-814e122440c2d100e3a44f7ea090f2e97ca5c0b5.tar.gz
cdo-814e122440c2d100e3a44f7ea090f2e97ca5c0b5.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/bundle/OM.java3
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/preferences/BuddiesPreferencePage.java8
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java101
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/BuddiesUtil.java10
4 files changed, 106 insertions, 16 deletions
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 e681339..00c308c 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
@@ -42,6 +42,9 @@ public abstract class OM
public static final OMPreference<String> PREF_PASSWORD = //
PREFS.initString("PREF_PASSWORD"); //$NON-NLS-1$
+ public static final OMPreference<Boolean> PREF_AUTO_CONNECT = //
+ PREFS.init("PREF_AUTO_CONNECT", true); //$NON-NLS-1$
+
/**
* @author Eike Stepper
*/
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 5034bdd..3a77525 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
@@ -18,6 +18,7 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
@@ -34,6 +35,8 @@ public class BuddiesPreferencePage extends OMPreferencePage
private Text password;
+ private Button autoConnect;
+
private ModifyListener modifyListener = new ModifyListener()
{
public void modifyText(ModifyEvent e)
@@ -73,6 +76,9 @@ public class BuddiesPreferencePage extends OMPreferencePage
password.setLayoutData(new GridData(100, SWT.DEFAULT));
password.addModifyListener(modifyListener);
+ new Label(composite, SWT.NONE);
+ autoConnect = new Button(composite, SWT.CHECK);
+
initValues();
return composite;
}
@@ -82,6 +88,7 @@ public class BuddiesPreferencePage extends OMPreferencePage
connectorDescription.setText(OM.PREF_CONNECTOR_DESCRIPTION.getValue());
userID.setText(OM.PREF_USER_ID.getValue());
password.setText(OM.PREF_PASSWORD.getValue());
+ autoConnect.setSelection(OM.PREF_AUTO_CONNECT.getValue());
}
@Override
@@ -90,6 +97,7 @@ public class BuddiesPreferencePage extends OMPreferencePage
OM.PREF_CONNECTOR_DESCRIPTION.setValue(connectorDescription.getText());
OM.PREF_USER_ID.setValue(userID.getText());
OM.PREF_PASSWORD.setValue(password.getText());
+ OM.PREF_AUTO_CONNECT.setValue(autoConnect.getSelection());
return super.performOk();
}
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 b4bf63d..5488927 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
@@ -10,6 +10,7 @@ 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.actions.SafeAction;
import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
import org.eclipse.net4j.util.ui.views.ContainerView;
@@ -19,30 +20,77 @@ public class BuddiesView extends ContainerView implements IListener
{
private IBuddySession session;
+ private boolean connecting;
+
public BuddiesView()
{
- String connectorDescription = OM.PREF_CONNECTOR_DESCRIPTION.getValue();
- IConnector connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, connectorDescription);
- if (connector == null)
+ if (isAutoConnect())
{
- throw new IllegalStateException("connector == null");
+ connect();
}
+ }
+
+ protected Boolean isAutoConnect()
+ {
+ return OM.PREF_AUTO_CONNECT.getValue();
+ }
- String userID = OM.PREF_USER_ID.getValue();
- String password = OM.PREF_PASSWORD.getValue();
- session = BuddiesUtil.openSession(connector, userID, password);
- if (session == null)
+ protected void connect()
+ {
+ new Thread("buddies-connector")
{
- throw new IllegalStateException("session == null");
- }
+ @Override
+ public void run()
+ {
+ try
+ {
+ connecting = true;
+ while (session == null && connecting && isAutoConnect())
+ {
+ String connectorDescription = OM.PREF_CONNECTOR_DESCRIPTION.getValue();
+ IConnector connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, connectorDescription);
+ if (connector == null)
+ {
+ throw new IllegalStateException("connector == null");
+ }
- session.addListener(this);
+ String userID = OM.PREF_USER_ID.getValue();
+ String password = OM.PREF_PASSWORD.getValue();
+ session = BuddiesUtil.openSession(connector, userID, password, 5000L);
+ if (session != null)
+ {
+ if (connecting)
+ {
+ session.addListener(BuddiesView.this);
+ }
+ else
+ {
+ session.close();
+ session = null;
+ }
+ }
+ }
+ }
+ finally
+ {
+ connecting = false;
+ }
+ }
+ }.start();
+ }
+
+ protected void disconnect()
+ {
+ session.removeListener(this);
+ session.close();
+ session = null;
+ connecting = false;
}
@Override
public void dispose()
{
- session.removeListener(this);
+ disconnect();
super.dispose();
}
@@ -54,7 +102,10 @@ public class BuddiesView extends ContainerView implements IListener
{
if (((ILifecycleEvent)event).getKind() == ILifecycleEvent.Kind.DEACTIVATED)
{
- closeView();
+ if (isAutoConnect())
+ {
+ connect();
+ }
}
}
}
@@ -99,7 +150,29 @@ public class BuddiesView extends ContainerView implements IListener
@Override
protected void fillLocalToolBar(IToolBarManager manager)
{
- // manager.add(addConnectorAction);
+ if (session == null && !connecting)
+ {
+ manager.add(new SafeAction("Connect", "Connect to buddies server")
+ {
+ @Override
+ protected void safeRun() throws Exception
+ {
+ connect();
+ }
+ });
+ }
+ else
+ {
+ manager.add(new SafeAction("Disonnect", "Disconnect from buddies server")
+ {
+ @Override
+ protected void safeRun() throws Exception
+ {
+ disconnect();
+ }
+ });
+ }
+
super.fillLocalToolBar(manager);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/BuddiesUtil.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/BuddiesUtil.java
index 8fc6795..b2474c5 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/BuddiesUtil.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/BuddiesUtil.java
@@ -14,6 +14,7 @@ import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.IConnector;
import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
import org.eclipse.net4j.internal.buddies.protocol.OpenSessionRequest;
+import org.eclipse.net4j.signal.SignalActor;
import org.eclipse.net4j.util.WrappedException;
/**
@@ -25,17 +26,22 @@ public final class BuddiesUtil
{
}
- public static IBuddySession openSession(IConnector connector, String userID, String password)
+ public static IBuddySession openSession(IConnector connector, String userID, String password, long timeout)
{
try
{
IChannel channel = connector.openChannel(BuddiesProtocolConstants.PROTOCOL_NAME, null);
OpenSessionRequest request = new OpenSessionRequest(channel, userID, password);
- return request.send();
+ return request.send(timeout);
}
catch (Exception ex)
{
throw WrappedException.wrap(ex);
}
}
+
+ public static IBuddySession openSession(IConnector connector, String userID, String password)
+ {
+ return openSession(connector, userID, password, SignalActor.NO_TIMEOUT);
+ }
}