use of org.eclipse.ecf.internal.example.collab.ui.SharedObjectContainerUI in project ecf by eclipse.
the class CollabClient method createAndConnectClient.
/**
* Create a new container instance, and connect to a remote server or group.
*
* @param containerType
* the container type used to create the new container instance.
* Must not be null.
* @param uri
* the uri that is used to create a targetID for connection. Must
* not be null.
* @param nickname
* an optional String nickname. May be null.
* @param connectData
* optional connection data. May be null.
* @param resource
* the resource that this container instance is associated with.
* Must not be null.
* @throws Exception
*/
public void createAndConnectClient(final String containerType, String uri, String nickname, final Object connectData, final IResource resource) throws Exception {
// First create the new container instance
final IContainer newClient = ContainerFactory.getDefault().createContainer(containerType);
// Create the targetID instance
ID targetID = IDFactory.getDefault().createID(newClient.getConnectNamespace(), uri);
// Setup username
String username = setupUsername(targetID, nickname);
// Create a new container entry to hold onto container once created
final ClientEntry newClientEntry = new ClientEntry(containerType, newClient);
// Setup sharedobject container if the new instance supports
// this
ISharedObjectContainer sharedObjectContainer = (ISharedObjectContainer) newClient.getAdapter(ISharedObjectContainer.class);
SharedObjectContainerUI socui = new SharedObjectContainerUI(this, sharedObjectContainer);
socui.setup(sharedObjectContainer, newClientEntry, resource, username);
// Now connect
try {
newClient.connect(targetID, ConnectContextFactory.createUsernamePasswordConnectContext(username, connectData));
} catch (ContainerConnectException e) {
// If we have a connect exception then we remove any previously
// added shared object
EclipseCollabSharedObject so = newClientEntry.getSharedObject();
if (so != null)
so.destroySelf();
throw e;
}
// only add container if the connect was successful
addClientForResource(newClientEntry, resource);
}
Aggregations