diff options
| author | slewis | 2005-02-17 06:45:41 +0000 |
|---|---|---|
| committer | slewis | 2005-02-17 06:45:41 +0000 |
| commit | 9b78c684f2260416737fec14779acdf15faa4c06 (patch) | |
| tree | 683bc6bcee9b68f4032ba479ee9593605ad5870a | |
| parent | 5705091d5ef4d81df0dfa52b2ea34f17e334c2ea (diff) | |
| download | org.eclipse.ecf-9b78c684f2260416737fec14779acdf15faa4c06.tar.gz org.eclipse.ecf-9b78c684f2260416737fec14779acdf15faa4c06.tar.xz org.eclipse.ecf-9b78c684f2260416737fec14779acdf15faa4c06.zip | |
Changes/improvements to structure of top-level Client class in org.eclipse.ecf.example.collab to allow for multiple containers (of different providers) for a single project. Changed getContainer() API to getContainer(IProject). Changed call in org.eclipse.ecf.example.sdo.editor to use new API.
6 files changed, 235 insertions, 79 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java index 84b6c9778..1a6992f38 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/Client.java @@ -11,9 +11,12 @@ package org.eclipse.ecf.example.collab; +import java.net.ConnectException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; import java.util.Vector; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; @@ -41,12 +44,110 @@ public class Client { public static final String FILE_DIRECTORY = "received_files"; public static final String USERNAME = System.getProperty("user.name"); public static final String ECFDIRECTORY = "ECF_" + FILE_DIRECTORY + "/"; + static ID defaultGroupID = null; + /* static ISharedObjectContainer client = null; static EclipseCollabSharedObject sharedObject = null; - static ID defaultGroupID = null; static ID groupID = null; static ID sharedObjectID = null; + */ + static Hashtable clients = new Hashtable(); + public static class ClientEntry { + String type; + ISharedObjectContainer client; + EclipseCollabSharedObject obj; + + public ClientEntry(String type, ISharedObjectContainer cont) { + this.type = type; + this.client = cont; + } + public String getType() { + return type; + } + public ISharedObjectContainer getContainer() { + return client; + } + public void setObject(EclipseCollabSharedObject obj) { + this.obj = obj; + } + public EclipseCollabSharedObject getObject() { + return obj; + } + public void dispose() { + /* + if (obj != null) { + obj.destroySelf(); + obj = null; + } + */ + /* + if (client != null) { + client.dispose(1000); + client = null; + } + */ + } + } + + protected static void addClientEntry(IProject proj, ClientEntry entry) { + synchronized (clients) { + Vector v = (Vector) clients.get(proj.getName()); + if (v == null) { + v = new Vector(); + } + v.add(entry); + clients.put(proj.getName(),v); + } + } + protected static Vector getClientEntries(IProject proj) { + synchronized (clients) { + return (Vector) clients.get(proj.getName()); + } + } + protected static ClientEntry getClientEntry(IProject proj, String type) { + synchronized (clients) { + Vector v = (Vector) getClientEntries(proj); + if (v == null) return null; + for(Iterator i=v.iterator(); i.hasNext(); ) { + ClientEntry e = (ClientEntry) i.next(); + if (isType(e,type)) { + return e; + } + } + } + return null; + } + protected static boolean containsEntry(IProject proj, String type) { + synchronized (clients) { + Vector v = (Vector) clients.get(proj.getName()); + if (v == null) return false; + for(Iterator i=v.iterator(); i.hasNext(); ) { + ClientEntry e = (ClientEntry) i.next(); + if (isType(e,type)) { + return true; + } + } + } + return false; + } + protected static void removeClientEntry(IProject proj, String type) { + synchronized (clients) { + Vector v = (Vector) clients.get(proj.getName()); + if (v == null) return; + ClientEntry remove = null; + for(Iterator i=v.iterator(); i.hasNext(); ) { + ClientEntry e = (ClientEntry) i.next(); + if (isType(e,type)) { + remove = e; + } + } + if (remove != null) v.remove(remove); + if (v.size()==0) { + clients.remove(proj.getName()); + } + } + } public Client() throws Exception { defaultGroupID = IDFactory.makeStringID(DEFAULT_SERVER_ID); } @@ -77,72 +178,86 @@ public class Client { return projects[0]; } - protected void makeAndAddSharedObject(ISharedObjectContainer client, - IProject proj, User user, String fileDir) throws Exception { + protected void makeAndAddSharedObject(final ClientEntry client, + final IProject proj, User user, String fileDir) throws Exception { IWorkbenchWindow ww = PlatformUI.getWorkbench() .getActiveWorkbenchWindow(); - sharedObject = new EclipseCollabSharedObject(proj, ww, + EclipseCollabSharedObject sharedObject = new EclipseCollabSharedObject(proj, ww, user, fileDir); sharedObject.setListener(new SharedObjectEventListener() { public void memberRemoved(ID member) { + ID groupID = client.getContainer().getGroupID(); if (member.equals(groupID)) { - disposeClient(); + disposeClient(proj, client); } } public void memberAdded(ID member) {} public void otherActivated(ID other) {} public void otherDeactivated(ID other) {} public void windowClosing() { - disposeClient(); + disposeClient(proj, client); } }); ID newID = IDFactory.makeStringID(COLLAB_SHARED_OBJECT_ID); - client.getSharedObjectManager().addSharedObject(newID, sharedObject, + client.getContainer().getSharedObjectManager().addSharedObject(newID, sharedObject, new HashMap(), null); + client.setObject(sharedObject); } - protected void addObjectToClient(ISharedObjectContainer client, + protected void addObjectToClient(ClientEntry client, String username, IProject proj) throws Exception { IProject project = (proj == null) ? getFirstProjectFromWorkspace() : proj; String fileDir = getSharedFileDirectoryForProject(project); String projName = (project == null) ? "<workspace>" : project.getName(); - User user = getUserData(client.getClass().getName(),client.getConfig().getID(), + User user = getUserData(client.getClass().getName(),client.getContainer().getConfig().getID(), (username == null) ? USERNAME : username, projName); makeAndAddSharedObject(client, project, user, fileDir); } - public synchronized boolean isConnected() { - return (client != null); + public synchronized ClientEntry isConnected(IProject project, String type) { + if (type == null) type = GENERIC_CONTAINER_CLIENT_NAME; + ClientEntry entry = getClientEntry(project,type); + return entry; } + public static boolean isType(ClientEntry entry, String type) { + if (entry == null || type == null) return false; + String name = entry.getType(); + if (name.equals(type)) return true; + else return false; + } public synchronized void createAndConnectClient(String type, ID gID, String username, Object data, IProject proj) throws Exception { + + if (proj == null) throw new NullPointerException("Project cannot be null"); + ClientEntry entry = getClientEntry(proj,type); + if (entry != null) { + // Already got a session going...that's OK as long as it's not of the same type... + throw new ConnectException("Already connected"); + } + String containerType = (type==null)?GENERIC_CONTAINER_CLIENT_NAME:type; - client = SharedObjectContainerFactory - .makeSharedObjectContainer(containerType); + ISharedObjectContainer client = SharedObjectContainerFactory + .makeSharedObjectContainer(containerType); + ClientEntry newClient = new ClientEntry(containerType,client); if (gID == null) { - groupID = defaultGroupID; - } else { - groupID = gID; - } - addObjectToClient(client, username, proj); - if (groupID == null) - client.joinGroup(defaultGroupID, data); - else - client.joinGroup(groupID, data); + gID = defaultGroupID; + } + if (containerType.equals(GENERIC_CONTAINER_CLIENT_NAME)) addObjectToClient(newClient, username, proj); + client.joinGroup(gID, data); + // only add client if the join successful + addClientEntry(proj,newClient); } - public synchronized void disposeClient() { - if (isConnected()) { - try { - if (sharedObject != null) sharedObject.destroySelf(); - } catch (Exception e) {} - sharedObject = null; - } + public synchronized void disposeClient(IProject proj, ClientEntry entry) { + entry.dispose(); + removeClientEntry(proj,entry.getType()); } - - public synchronized ISharedObjectContainer getContainer() { - return client; + + public synchronized static ISharedObjectContainer getContainer(IProject proj) { + ClientEntry entry = getClientEntry(proj,GENERIC_CONTAINER_CLIENT_NAME); + if (entry != null) return entry.getContainer(); + else return null; } } diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/actions/ClientConnectAction.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/actions/ClientConnectAction.java index 1e2fddf8b..a93645944 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/actions/ClientConnectAction.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/actions/ClientConnectAction.java @@ -21,7 +21,9 @@ import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.example.collab.Client; import org.eclipse.ecf.example.collab.ClientPlugin; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; @@ -56,10 +58,12 @@ public class ClientConnectAction implements IWorkbenchWindowActionDelegate { protected Object data = null; protected IProject project = null; protected String projectName = null; + protected Client client = null; public ClientConnectAction() { try { targetID = IDFactory.makeStringID(DEFAULT_SERVER_ID); + client = new Client(); } catch (Exception e) { } @@ -76,20 +80,26 @@ public class ClientConnectAction implements IWorkbenchWindowActionDelegate { super(name); } public IStatus run(IProgressMonitor pm) { - Client ct = null; try { - ct = new Client(); + Status okStatus = new Status(IStatus.OK,ClientPlugin.PLUGIN_ID,IStatus.OK,"Connected",null); // Make sure we're disconnected - if (ct.isConnected()) { - ct.disposeClient(); + Client.ClientEntry entry = client.isConnected(project,containerType); + if (entry != null) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + Display.getDefault().beep(); + MessageDialog.openInformation( + null, + "Already connected", + "Already connected for provider "+containerType); + } + }); + return okStatus; } // Actually create and connect client - ct.createAndConnectClient(containerType,targetID,username,data,project); - return new Status(IStatus.OK,ClientPlugin.PLUGIN_ID,IStatus.OK,"Connected",null); + client.createAndConnectClient(containerType,targetID,username,data,project); + return okStatus; } catch (Exception e) { - if (ct != null) { - ct.disposeClient(); - } return new Status(IStatus.ERROR,ClientPlugin.PLUGIN_ID,IStatus.OK,"Could not connect to group '"+targetID.getName()+"'",e); } } diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/JoinGroupWizardPage.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/JoinGroupWizardPage.java index 5bae16fd8..3a4149639 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/JoinGroupWizardPage.java +++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/JoinGroupWizardPage.java @@ -18,6 +18,8 @@ import org.eclipse.ecf.core.SharedObjectContainerDescription; import org.eclipse.ecf.core.SharedObjectContainerFactory; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; @@ -28,11 +30,23 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; public class JoinGroupWizardPage extends WizardPage { + + protected static final String CLASSNAME = JoinGroupWizardPage.class.getName(); + + protected static final String USER_NAME_SYSTEM_PROPERTY = "user.name"; + + protected static final String ISCLIENT_PROP_NAME = CLASSNAME+".isClient"; + protected static final String DEFAULTGROUPID_PROP_NAME = CLASSNAME+".defaultgroupid"; + protected static final String EXAMPLEGROUPID_PROP_NAME = CLASSNAME+".examplegroupid"; + protected static final String USEPASSWORD_PROP_NAME = CLASSNAME+".usepassword"; + protected static final String URLPREFIX_NAME = CLASSNAME+".urlprefix"; + protected static final String GROUPIDLABEL_PROP_NAME = CLASSNAME+".groupIDLabel"; + protected static final String PAGE_DESCRIPTION = "Join ECF Collaboration Group"; - private static final String JOINGROUP_FIELDNAME = "Group ID:"; - private static final String NICKNAME_FIELDNAME = "Nickname:"; - private static final String ECF_DEFAULT_URL = "ecftcp://localhost:3282/server"; - protected static final String ECF_TEMPLATE_URL = "ecftcp://<machinename>:<port>/<name>"; + protected static final String JOINGROUP_FIELDNAME = "Group ID:"; + protected static final String NICKNAME_FIELDNAME = "Nickname:"; + protected static final String ECF_DEFAULT_URL = "ecftcp://localhost:3282/server"; + protected static final String ECF_TEMPLATE_URL = "<protocol>://<machinename>:<port>/<servicename>"; protected static final String PAGE_TITLE = "Join ECF Group"; protected static final String DEFAULT_CLIENT = "org.eclipse.ecf.provider.generic.Client"; @@ -54,12 +68,22 @@ public class JoinGroupWizardPage extends WizardPage { protected Combo combo; protected Text password_text; protected List containerDescriptions = new ArrayList(); + protected String urlPrefix = ""; + protected Label groupIDLabel; protected void modifyUI(Map props) { if (props != null) { - String usePassword = (String) props.get("usepassword"); - String examplegroupid = (String) props.get("examplegroupid"); - String defaultgroupid = (String) props.get("defaultgroupid"); + String usePassword = (String) props.get(USEPASSWORD_PROP_NAME); + String examplegroupid = (String) props.get(EXAMPLEGROUPID_PROP_NAME); + String defaultgroupid = (String) props.get(DEFAULTGROUPID_PROP_NAME); + urlPrefix = (String) props.get(URLPREFIX_NAME); + if (urlPrefix == null) urlPrefix = ""; + String groupLabel = (String) props.get(GROUPIDLABEL_PROP_NAME); + if (groupLabel != null) { + groupIDLabel.setText(groupLabel); + } else { + groupIDLabel.setText(JOINGROUP_FIELDNAME); + } // turn off password unless used if (usePassword != null){ password_label.setVisible(true); @@ -83,17 +107,14 @@ public class JoinGroupWizardPage extends WizardPage { String name = desc.getName(); String description = desc.getDescription(); Map props = desc.getProperties(); - String isClient = (String) props.get("isClient"); - if (isClient != null) { - if (DEFAULT_CLIENT.equals(name)) { - def = index; - defProps = props; - } - combo.add(description+" - "+name,index); - combo.setData(""+index,desc); - containerDescriptions.add(desc); - index++; + if (DEFAULT_CLIENT.equals(name)) { + def = index; + defProps = props; } + combo.add(description+" - "+name,index); + combo.setData(""+index,desc); + containerDescriptions.add(desc); + index++; } combo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { @@ -111,7 +132,6 @@ public class JoinGroupWizardPage extends WizardPage { if (defProps != null) modifyUI(defProps); } - //protected public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); final GridLayout gridLayout = new GridLayout(); @@ -132,14 +152,23 @@ public class JoinGroupWizardPage extends WizardPage { example_label = new Label(container, SWT.NONE); example_label.setText(template_url); - final Label label = new Label(container, SWT.NONE); - label.setText(JOINGROUP_FIELDNAME); + groupIDLabel = new Label(container, SWT.NONE); + groupIDLabel.setText(JOINGROUP_FIELDNAME); joingroup_text = new Text(container, SWT.BORDER); joingroup_text.setText(default_url); final GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 140; joingroup_text.setLayoutData(gridData); + joingroup_text.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + String t = joingroup_text.getText(); + joingroup_text.setSelection(t.length()); + } + + public void focusLost(FocusEvent e) { + } + }); final Label label_1 = new Label(container, SWT.NONE); label_1.setLayoutData(new GridData()); @@ -148,7 +177,16 @@ public class JoinGroupWizardPage extends WizardPage { nickname_text = new Text(container, SWT.BORDER); final GridData nickname = new GridData(GridData.HORIZONTAL_ALIGN_FILL); nickname_text.setLayoutData(nickname); - nickname_text.setText(System.getProperty("user.name")); + nickname_text.setText(System.getProperty(USER_NAME_SYSTEM_PROPERTY)); + nickname_text.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + String t = nickname_text.getText(); + nickname_text.selectAll(); + } + + public void focusLost(FocusEvent e) { + } + }); password_label = new Label(container, SWT.NONE); password_label.setText("Password:"); @@ -164,7 +202,11 @@ public class JoinGroupWizardPage extends WizardPage { } public String getJoinGroupText() { - return joingroup_text.getText().trim(); + String textValue = joingroup_text.getText().trim(); + if (!urlPrefix.equals("") && !textValue.startsWith(urlPrefix)) { + textValue = urlPrefix+textValue; + } + return textValue; } public String getNicknameText() { diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java index 9a2be299d..2f1cfaed8 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java @@ -12,7 +12,6 @@ package org.eclipse.ecf.example.sdo.editor; import java.util.MissingResourceException; import java.util.ResourceBundle; - import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -31,7 +30,6 @@ import org.eclipse.ecf.sdo.WaitableSubscriptionCallback; import org.eclipse.ecf.sdo.emf.EMFUpdateProvider; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; - import commonj.sdo.DataGraph; /** @@ -180,16 +178,7 @@ public class EditorPlugin extends AbstractUIPlugin { private ISharedObjectContainer getContainer(IProject project) throws ECFException { - if (client == null) { - try { - client = new Client(); - } catch (Exception e) { - throw new ECFException(e); - } - } - - // TODO Change to getContainer(project) when API available. - return client.getContainer(); + return Client.getContainer(project); } private PublishedGraphTracker getTracker(ISharedObjectContainer container) diff --git a/framework/bundles/org.eclipse.ecf.provider/plugin.xml b/framework/bundles/org.eclipse.ecf.provider/plugin.xml index d69cd5498..d4a347175 100644 --- a/framework/bundles/org.eclipse.ecf.provider/plugin.xml +++ b/framework/bundles/org.eclipse.ecf.provider/plugin.xml @@ -16,13 +16,13 @@ name="keepAlive"/> <property value="ecftcp://<server>:<port>/<servicename>" - name="examplegroupid"/> + name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.examplegroupid"/> <property value="ecftcp://localhost:3282/server" - name="defaultgroupid"/> + name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.defaultgroupid"/> <property value="true" - name="isClient"/> + name="org.eclipse.ecf.example.collab.ui.JoinGroupWizardPage.isClient"/> </containerFactory> </extension> <extension diff --git a/framework/bundles/org.eclipse.ecf.ui/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.ui/META-INF/MANIFEST.MF index 619b41bda..b990ff162 100644 --- a/framework/bundles/org.eclipse.ecf.ui/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.ui/META-INF/MANIFEST.MF @@ -10,5 +10,5 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ecf, org.eclipse.core.runtime Eclipse-AutoStart: true -Provide-Package: org.eclipse.ecf.ui.presence, org.eclipse.ecf.ui +Provide-Package: org.eclipse.ecf.ui.presence, org.eclipse.ecf.ui, org.eclipse.ecf.ui.messaging |
