Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkgilmer2005-02-18 07:36:59 +0000
committerkgilmer2005-02-18 07:36:59 +0000
commit476a9291d906c6618bf59a1806719413f0b0029a (patch)
tree0aa32a23fe9427f975a69c76169b62f1fad8427e
parent9b78c684f2260416737fec14779acdf15faa4c06 (diff)
downloadorg.eclipse.ecf-476a9291d906c6618bf59a1806719413f0b0029a.tar.gz
org.eclipse.ecf-476a9291d906c6618bf59a1806719413f0b0029a.tar.xz
org.eclipse.ecf-476a9291d906c6618bf59a1806719413f0b0029a.zip
Chat StyledText widget now uses color to denote message origin.
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/plugin.xml2
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPlugin.java5
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPluginConstants.java1
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java2003
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/io/EclipseFileTransfer.java267
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatComposite.java65
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatLine.java100
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ClientPreferencePage.java4
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatClientView.java49
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatView.java2
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/TeamChat.java2
11 files changed, 1357 insertions, 1143 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml b/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
index 0c2ed1ff4..d2be27984 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
+++ b/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
@@ -56,7 +56,7 @@
point="org.eclipse.ui.preferencePages">
<page
class="org.eclipse.ecf.example.collab.ui.ClientPreferencePage"
- name="ECF"
+ name="ECF Collaboration"
id="org.eclipse.ecf.example.collab.ui.preferences"/>
</extension>
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPlugin.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPlugin.java
index 9a06ce14c..19ceaf342 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPlugin.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPlugin.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -93,6 +94,10 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
return this.fontRegistry;
}
+ public Shell getActiveShell() {
+ return this.getWorkbench().getDisplay().getActiveShell();
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPluginConstants.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPluginConstants.java
index a81ff4517..03442e1e4 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPluginConstants.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ClientPluginConstants.java
@@ -26,6 +26,7 @@ public interface ClientPluginConstants {
public static final String PREF_CONFIRM_FILE_SEND = "confirmFileSend";
public static final String PREF_CONFIRM_REMOTE_VIEW = "confirmRemoteView";
public static final String PREF_FILE_SEND_PATH = "findSendPath";
+ public static final String PREF_CONFIRM_FILE_RECEIVE = "confirmFileReceive";
/*
* Contstants used to describe decoration images.
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
index cac281cbd..d05900f9a 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
@@ -1,13 +1,13 @@
/****************************************************************************
-* Copyright (c) 2004 Composent, Inc. and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Eclipse Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/epl-v10.html
-*
-* Contributors:
-* Composent, Inc. - initial API and implementation
-*****************************************************************************/
+ * Copyright (c) 2004 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
package org.eclipse.ecf.example.collab.share;
@@ -27,6 +27,7 @@ import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.example.collab.ClientPlugin;
import org.eclipse.ecf.example.collab.share.io.EclipseFileTransfer;
import org.eclipse.ecf.example.collab.share.io.FileTransferParams;
+import org.eclipse.ecf.example.collab.ui.ChatLine;
import org.eclipse.ecf.example.collab.ui.FileReceiverUI;
import org.eclipse.ecf.example.collab.ui.LineChatClientView;
import org.eclipse.ecf.example.collab.ui.LineChatHandler;
@@ -43,988 +44,1004 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class EclipseCollabSharedObject extends GenericSharedObject implements
- LineChatHandler, EclipseProject {
- protected static final String CHAT_VIEW_ID = LineChatView.class.getName();
- protected static String DEFAULTTREETOPLABEL = "Presence";
- public static final String ECLIPSEOBJECTNAME = "chat";
- public static final String INIT_TEXT = "Collaboration for '";
- Date creationTime = new Date();
- String downloaddir = "";
- protected LineChatClientView localGUI;
- IProject localProject;
- User localUser;
- String localVersion = "";
- ID serverID;
- SharedObjectEventListener sessionListener;
- IWorkbenchWindow shellWindow;
- String treeTopLabel;
- String windowtitle = "Chat";
- URL[] projectCodebase = null;
-
- public EclipseCollabSharedObject() {
- }
-
- public EclipseCollabSharedObject(IProject proj, IWorkbenchWindow shell,
- User user, String downloaddir) {
- this.localProject = proj;
- this.shellWindow = shell;
- this.localUser = user;
- this.downloaddir = downloaddir;
- localGUI = getOutputWindow();
- if (localGUI == null)
- throw new NullPointerException(
- "Local GUI cannot be created...exiting");
- }
-
- public void activated(ID[] others) {
- super.activated(others);
- if (localGUI == null) {
- try {
- if (!getContext().isGroupServer())
- destroySelfLocal();
- } catch (Exception e) {
- debugdump(e, "Unable to check whether we are server instance");
- destroySelfLocal();
- }
- }
- }
-
- public void chatException(Exception e, String text) {
- debugdump(e, text);
- }
-
- public void chatGUIDestroy() {
- debugmsg("chatGUIDestroy()");
- if (sessionListener != null) {
- sessionListener.windowClosing();
- }
- destroySelf();
- }
-
- protected void checkRegisterProxyPolicy(String operation, User sender,
- String proxyClass) throws SecurityException {
- // by default let it through;
- }
-
- public void deactivated() {
- super.deactivated();
- synchronized (this) {
- if (localGUI != null) {
- localGUI.disposeClient();
- localGUI = null;
- }
- }
- if (sessionListener != null) {
- sessionListener = null;
- }
- if (shellWindow != null) {
- shellWindow = null;
- }
- if (localProject != null) {
- localProject = null;
- }
- }
-
- public void debugdump(Exception e, String aString) {
- }
-
- public void debugmsg(String aString) {
- // ClientPlugin.log(aString);
- }
-
- public void destroySelf() {
- // Make sure we disconnect
- try {
- if (isHost()) {
- try {
- // try to disconnect
- leaveGroup();
- } catch (Exception e) {
- debugdump(e, "Exception leaving space");
- }
- }
- } catch (Exception e) {
- debugdump(e,"Exception in destroySelf");
- }
- // Destroy self
- super.destroySelfLocal();
- }
-
- public String getDownloaddir(String dir) {
- return downloaddir;
- }
-
- public SharedObjectEventListener getListener() {
- return sessionListener;
- }
-
- public String getLocalFullProjectPath() {
- String eclipseDir = null;
- String result = null;
- try {
- eclipseDir = Platform.getLocation().toOSString();
- } catch (Exception e) {
- debugdump(e,
- "EclipseCollabSharedObject. Exception getting local project path");
- }
- if (eclipseDir==null) {
- eclipseDir = ".";
- }
- String projectDir = null;
- if (getProject()==null) {
- projectDir = downloaddir;
- } else {
- projectDir = getProject().getFullPath().toOSString();
- }
- File fresult = new File(eclipseDir,projectDir);
- return fresult.getAbsolutePath();
- }
-
- public String getLocalFullDownloadPath() {
- String projectPath = getLocalFullProjectPath();
- File downloadpath = new File(projectPath,downloaddir);
- return downloadpath.getAbsolutePath();
- }
- public ID getObjectID() {
- return getID();
- }
-
- protected LineChatClientView getOutputWindow() {
- final String pn = (localProject==null)?"<workspace>":localProject.getName();
- final String projectName = pn;
- final String init = INIT_TEXT + pn
- + "' project\n\n";
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (LineChatView.isDisposed())
- showView();
- localGUI = LineChatView.makeClientView(
- EclipseCollabSharedObject.this, projectName, init,
- getLocalFullDownloadPath());
- } catch (Exception e) {
- debugdump(e,
- "Exception creating output window in getOutputWindow");
- }
- }
- });
- return localGUI;
- }
-
- public IProject getProject() {
- return localProject;
- }
-
- protected SharedObjectDescription getReplicaDescription(ID remoteID) {
- // no replication...depend upon clients to create
- // local instance of their own copy of this object...with local
- // data.
- return null;
- }
-
- public ID getServerID() {
- return serverID;
- }
-
- public String getTreeTopLabel() {
- return DEFAULTTREETOPLABEL;
- }
-
- public ID getUniqueID() {
- try {
- return getLocalContainerID();
- } catch (Exception e) {
- debugdump(e, "Exception getting unique id");
- return null;
- }
- }
-
- public User getUser() {
- return localUser;
- }
-
- public User getUserForID(final ID user) {
- if (localGUI != null) {
- return localGUI.getUser(user);
- }
- return null;
- }
-
- public String getUserName() {
- return localUser.getNickname();
- }
-
- public String getVersionString() {
- return localVersion;
- }
-
- public String getWindowTitle() {
- return windowtitle;
- }
-
- public IWorkbenchWindow getWorkbenchWindow() {
- return shellWindow;
- }
-
- // SharedObjectMsg handlers
- protected void handleCreateObject(SharedObjectDescription cons) {
- try {
- makeObject(cons.getID(), cons.getClassname(), cons.getProperties());
- } catch (Exception e) {
- debugdump(e, "Exception creating local object " + cons);
- }
- }
-
- public void handleNotifyUserAdded(User user) {
- boolean add = false;
- try {
- ID[] members = getContext().getGroupMemberIDs();
- for (int i = 0; i < members.length; i++) {
- if (members[i].equals(user.getUserID())) {
- add = true;
- break;
- }
- }
- } catch (Exception e) {
- debugdump(e, "Exception checking for membership");
- }
- if (add) {
- boolean addUserResult = false;
- if (localGUI != null) {
- addUserResult = localGUI.addUser(user);
- }
- // If addUserResult is false, it means that this is a new user
- // And we need to report our own existence to them
- if (addUserResult) {
- sendNotifyUserAdded();
- }
- }
- }
-
- protected void handleRegisterProxy(User sender, String proxyClass,
- String name) {
- if (sender == null || proxyClass == null || name == null)
- throw new NullPointerException("sender or proxyClass is null");
- try {
- checkRegisterProxyPolicy("register", sender, proxyClass);
- } catch (SecurityException e) {
- debugdump(e, "SecurityException with registering Eclipse proxy");
- throw e;
- }
- localRegisterProxy(sender, proxyClass, name);
- }
-
- protected void handleRequestUserUpdate(ID requestor) {
- sendUserUpdate(requestor);
- }
-
- protected void handleShowPrivateTextMsg(final User remote, final String aString) {
- // Show line on local interface
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null)
- localGUI.showPrivate(remote.getUserID(), aString);
- } catch (Exception e) {
- debugdump(e,
- "Exception in showLineOnGUI");
- }
- }
- });
- }
-
- protected void handleShowTextMsg(ID remote, String aString) {
- // Show line on local interface
- showLineOnGUI(remote, aString);
- }
-
- protected void handleUnregisterProxy(User sender, String name) {
- if (sender == null || name == null)
- throw new NullPointerException("sender or proxyClass is null");
- // loadClass and create instance if possible
- EclipseProjectComponent ec = null;
- try {
- checkRegisterProxyPolicy("deregister", sender, name);
- } catch (SecurityException e) {
- debugdump(e, "SecurityException with deregistering Eclipse proxy");
- throw e;
- }
- localUnregisterProxy(sender, name);
- }
-
- protected void handleUpdateTreeDisplay(final ID fromID, final TreeItem item) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null)
- localGUI.updateTreeDisplay(fromID, item);
- } catch (Exception e) {
- debugdump(e,
- "Exception in showLineOnGUI");
- }
- }
- });
- }
-
- protected void handleUserUpdate(final User ud) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null)
- localGUI.changeUser(ud);
- } catch (Exception e) {
- debugdump(e,
- "Exception in showLineOnGUI");
- }
- }
- });
- }
-
- protected void handleUserMessage(final User sender, String msg) {
- // Show line on local interface
- final String username = sender.getNickname();
- final String message = msg;
- if (sender == null)
- return;
- if (localGUI != null) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- Display.getDefault().beep();
- Shell[] shells = Display.getDefault().getShells();
- if (shells != null && shells.length > 0) {
- shells[0].setActive();
- }
- MessageDialog.openInformation(null,
- "Private Message from " + sender.getNickname(),
- message);
- }
- });
- }
- }
-
- protected synchronized void handleStartedTyping(User user) {
- if (localGUI != null)
- localGUI.startedTyping(user);
- }
-
- public void sendStartedTyping() {
- try {
- forwardMsgTo(null, SharedObjectMsg.makeMsg(null,
- "handleStartedTyping", localUser));
- } catch (Exception e) {
- debugdump(e, "Exception on sendStartedTyping to remote clients");
- }
- }
-
- public void inputText(String aString) {
- sendShowTextMsg(aString);
- }
-
- public boolean isHost() {
- return super.isHost();
- }
-
- public void joinGroup(ID remote, Object data)
- throws SharedObjectContainerJoinException {
- ISharedObjectContext crs = getContext();
- if (crs == null) {
- throw new SharedObjectContainerJoinException(
- "Cannot join remote space " + remote
- + ". Have no local space access capability.");
- } else {
- if (remote != null) {
- // Do it.
- if (localGUI != null) {
- String name = remote.getName();
- localGUI.showLine(getID(), "Connecting to: " + name);
- }
- crs.joinGroup(remote, data);
- if (localGUI != null) {
- localGUI.showLine(getID(), "Connected.");
- }
- // Success
- } else {
- throw new SharedObjectContainerJoinException(
- "Invalid remote space ID " + remote);
- }
- }
- }
-
- public void leaveGroup() {
- ISharedObjectContext crs = getContext();
- if (crs == null) {
- } else {
- // Do it.
- crs.leaveGroup();
- }
- }
-
- public URL[] getCodeBase() {
- return null;
- }
-
- public void localRegisterProxy(User sender, String proxyClass, String name) {
- EclipseProjectComponent ec = null;
- try {
- ClassLoader classLoader = getClass().getClassLoader();
- URL[] codeBase = getCodeBase();
- URLClassLoader ucl = new URLClassLoader(codeBase, classLoader);
- Class cl = Class.forName(proxyClass, true, ucl);
- ec = (EclipseProjectComponent) cl.newInstance();
- } catch (Exception e) {
- debugdump(e,
- "Exception loading proxy class or creating proxy instance for user "
- + sender.getNickname());
- throw new RuntimeException("Exception creating proxy instance", e);
- }
- try {
- ec.register(this, sender);
- } catch (Exception e) {
- debugdump(e, "Exception initializing EclipseProjectComponent");
- throw new RuntimeException(
- "Exception initializing EclipseProjectComponent", e);
- }
- // OK, we have new instance...now we add it to our registered proxies
- registerProxy(ec, name, EclipseProjectComponent.INVOKE_METHOD_NAME);
- }
-
- public void localUnregisterProxy(User ud, String name) {
- MsgMap m = null;
- Object removed = null;
- synchronized (msgMapLock) {
- // Get entry (if exists)
- m = (MsgMap) ((msgMap == null) ? null : (msgMap.get(name)));
- if (m == null)
- throw new RuntimeException(
- "deregisterProxy: No proxy registered for " + name);
- // Then remove
- removed = msgMap.remove(name);
- }
- if (removed != null) {
- try {
- MsgMap mm = (MsgMap) removed;
- EclipseProjectComponent ec = (EclipseProjectComponent) mm
- .getObject();
- // Call it to give it a chance to clean up
- if (ec != null)
- ec.deregister(this);
- } catch (Exception e) {
- debugdump(e, "Exception deregistering component with name "
- + name + " with User " + ud);
- }
- }
- }
-
- public Object getObject(ID obj) {
- ISharedObjectContext crs = getContext();
- if (crs == null)
- return null;
- return crs.getSharedObjectManager().getSharedObject(obj);
- }
-
- public void makeProxyObject(ID target, String proxyClass, String name) {
- ID[] targets = new ID[1];
- targets[0] = target;
- if (name == null)
- name = proxyClass;
- registerEclipseProxy((target == null), targets, proxyClass, name);
- }
-
- public void memberAdded(ID member) {
- if (sessionListener != null) {
- sessionListener.memberAdded(member);
- }
- super.memberAdded(member);
- sendNotifyUserAdded();
- }
-
- public void memberRemoved(final ID member) {
- if (sessionListener != null) {
- sessionListener.memberRemoved(member);
- }
- super.memberRemoved(member);
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null) {
- localGUI.removeUser(member);
- }
- } catch (Exception e) {
- debugdump(e,
- "Exception in showLineOnGUI");
- }
- }
- });
- }
-
- public void messageProxyObject(ID target, String classname, String meth,
- Object[] args) {
- SharedObjectMsg m = SharedObjectMsg.makeMsg(null, classname, meth,
- (Object[]) args);
- try {
- forwardMsgTo(target, m);
- if (target == null) {
- sendSelf(m);
- }
- } catch (Exception e) {
- debugdump(e, "Exception sending message to proxy object");
- }
- }
-
- public void otherActivated(ID object) {
- if (sessionListener != null) {
- sessionListener.otherActivated(object);
- }
- super.otherActivated(object);
- }
-
- public void otherDeactivated(ID object) {
- if (sessionListener != null) {
- sessionListener.otherDeactivated(object);
- }
- super.otherDeactivated(object);
- }
-
- public void refreshProject() {
- if (localProject != null) {
- try {
- localProject.refreshLocal(IResource.DEPTH_INFINITE,
- new NullProgressMonitor());
- } catch (Exception e) {
- debugdump(e, "Exception refreshing project "
- + localProject.getName());
- }
- }
- }
-
- public void registerEclipseProxy(boolean localAlso, ID[] toReceivers,
- String proxyClass, String name) {
- // first, do it locally if this is what is desired
- if (localAlso) {
- try {
- localRegisterProxy(localUser, proxyClass, name);
- } catch (Exception e) {
- debugdump(e, "Exception registering proxy class " + proxyClass
- + " locally");
- throw new RuntimeException(
- "registerEclipseProxy. Local registration failed", e);
- }
- }
- // Now send register message to appropriate receiver(s).
- if (toReceivers == null)
- sendRegisterProxy(null, proxyClass, name);
- else if (toReceivers.length == 1)
- sendRegisterProxy(toReceivers[0], proxyClass, name);
- else {
- for (int i = 0; i < toReceivers.length; i++) {
- try {
- sendRegisterProxy(toReceivers[i], proxyClass, name);
- } catch (Exception e) {
- debugdump(e, "Exception sending register proxy message to "
- + toReceivers[i]);
- }
- }
- }
- }
-
- public void removeProxyObject(ID target, String name) {
- ID[] targets = new ID[1];
- targets[0] = target;
- unregisterEclipseProxy((target == null), targets, name);
- }
-
- // SharedObjectMsg senders
- public void sendNotifyUserAdded() {
- try {
- forwardMsgTo(null, SharedObjectMsg.makeMsg(null,
- "handleNotifyUserAdded", localUser));
- } catch (Exception e) {
- debugdump(e, "Exception on sendNotifyUserAdded to remote clients");
- }
- }
-
- public void sendPrivateMessageToUser(User touser, String msg) {
- try {
- forwardMsgTo(touser.getUserID(), SharedObjectMsg.makeMsg(null,
- "handleShowPrivateTextMsg", localUser, msg));
- } catch (Exception e) {
- debugdump(e,
- "Exception on sendShowPrivateTextMsg to remote clients");
- }
- }
-
- public void sendRegisterProxy(ID toID, String proxyClass, String name) {
- try {
- forwardMsgTo(toID, SharedObjectMsg.makeMsg(null,
- "handleRegisterProxy", localUser, proxyClass, name));
- } catch (IOException e) {
- debugdump(e, "Exception sendRegisterProxy");
- }
- }
-
- public void sendRequestUserUpdate(ID requestTarget) {
- try {
- forwardMsgTo(requestTarget, SharedObjectMsg.makeMsg(null,
- "handleRequestUserUpdate", getUniqueID()));
- } catch (Exception e) {
- debugdump(e, "Exception on sendRequestUserUpdate to remote clients");
- }
- }
-
- public void sendCVSProjectUpdateRequest(User touser, String msg) {
- ID receiver = null;
- if (touser != null) {
- receiver = touser.getUserID();
- }
- try {
- SharedObjectMsg m = SharedObjectMsg.makeMsg(null,
- "handleCVSProjectUpdateRequest", getUser(), msg);
- forwardMsgTo(receiver, m);
- if (receiver == null) {
- sendSelf(m);
- }
- } catch (Exception e) {
- debugdump(e, "Exception on sendCVSProjectUpdateRequest to "
- + touser);
- }
- }
-
- public boolean isCVSShared() {
- try {
- //return CVSWorkspaceRoot.isSharedWithCVS(getProject());
- return false;
- } catch (Exception e) {
- ClientPlugin
- .log(
- "CVS Exception calling isSharedWithCVS in TeamUpdateAction",
- e);
- return false;
- }
- }
-
- protected void doCVSUpdateOperation(IProject proj, User fromUser) {
- /*
- IResource[] resources = new IResource[1];
- resources[0] = proj;
- try {
- new UpdateOperation(getViewPart(), resources,
- Command.NO_LOCAL_OPTIONS, null).run();
- } catch (InvocationTargetException e) {
- ClientPlugin.log("Exception calling update operation from user "
- + fromUser, e);
- CVSUIPlugin.openError(Display.getDefault().getActiveShell(), null,
- null, e);
- } catch (InterruptedException e) {
- }
- */
- }
-
- protected void handleCVSProjectUpdateRequest(final User fromUser,
- final String msg) {
- final IProject proj = getProject();
- // If project doesn't actually exist, just return silently
- if (!proj.exists() || !isCVSShared())
- return;
- doCVSUpdateOperation(proj, fromUser);
- }
-
- public void sendRingMessageToUser(User user, String msg) {
- ID receiver = null;
- if (user != null) {
- receiver = user.getUserID();
- }
- try {
- SharedObjectMsg m = SharedObjectMsg.makeMsg(null,
- "handleUserMessage", this.localUser, msg);
- forwardMsgTo(receiver, m);
- if (receiver == null)
- sendSelf(m);
- } catch (Exception e) {
- debugdump(e, "Exception on sendMessageToUser to " + user);
- }
- }
-
- public void sendShowTextMsg(String msg) {
- try {
- trace("sendShowTextMsg(" + msg + ")");
- forwardMsgTo(null, SharedObjectMsg.makeMsg(null,
- "handleShowTextMsg", getUniqueID(), msg));
- } catch (Exception e) {
- debugdump(e, "Exception on sendShowTextMsg to remote clients");
- }
- }
-
- public void sendUnregisterProxy(ID toID, String proxyClass) {
- try {
- forwardMsgTo(toID, SharedObjectMsg.makeMsg(null,
- "handleUnregisterProxy", localUser, proxyClass));
- } catch (IOException e) {
- debugdump(e, "Exception sendRegisterProxy");
- }
- }
-
- public void sendUpdateTreeDisplay(ID target, TreeItem item) {
- try {
- forwardMsgTo(target, SharedObjectMsg.makeMsg(null,
- "handleUpdateTreeDisplay", getUniqueID(), item));
- } catch (Exception e) {
- debugdump(e, "Exception on sendUpdateTreeDisplay to remote clients");
- }
- }
-
- public void sendUserUpdate(ID target) {
- try {
- forwardMsgTo(target, SharedObjectMsg.makeMsg(null,
- "handleUserUpdate", localUser));
- } catch (Exception e) {
- debugdump(e, "Exception on sendUserUpdate to remote clients");
- }
- }
-
- public void setListener(SharedObjectEventListener l) {
- sessionListener = l;
- }
-
- public void setServerID(ID server) {
- serverID = server;
- }
-
- public void setVersionString(String ver) {
- localVersion = ver;
- }
-
- public void setWindowTitle(String title) {
- windowtitle = title;
- synchronized (this) {
- if (localGUI != null) {
- localGUI.setTitle(title);
- }
- }
- }
-
- public void show(final boolean show) {
- if (localGUI != null) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- localGUI.setVisible(show);
- localGUI.toFront();
- }
- });
- }
- }
-
- public void showLineOnGUI(final ID remote, final String line) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null)
- localGUI.showLine(remote, line);
- } catch (Exception e) {
- debugdump(e,
- "Exception in showLineOnGUI");
- }
- }
- });
- }
-
- public void showRawLine(final ID sender, final String line) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null) {
- localGUI.showRawLine(sender, line);
- }
- } catch (Exception e) {
- debugdump(e,
- "Exception in showLineOnGUI");
- }
- }
- });
- }
-
- public void showView() {
- try {
- showView(CHAT_VIEW_ID);
- } catch (Exception e) {
- debugdump(e, "Exception showing view");
- }
- }
-
- public void sendShowViewWithID(User touser, String id, String secID,
- Integer mode) {
- ID receiver = null;
- if (touser != null) {
- receiver = touser.getUserID();
- }
- try {
- SharedObjectMsg m = SharedObjectMsg.makeMsg(null,
- "handleShowViewWithID", getUser(), id, secID, mode);
- forwardMsgTo(receiver, m);
- if (receiver == null) {
- sendSelf(m);
- }
- } catch (Exception e) {
- debugdump(e, "Exception on handleShowViewWithID to " + touser);
- }
- }
-
- public void sendShowView(User touser, String id) {
- ID receiver = null;
- if (touser != null) {
- receiver = touser.getUserID();
- }
- try {
- SharedObjectMsg m = SharedObjectMsg.makeMsg(null, "handleShowView",
- getUser(), id);
- forwardMsgTo(receiver, m);
- if (receiver == null) {
- sendSelf(m);
- }
- } catch (Exception e) {
- debugdump(e, "Exception on sendCVSProjectUpdateRequest to "
- + touser);
- }
- }
-
- protected void handleShowViewWithID(User fromUser, final String id,
- final String secID, final Integer mode) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- showViewWithID(id, secID, mode.intValue());
- } catch (Exception e) {
- debugdump(e, "Exception in showing view id=" + id
- + ";secID=" + secID + ";mode=" + mode);
- }
- }
- });
- }
-
- protected void handleShowView(User fromUser, final String id) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- showView(id);
- } catch (Exception e) {
- debugdump(e, "Exception in showing view id=" + id);
- }
- }
- });
- }
-
- protected IViewPart showViewWithID(String id, String secID, int mode)
- throws PartInitException {
- IWorkbenchWindow ww = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPage wp = ww.getActivePage();
- if (wp == null)
- throw new NullPointerException("showViewWithID(" + id + ") "
- + "workbench page is null");
- return wp.showView(id, secID, mode);
- }
-
- protected IViewPart showView(String id) throws PartInitException {
- IWorkbenchWindow ww = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPage wp = ww.getActivePage();
- if (wp == null)
- throw new NullPointerException("showView(" + id + ") "
- + "workbench page is null");
- return wp.showView(id);
- }
-
- public void unregisterEclipseProxy(boolean localAlso, ID[] toReceivers,
- String name) {
- // first, do it locally if this is what is desired
- if (localAlso) {
- try {
- localUnregisterProxy(getUser(), name);
- } catch (Exception e) {
- debugdump(e, "Exception deregistering " + name + " locally");
- throw new RuntimeException(
- "deregisterEclipseProxy. Local deregistration failed",
- e);
- }
- }
- // Now send register message to appropriate receiver(s).
- if (toReceivers == null)
- sendUnregisterProxy(null, name);
- else if (toReceivers.length == 1)
- sendUnregisterProxy(toReceivers[0], name);
- else {
- for (int i = 0; i < toReceivers.length; i++) {
- try {
- sendUnregisterProxy(toReceivers[i], name);
- } catch (Exception e) {
- debugdump(e, "Exception sending register proxy message to "
- + toReceivers[i]);
- }
- }
- }
- }
-
- public FileReceiverUI getFileReceiverUI(EclipseFileTransfer transfer,
- FileTransferParams params) {
- return new FileReceiverUI() {
- public void receiveStart(ID from, File aFile, long length,
- float rate) {
- User user = getUserForID(from);
- String nick = "<unknown>";
- if (user != null) {
- nick = user.getNickname();
- }
- showRawLine(from, "\t" + nick + " is sending you '"
- + aFile.getName() + "'");
- }
-
- public void receiveData(ID from, File aFile, int dataLength) {
- }
-
- public void receiveDone(ID from, File aFile, Exception e) {
- User user = getUserForID(from);
- String nick = "<unknown>";
- if (user != null) {
- nick = user.getNickname();
- }
- showRawLine(from, "\t'" + aFile.getName() + "' received from " + nick
- + ". Stored in: "+getLocalFullDownloadPath());
- refreshProject();
- }
- };
- }
-
- public void updateTreeDisplay(final TreeItem item) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null) {
- localGUI.updateTreeDisplay(getUniqueID(), item);
- }
- } catch (Exception e) {
- debugdump(e,
- "Exception in updateTreeDisplay");
- }
- }
- });
- // Send update message to all replicas
- sendUpdateTreeDisplay(null, item);
- }
-
- public ViewPart getViewPart() {
- if (localGUI == null)
- return null;
- return localGUI.getView();
- }
-
- public Control getTreeControl() {
- if (localGUI == null)
- return null;
- return localGUI.getTreeControl();
- }
-
- public Control getTextControl() {
- if (localGUI == null)
- return null;
- return localGUI.getTextControl();
- }
+ LineChatHandler, EclipseProject {
+ protected static final String CHAT_VIEW_ID = LineChatView.class.getName();
+
+ protected static String DEFAULTTREETOPLABEL = "Presence";
+
+ public static final String ECLIPSEOBJECTNAME = "chat";
+
+ public static final String INIT_TEXT = "Collaboration for '";
+
+ Date creationTime = new Date();
+
+ String downloaddir = "";
+
+ protected LineChatClientView localGUI;
+
+ IProject localProject;
+
+ User localUser;
+
+ String localVersion = "";
+
+ ID serverID;
+
+ SharedObjectEventListener sessionListener;
+
+ IWorkbenchWindow shellWindow;
+
+ String treeTopLabel;
+
+ String windowtitle = "Chat";
+
+ URL[] projectCodebase = null;
+
+ public EclipseCollabSharedObject() {
+ }
+
+ public EclipseCollabSharedObject(IProject proj, IWorkbenchWindow shell,
+ User user, String downloaddir) {
+ this.localProject = proj;
+ this.shellWindow = shell;
+ this.localUser = user;
+ this.downloaddir = downloaddir;
+ localGUI = getOutputWindow();
+ if (localGUI == null)
+ throw new NullPointerException(
+ "Local GUI cannot be created...exiting");
+ }
+
+ public void activated(ID[] others) {
+ super.activated(others);
+ if (localGUI == null) {
+ try {
+ if (!getContext().isGroupServer())
+ destroySelfLocal();
+ } catch (Exception e) {
+ debugdump(e, "Unable to check whether we are server instance");
+ destroySelfLocal();
+ }
+ }
+ }
+
+ public void chatException(Exception e, String text) {
+ debugdump(e, text);
+ }
+
+ public void chatGUIDestroy() {
+ debugmsg("chatGUIDestroy()");
+ if (sessionListener != null) {
+ sessionListener.windowClosing();
+ }
+ destroySelf();
+ }
+
+ protected void checkRegisterProxyPolicy(String operation, User sender,
+ String proxyClass) throws SecurityException {
+ // by default let it through;
+ }
+
+ public void deactivated() {
+ super.deactivated();
+ synchronized (this) {
+ if (localGUI != null) {
+ localGUI.disposeClient();
+ localGUI = null;
+ }
+ }
+ if (sessionListener != null) {
+ sessionListener = null;
+ }
+ if (shellWindow != null) {
+ shellWindow = null;
+ }
+ if (localProject != null) {
+ localProject = null;
+ }
+ }
+
+ public void debugdump(Exception e, String aString) {
+ }
+
+ public void debugmsg(String aString) {
+ // ClientPlugin.log(aString);
+ }
+
+ public void destroySelf() {
+ // Make sure we disconnect
+ try {
+ if (isHost()) {
+ try {
+ // try to disconnect
+ leaveGroup();
+ } catch (Exception e) {
+ debugdump(e, "Exception leaving space");
+ }
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception in destroySelf");
+ }
+ // Destroy self
+ super.destroySelfLocal();
+ }
+
+ public String getDownloaddir(String dir) {
+ return downloaddir;
+ }
+
+ public SharedObjectEventListener getListener() {
+ return sessionListener;
+ }
+
+ public String getLocalFullProjectPath() {
+ String eclipseDir = null;
+ String result = null;
+ try {
+ eclipseDir = Platform.getLocation().toOSString();
+ } catch (Exception e) {
+ debugdump(e,
+ "EclipseCollabSharedObject. Exception getting local project path");
+ }
+ if (eclipseDir == null) {
+ eclipseDir = ".";
+ }
+ String projectDir = null;
+ if (getProject() == null) {
+ projectDir = downloaddir;
+ } else {
+ projectDir = getProject().getFullPath().toOSString();
+ }
+ File fresult = new File(eclipseDir, projectDir);
+ return fresult.getAbsolutePath();
+ }
+
+ public String getLocalFullDownloadPath() {
+ String projectPath = getLocalFullProjectPath();
+ File downloadpath = new File(projectPath, downloaddir);
+ return downloadpath.getAbsolutePath();
+ }
+
+ public ID getObjectID() {
+ return getID();
+ }
+
+ protected LineChatClientView getOutputWindow() {
+ final String pn = (localProject == null) ? "<workspace>" : localProject
+ .getName();
+ final String projectName = pn;
+ final String init = INIT_TEXT + pn + "' project\n\n";
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (LineChatView.isDisposed())
+ showView();
+ localGUI = LineChatView.makeClientView(
+ EclipseCollabSharedObject.this, projectName, init,
+ getLocalFullDownloadPath());
+ } catch (Exception e) {
+ debugdump(e,
+ "Exception creating output window in getOutputWindow");
+ }
+ }
+ });
+ return localGUI;
+ }
+
+ public IProject getProject() {
+ return localProject;
+ }
+
+ protected SharedObjectDescription getReplicaDescription(ID remoteID) {
+ // no replication...depend upon clients to create
+ // local instance of their own copy of this object...with local
+ // data.
+ return null;
+ }
+
+ public ID getServerID() {
+ return serverID;
+ }
+
+ public String getTreeTopLabel() {
+ return DEFAULTTREETOPLABEL;
+ }
+
+ public ID getUniqueID() {
+ try {
+ return getLocalContainerID();
+ } catch (Exception e) {
+ debugdump(e, "Exception getting unique id");
+ return null;
+ }
+ }
+
+ public User getUser() {
+ return localUser;
+ }
+
+ public User getUserForID(final ID user) {
+ if (localGUI != null) {
+ return localGUI.getUser(user);
+ }
+ return null;
+ }
+
+ public String getUserName() {
+ return localUser.getNickname();
+ }
+
+ public String getVersionString() {
+ return localVersion;
+ }
+
+ public String getWindowTitle() {
+ return windowtitle;
+ }
+
+ public IWorkbenchWindow getWorkbenchWindow() {
+ return shellWindow;
+ }
+
+ // SharedObjectMsg handlers
+ protected void handleCreateObject(SharedObjectDescription cons) {
+ try {
+ makeObject(cons.getID(), cons.getClassname(), cons.getProperties());
+ } catch (Exception e) {
+ debugdump(e, "Exception creating local object " + cons);
+ }
+ }
+
+ public void handleNotifyUserAdded(User user) {
+ boolean add = false;
+ try {
+ ID[] members = getContext().getGroupMemberIDs();
+ for (int i = 0; i < members.length; i++) {
+ if (members[i].equals(user.getUserID())) {
+ add = true;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception checking for membership");
+ }
+ if (add) {
+ boolean addUserResult = false;
+ if (localGUI != null) {
+ addUserResult = localGUI.addUser(user);
+ }
+ // If addUserResult is false, it means that this is a new user
+ // And we need to report our own existence to them
+ if (addUserResult) {
+ sendNotifyUserAdded();
+ }
+ }
+ }
+
+ protected void handleRegisterProxy(User sender, String proxyClass,
+ String name) {
+ if (sender == null || proxyClass == null || name == null)
+ throw new NullPointerException("sender or proxyClass is null");
+ try {
+ checkRegisterProxyPolicy("register", sender, proxyClass);
+ } catch (SecurityException e) {
+ debugdump(e, "SecurityException with registering Eclipse proxy");
+ throw e;
+ }
+ localRegisterProxy(sender, proxyClass, name);
+ }
+
+ protected void handleRequestUserUpdate(ID requestor) {
+ sendUserUpdate(requestor);
+ }
+
+ protected void handleShowPrivateTextMsg(final User remote,
+ final String aString) {
+ // Show line on local interface
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null) {
+ ChatLine line = new ChatLine(aString);
+ line.setOriginator(remote);
+ line.setPrivate(true);
+ localGUI.showLine(line);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception in showLineOnGUI");
+ }
+ }
+ });
+ }
+
+ protected void handleShowTextMsg(ID remote, String aString) {
+ // Show line on local interface
+ showLineOnGUI(remote, aString);
+ }
+
+ protected void handleUnregisterProxy(User sender, String name) {
+ if (sender == null || name == null)
+ throw new NullPointerException("sender or proxyClass is null");
+ // loadClass and create instance if possible
+ EclipseProjectComponent ec = null;
+ try {
+ checkRegisterProxyPolicy("deregister", sender, name);
+ } catch (SecurityException e) {
+ debugdump(e, "SecurityException with deregistering Eclipse proxy");
+ throw e;
+ }
+ localUnregisterProxy(sender, name);
+ }
+
+ protected void handleUpdateTreeDisplay(final ID fromID, final TreeItem item) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null)
+ localGUI.updateTreeDisplay(fromID, item);
+ } catch (Exception e) {
+ debugdump(e, "Exception in showLineOnGUI");
+ }
+ }
+ });
+ }
+
+ protected void handleUserUpdate(final User ud) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null)
+ localGUI.changeUser(ud);
+ } catch (Exception e) {
+ debugdump(e, "Exception in showLineOnGUI");
+ }
+ }
+ });
+ }
+
+ protected void handleUserMessage(final User sender, String msg) {
+ // Show line on local interface
+ final String username = sender.getNickname();
+ final String message = msg;
+ if (sender == null)
+ return;
+ if (localGUI != null) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ Display.getDefault().beep();
+ Shell[] shells = Display.getDefault().getShells();
+ if (shells != null && shells.length > 0) {
+ shells[0].setActive();
+ }
+ MessageDialog.openInformation(null, "Private Message from "
+ + sender.getNickname(), message);
+ }
+ });
+ }
+ }
+
+ protected synchronized void handleStartedTyping(User user) {
+ if (localGUI != null)
+ localGUI.startedTyping(user);
+ }
+
+ public void sendStartedTyping() {
+ try {
+ forwardMsgTo(null, SharedObjectMsg.makeMsg(null,
+ "handleStartedTyping", localUser));
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendStartedTyping to remote clients");
+ }
+ }
+
+ public void inputText(String aString) {
+ sendShowTextMsg(aString);
+ }
+
+ public boolean isHost() {
+ return super.isHost();
+ }
+
+ public void joinGroup(ID remote, Object data)
+ throws SharedObjectContainerJoinException {
+ ISharedObjectContext crs = getContext();
+ if (crs == null) {
+ throw new SharedObjectContainerJoinException(
+ "Cannot join remote space " + remote
+ + ". Have no local space access capability.");
+ } else {
+ if (remote != null) {
+ // Do it.
+ ChatLine line = new ChatLine();
+
+ if (localGUI != null) {
+ line.setText("Connecting to " + remote.getName());
+ String name = remote.getName();
+
+ localGUI.showLine(line);
+ }
+ crs.joinGroup(remote, data);
+ if (localGUI != null) {
+ line.setText("Connected to " + remote.getName());
+ localGUI.showLine(line);
+ }
+ // Success
+ } else {
+ throw new SharedObjectContainerJoinException(
+ "Invalid remote space ID " + remote);
+ }
+ }
+ }
+
+ public void leaveGroup() {
+ ISharedObjectContext crs = getContext();
+ if (crs == null) {
+ } else {
+ // Do it.
+ crs.leaveGroup();
+ }
+ }
+
+ public URL[] getCodeBase() {
+ return null;
+ }
+
+ public void localRegisterProxy(User sender, String proxyClass, String name) {
+ EclipseProjectComponent ec = null;
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL[] codeBase = getCodeBase();
+ URLClassLoader ucl = new URLClassLoader(codeBase, classLoader);
+ Class cl = Class.forName(proxyClass, true, ucl);
+ ec = (EclipseProjectComponent) cl.newInstance();
+ } catch (Exception e) {
+ debugdump(e,
+ "Exception loading proxy class or creating proxy instance for user "
+ + sender.getNickname());
+ throw new RuntimeException("Exception creating proxy instance", e);
+ }
+ try {
+ ec.register(this, sender);
+ } catch (Exception e) {
+ debugdump(e, "Exception initializing EclipseProjectComponent");
+ throw new RuntimeException(
+ "Exception initializing EclipseProjectComponent", e);
+ }
+ // OK, we have new instance...now we add it to our registered proxies
+ registerProxy(ec, name, EclipseProjectComponent.INVOKE_METHOD_NAME);
+ }
+
+ public void localUnregisterProxy(User ud, String name) {
+ MsgMap m = null;
+ Object removed = null;
+ synchronized (msgMapLock) {
+ // Get entry (if exists)
+ m = (MsgMap) ((msgMap == null) ? null : (msgMap.get(name)));
+ if (m == null)
+ throw new RuntimeException(
+ "deregisterProxy: No proxy registered for " + name);
+ // Then remove
+ removed = msgMap.remove(name);
+ }
+ if (removed != null) {
+ try {
+ MsgMap mm = (MsgMap) removed;
+ EclipseProjectComponent ec = (EclipseProjectComponent) mm
+ .getObject();
+ // Call it to give it a chance to clean up
+ if (ec != null)
+ ec.deregister(this);
+ } catch (Exception e) {
+ debugdump(e, "Exception deregistering component with name "
+ + name + " with User " + ud);
+ }
+ }
+ }
+
+ public Object getObject(ID obj) {
+ ISharedObjectContext crs = getContext();
+ if (crs == null)
+ return null;
+ return crs.getSharedObjectManager().getSharedObject(obj);
+ }
+
+ public void makeProxyObject(ID target, String proxyClass, String name) {
+ ID[] targets = new ID[1];
+ targets[0] = target;
+ if (name == null)
+ name = proxyClass;
+ registerEclipseProxy((target == null), targets, proxyClass, name);
+ }
+
+ public void memberAdded(ID member) {
+ if (sessionListener != null) {
+ sessionListener.memberAdded(member);
+ }
+ super.memberAdded(member);
+ sendNotifyUserAdded();
+ }
+
+ public void memberRemoved(final ID member) {
+ if (sessionListener != null) {
+ sessionListener.memberRemoved(member);
+ }
+ super.memberRemoved(member);
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null) {
+ localGUI.removeUser(member);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception in showLineOnGUI");
+ }
+ }
+ });
+ }
+
+ public void messageProxyObject(ID target, String classname, String meth,
+ Object[] args) {
+ SharedObjectMsg m = SharedObjectMsg.makeMsg(null, classname, meth,
+ (Object[]) args);
+ try {
+ forwardMsgTo(target, m);
+ if (target == null) {
+ sendSelf(m);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception sending message to proxy object");
+ }
+ }
+
+ public void otherActivated(ID object) {
+ if (sessionListener != null) {
+ sessionListener.otherActivated(object);
+ }
+ super.otherActivated(object);
+ }
+
+ public void otherDeactivated(ID object) {
+ if (sessionListener != null) {
+ sessionListener.otherDeactivated(object);
+ }
+ super.otherDeactivated(object);
+ }
+
+ public void refreshProject() {
+ if (localProject != null) {
+ try {
+ localProject.refreshLocal(IResource.DEPTH_INFINITE,
+ new NullProgressMonitor());
+ } catch (Exception e) {
+ debugdump(e, "Exception refreshing project "
+ + localProject.getName());
+ }
+ }
+ }
+
+ public void registerEclipseProxy(boolean localAlso, ID[] toReceivers,
+ String proxyClass, String name) {
+ // first, do it locally if this is what is desired
+ if (localAlso) {
+ try {
+ localRegisterProxy(localUser, proxyClass, name);
+ } catch (Exception e) {
+ debugdump(e, "Exception registering proxy class " + proxyClass
+ + " locally");
+ throw new RuntimeException(
+ "registerEclipseProxy. Local registration failed", e);
+ }
+ }
+ // Now send register message to appropriate receiver(s).
+ if (toReceivers == null)
+ sendRegisterProxy(null, proxyClass, name);
+ else if (toReceivers.length == 1)
+ sendRegisterProxy(toReceivers[0], proxyClass, name);
+ else {
+ for (int i = 0; i < toReceivers.length; i++) {
+ try {
+ sendRegisterProxy(toReceivers[i], proxyClass, name);
+ } catch (Exception e) {
+ debugdump(e, "Exception sending register proxy message to "
+ + toReceivers[i]);
+ }
+ }
+ }
+ }
+
+ public void removeProxyObject(ID target, String name) {
+ ID[] targets = new ID[1];
+ targets[0] = target;
+ unregisterEclipseProxy((target == null), targets, name);
+ }
+
+ // SharedObjectMsg senders
+ public void sendNotifyUserAdded() {
+ try {
+ forwardMsgTo(null, SharedObjectMsg.makeMsg(null,
+ "handleNotifyUserAdded", localUser));
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendNotifyUserAdded to remote clients");
+ }
+ }
+
+ public void sendPrivateMessageToUser(User touser, String msg) {
+ try {
+ forwardMsgTo(touser.getUserID(), SharedObjectMsg.makeMsg(null,
+ "handleShowPrivateTextMsg", localUser, msg));
+ } catch (Exception e) {
+ debugdump(e,
+ "Exception on sendShowPrivateTextMsg to remote clients");
+ }
+ }
+
+ public void sendRegisterProxy(ID toID, String proxyClass, String name) {
+ try {
+ forwardMsgTo(toID, SharedObjectMsg.makeMsg(null,
+ "handleRegisterProxy", localUser, proxyClass, name));
+ } catch (IOException e) {
+ debugdump(e, "Exception sendRegisterProxy");
+ }
+ }
+
+ public void sendRequestUserUpdate(ID requestTarget) {
+ try {
+ forwardMsgTo(requestTarget, SharedObjectMsg.makeMsg(null,
+ "handleRequestUserUpdate", getUniqueID()));
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendRequestUserUpdate to remote clients");
+ }
+ }
+
+ public void sendCVSProjectUpdateRequest(User touser, String msg) {
+ ID receiver = null;
+ if (touser != null) {
+ receiver = touser.getUserID();
+ }
+ try {
+ SharedObjectMsg m = SharedObjectMsg.makeMsg(null,
+ "handleCVSProjectUpdateRequest", getUser(), msg);
+ forwardMsgTo(receiver, m);
+ if (receiver == null) {
+ sendSelf(m);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendCVSProjectUpdateRequest to "
+ + touser);
+ }
+ }
+
+ public boolean isCVSShared() {
+ try {
+ // return CVSWorkspaceRoot.isSharedWithCVS(getProject());
+ return false;
+ } catch (Exception e) {
+ ClientPlugin
+ .log(
+ "CVS Exception calling isSharedWithCVS in TeamUpdateAction",
+ e);
+ return false;
+ }
+ }
+
+ protected void doCVSUpdateOperation(IProject proj, User fromUser) {
+ /*
+ * IResource[] resources = new IResource[1]; resources[0] = proj; try {
+ * new UpdateOperation(getViewPart(), resources,
+ * Command.NO_LOCAL_OPTIONS, null).run(); } catch
+ * (InvocationTargetException e) { ClientPlugin.log("Exception calling
+ * update operation from user " + fromUser, e);
+ * CVSUIPlugin.openError(Display.getDefault().getActiveShell(), null,
+ * null, e); } catch (InterruptedException e) { }
+ */
+ }
+
+ protected void handleCVSProjectUpdateRequest(final User fromUser,
+ final String msg) {
+ final IProject proj = getProject();
+ // If project doesn't actually exist, just return silently
+ if (!proj.exists() || !isCVSShared())
+ return;
+ doCVSUpdateOperation(proj, fromUser);
+ }
+
+ public void sendRingMessageToUser(User user, String msg) {
+ ID receiver = null;
+ if (user != null) {
+ receiver = user.getUserID();
+ }
+ try {
+ SharedObjectMsg m = SharedObjectMsg.makeMsg(null,
+ "handleUserMessage", this.localUser, msg);
+ forwardMsgTo(receiver, m);
+ if (receiver == null)
+ sendSelf(m);
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendMessageToUser to " + user);
+ }
+ }
+
+ public void sendShowTextMsg(String msg) {
+ try {
+ trace("sendShowTextMsg(" + msg + ")");
+ forwardMsgTo(null, SharedObjectMsg.makeMsg(null,
+ "handleShowTextMsg", getUniqueID(), msg));
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendShowTextMsg to remote clients");
+ }
+ }
+
+ public void sendUnregisterProxy(ID toID, String proxyClass) {
+ try {
+ forwardMsgTo(toID, SharedObjectMsg.makeMsg(null,
+ "handleUnregisterProxy", localUser, proxyClass));
+ } catch (IOException e) {
+ debugdump(e, "Exception sendRegisterProxy");
+ }
+ }
+
+ public void sendUpdateTreeDisplay(ID target, TreeItem item) {
+ try {
+ forwardMsgTo(target, SharedObjectMsg.makeMsg(null,
+ "handleUpdateTreeDisplay", getUniqueID(), item));
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendUpdateTreeDisplay to remote clients");
+ }
+ }
+
+ public void sendUserUpdate(ID target) {
+ try {
+ forwardMsgTo(target, SharedObjectMsg.makeMsg(null,
+ "handleUserUpdate", localUser));
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendUserUpdate to remote clients");
+ }
+ }
+
+ public void setListener(SharedObjectEventListener l) {
+ sessionListener = l;
+ }
+
+ public void setServerID(ID server) {
+ serverID = server;
+ }
+
+ public void setVersionString(String ver) {
+ localVersion = ver;
+ }
+
+ public void setWindowTitle(String title) {
+ windowtitle = title;
+ synchronized (this) {
+ if (localGUI != null) {
+ localGUI.setTitle(title);
+ }
+ }
+ }
+
+ public void show(final boolean show) {
+ if (localGUI != null) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ localGUI.setVisible(show);
+ localGUI.toFront();
+ }
+ });
+ }
+ }
+
+ public void showLineOnGUI(final ID remote, final String line) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null)
+
+ localGUI.showLine(new ChatLine(line, getUserForID(remote)));
+ } catch (Exception e) {
+ debugdump(e, "Exception in showLineOnGUI");
+ }
+ }
+ });
+ }
+
+ public void showRawLine(final ID sender, final String line) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null) {
+ ChatLine rawLine = new ChatLine(line, getUserForID(sender));
+ rawLine.setRaw(true);
+ localGUI.showLine(rawLine);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception in showLineOnGUI");
+ }
+ }
+ });
+ }
+
+ public void showView() {
+ try {
+ showView(CHAT_VIEW_ID);
+ } catch (Exception e) {
+ debugdump(e, "Exception showing view");
+ }
+ }
+
+ public void sendShowViewWithID(User touser, String id, String secID,
+ Integer mode) {
+ ID receiver = null;
+ if (touser != null) {
+ receiver = touser.getUserID();
+ }
+ try {
+ SharedObjectMsg m = SharedObjectMsg.makeMsg(null,
+ "handleShowViewWithID", getUser(), id, secID, mode);
+ forwardMsgTo(receiver, m);
+ if (receiver == null) {
+ sendSelf(m);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception on handleShowViewWithID to " + touser);
+ }
+ }
+
+ public void sendShowView(User touser, String id) {
+ ID receiver = null;
+ if (touser != null) {
+ receiver = touser.getUserID();
+ }
+ try {
+ SharedObjectMsg m = SharedObjectMsg.makeMsg(null, "handleShowView",
+ getUser(), id);
+ forwardMsgTo(receiver, m);
+ if (receiver == null) {
+ sendSelf(m);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception on sendCVSProjectUpdateRequest to "
+ + touser);
+ }
+ }
+
+ protected void handleShowViewWithID(User fromUser, final String id,
+ final String secID, final Integer mode) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ showViewWithID(id, secID, mode.intValue());
+ } catch (Exception e) {
+ debugdump(e, "Exception in showing view id=" + id
+ + ";secID=" + secID + ";mode=" + mode);
+ }
+ }
+ });
+ }
+
+ protected void handleShowView(User fromUser, final String id) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ showView(id);
+ } catch (Exception e) {
+ debugdump(e, "Exception in showing view id=" + id);
+ }
+ }
+ });
+ }
+
+ protected IViewPart showViewWithID(String id, String secID, int mode)
+ throws PartInitException {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage wp = ww.getActivePage();
+ if (wp == null)
+ throw new NullPointerException("showViewWithID(" + id + ") "
+ + "workbench page is null");
+ return wp.showView(id, secID, mode);
+ }
+
+ protected IViewPart showView(String id) throws PartInitException {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage wp = ww.getActivePage();
+ if (wp == null)
+ throw new NullPointerException("showView(" + id + ") "
+ + "workbench page is null");
+ return wp.showView(id);
+ }
+
+ public void unregisterEclipseProxy(boolean localAlso, ID[] toReceivers,
+ String name) {
+ // first, do it locally if this is what is desired
+ if (localAlso) {
+ try {
+ localUnregisterProxy(getUser(), name);
+ } catch (Exception e) {
+ debugdump(e, "Exception deregistering " + name + " locally");
+ throw new RuntimeException(
+ "deregisterEclipseProxy. Local deregistration failed",
+ e);
+ }
+ }
+ // Now send register message to appropriate receiver(s).
+ if (toReceivers == null)
+ sendUnregisterProxy(null, name);
+ else if (toReceivers.length == 1)
+ sendUnregisterProxy(toReceivers[0], name);
+ else {
+ for (int i = 0; i < toReceivers.length; i++) {
+ try {
+ sendUnregisterProxy(toReceivers[i], name);
+ } catch (Exception e) {
+ debugdump(e, "Exception sending register proxy message to "
+ + toReceivers[i]);
+ }
+ }
+ }
+ }
+
+ public FileReceiverUI getFileReceiverUI(EclipseFileTransfer transfer,
+ FileTransferParams params) {
+ return new FileReceiverUI() {
+ public void receiveStart(ID from, File aFile, long length,
+ float rate) {
+ User user = getUserForID(from);
+ String nick = "<unknown>";
+ if (user != null) {
+ nick = user.getNickname();
+ }
+ showRawLine(from, "\t" + nick + " is sending you '"
+ + aFile.getName() + "'");
+ }
+
+ public void receiveData(ID from, File aFile, int dataLength) {
+ }
+
+ public void receiveDone(ID from, File aFile, Exception e) {
+ User user = getUserForID(from);
+ String nick = "<unknown>";
+ if (user != null) {
+ nick = user.getNickname();
+ }
+ showRawLine(from, "\t'" + aFile.getName() + "' received from "
+ + nick + ". Stored in: " + getLocalFullDownloadPath());
+ refreshProject();
+ }
+ };
+ }
+
+ public void updateTreeDisplay(final TreeItem item) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ if (localGUI != null) {
+ localGUI.updateTreeDisplay(getUniqueID(), item);
+ }
+ } catch (Exception e) {
+ debugdump(e, "Exception in updateTreeDisplay");
+ }
+ }
+ });
+ // Send update message to all replicas
+ sendUpdateTreeDisplay(null, item);
+ }
+
+ public ViewPart getViewPart() {
+ if (localGUI == null)
+ return null;
+ return localGUI.getView();
+ }
+
+ public Control getTreeControl() {
+ if (localGUI == null)
+ return null;
+ return localGUI.getTreeControl();
+ }
+
+ public Control getTextControl() {
+ if (localGUI == null)
+ return null;
+ return localGUI.getTextControl();
+ }
} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/io/EclipseFileTransfer.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/io/EclipseFileTransfer.java
index 5d15607d4..fb48e89ee 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/io/EclipseFileTransfer.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/io/EclipseFileTransfer.java
@@ -1,13 +1,13 @@
/****************************************************************************
-* Copyright (c) 2004 Composent, Inc. and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Eclipse Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/epl-v10.html
-*
-* Contributors:
-* Composent, Inc. - initial API and implementation
-*****************************************************************************/
+ * Copyright (c) 2004 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
package org.eclipse.ecf.example.collab.share.io;
@@ -22,101 +22,104 @@ import org.eclipse.ecf.core.SharedObjectAddAbortException;
import org.eclipse.ecf.core.SharedObjectDescription;
import org.eclipse.ecf.core.SharedObjectInitException;
import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.example.collab.ClientPlugin;
import org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject;
import org.eclipse.ecf.example.collab.ui.FileReceiverUI;
import org.eclipse.ecf.example.collab.ui.FileSenderUI;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+public class EclipseFileTransfer extends FileTransferSharedObject implements
+ FileTransferListener {
-public class EclipseFileTransfer
- extends FileTransferSharedObject
- implements FileTransferListener {
-
FileSenderUI senderUI;
+
ID eclipseStageID;
-
- public EclipseFileTransfer(
- FileSenderUI view,
- ID target,
- InputStream ins,
- FileTransferParams params,
- ID receiverID) {
+
+ public EclipseFileTransfer(FileSenderUI view, ID target, InputStream ins,
+ FileTransferParams params, ID receiverID) {
super(target, ins, params);
senderUI = view;
progressListener = this;
this.eclipseStageID = receiverID;
}
- protected SharedObjectDescription getReplicaDescription(ID remoteMember)
- {
+
+ protected SharedObjectDescription getReplicaDescription(ID remoteMember) {
HashMap map = new HashMap();
- map.put("args",new Object [] { transferParams, eclipseStageID });
- map.put("types",new String [] { FileTransferParams.class.getName(), ID.class.getName() });
- return new SharedObjectDescription(getID(),
- getClass().getName(),map,
- replicateID++);
+ map.put("args", new Object[] { transferParams, eclipseStageID });
+ map.put("types", new String[] { FileTransferParams.class.getName(),
+ ID.class.getName() });
+ return new SharedObjectDescription(getID(), getClass().getName(), map,
+ replicateID++);
+ }
+
+ public void init(ISharedObjectConfig config)
+ throws SharedObjectInitException {
+ super.init(config);
+ Map props = config.getProperties();
+ trace("args is " + props);
+ Object[] args = (Object[]) props.get("args");
+ if (args != null && args.length == 2) {
+ transferParams = (FileTransferParams) args[0];
+ eclipseStageID = (ID) args[1];
+ progressListener = this;
+ }
+ if (args != null && args.length == 5) {
+ senderUI = (FileSenderUI) args[0];
+ targetReceiver = (ID) args[1];
+ setInputStream((InputStream) args[2]);
+ transferParams = (FileTransferParams) args[3];
+ eclipseStageID = (ID) args[4];
+ progressListener = this;
+ }
}
- public void init(ISharedObjectConfig config) throws SharedObjectInitException {
- super.init(config);
- Map props = config.getProperties();
- trace("args is "+props);
- Object [] args = (Object []) props.get("args");
- if (args != null && args.length == 2) {
- transferParams = (FileTransferParams) args[0];
- eclipseStageID = (ID) args[1];
- progressListener = this;
- }
- if (args != null && args.length == 5) {
- senderUI = (FileSenderUI) args[0];
- targetReceiver = (ID) args[1];
- setInputStream((InputStream) args[2]);
- transferParams = (FileTransferParams) args[3];
- eclipseStageID = (ID) args[4];
- progressListener = this;
- }
- }
/**
* Client constructor
- *
- * @param params the file send parameters associated with this file delivery
+ *
+ * @param params
+ * the file send parameters associated with this file delivery
*/
public EclipseFileTransfer(FileTransferParams params, ID receiverID) {
super(params);
this.progressListener = this;
this.eclipseStageID = receiverID;
}
+
public EclipseFileTransfer() {
- super();
- }
+ super();
+ }
+
public void sendStart(FileTransferSharedObject obj, long length, float rate) {
if (senderUI != null) {
senderUI.sendStart(transferParams.getRemoteFile(), length, rate);
} else {
- System.out.println("Sending file: "+transferParams.getRemoteFile()+", length: "+length);
+ System.out.println("Sending file: "
+ + transferParams.getRemoteFile() + ", length: " + length);
}
}
+
public void sendData(FileTransferSharedObject obj, int dataLength) {
if (senderUI != null) {
senderUI.sendData(transferParams.getRemoteFile(), dataLength);
} else {
- System.out.println("Sending data: "+dataLength+" bytes");
+ System.out.println("Sending data: " + dataLength + " bytes");
}
}
+
public void sendDone(FileTransferSharedObject obj, Exception e) {
if (senderUI != null) {
senderUI.sendDone(transferParams.getRemoteFile(), e);
} else {
- System.out.println("Sending done for: "+transferParams.getRemoteFile());
+ System.out.println("Sending done for: "
+ + transferParams.getRemoteFile());
}
}
- protected File makePath(
- EclipseCollabSharedObject stage,
- boolean server,
- File file,
- long length,
- float rate) {
-
- String downloadpath = null;
+ protected File makePath(EclipseCollabSharedObject stage, boolean server,
+ File file, long length, float rate) {
+
+ String downloadpath = null;
// First, find EclipseCollabSharedObject if available
try {
if (stage != null) {
@@ -124,82 +127,61 @@ public class EclipseFileTransfer
}
} catch (Exception e) {
}
- File downloadDir = new File(downloadpath);
- // create directories if we need them
- downloadDir.mkdirs();
- // Then create new file
- File retFile = new File(downloadDir,file.getName());
- return retFile;
+ File downloadDir = new File(downloadpath);
+ // create directories if we need them
+ downloadDir.mkdirs();
+ // Then create new file
+ File retFile = new File(downloadDir, file.getName());
+ return retFile;
}
protected File localFile = null;
+
protected FileReceiverUI receiverUI = null;
- protected EclipseCollabSharedObject receiverStage = null;
-
- public void receiveStart(
- FileTransferSharedObject obj,
- File aFile,
- long length,
- float rate) {
- boolean isServer = false;
-
- // First, find out if our local environment has access to an EclipseCollabSharedObject instance
- try {
- receiverStage = (EclipseCollabSharedObject) getContext().getSharedObjectManager().getSharedObject(eclipseStageID);
- } catch (Exception e) {
- // Should never happen
- e.printStackTrace(System.err);
- }
- try {
- isServer = getContext().isGroupServer();
- } catch (Exception e) {
- e.printStackTrace(System.err);
- }
+ protected EclipseCollabSharedObject receiverStage = null;
- if (receiverStage != null) {
- receiverUI = receiverStage.getFileReceiverUI(this,transferParams);
- }
- localFile = makePath(receiverStage,isServer, aFile, length, rate);
- // Our superclass depends upon the transferParams.getRemoteFile() call to give a valid file.
- // We modify this to the new local file we've decided upon
- transferParams.setRemoteFile(localFile);
+ public void receiveStart(FileTransferSharedObject obj, File aFile,
+ long length, float rate) {
- if (receiverUI != null) {
- receiverUI.receiveStart(getHomeContainerID(),localFile,length,rate);
- } else {
- System.out.println("Receiving to local file: "+localFile);
- }
+ FileReceiver r = new FileReceiver(obj, aFile, length, rate);
+ Display d = ClientPlugin.getDefault().getActiveShell().getDisplay();
+ d.asyncExec(r);
}
+
public void receiveData(FileTransferSharedObject obj, int dataLength) {
if (receiverUI != null) {
- receiverUI.receiveData(getHomeContainerID(),localFile,dataLength);
+ receiverUI.receiveData(getHomeContainerID(), localFile, dataLength);
} else {
- System.out.println("Receiving data: "+dataLength+" bytes");
+ System.out.println("Receiving data: " + dataLength + " bytes");
}
}
+
public void receiveDone(FileTransferSharedObject obj, Exception e) {
// Need GUI progress indicator here
if (receiverUI != null) {
- receiverUI.receiveDone(getHomeContainerID(),localFile,e);
+ receiverUI.receiveDone(getHomeContainerID(), localFile, e);
} else {
- System.out.println("Receiving done for: "+localFile);
+ System.out.println("Receiving done for: " + localFile);
}
}
- protected boolean votingCompleted() throws SharedObjectAddAbortException
- {
- // The test here is is we've received any indication of failed participants in
- // the transaction. If so, we throw.
+ protected boolean votingCompleted() throws SharedObjectAddAbortException {
+ // The test here is is we've received any indication of failed
+ // participants in
+ // the transaction. If so, we throw.
if (failedParticipants != null && failedParticipants.size() > 0) {
ID remoteID = (ID) failedParticipants.keys().nextElement();
Exception e = (Exception) failedParticipants.get(remoteID);
// In this case, we're going to go ahead and continue anyway
return true;
// Abort!
- //throw new AbortException("Abort received from RepSpace "+remoteID, e);
- // If no problems, and the number of participants to here from is 0, then we're done
- } else if (state == ISharedObjectContainerTransaction.VOTING && participantIDs.size() == 0) {
+ // throw new AbortException("Abort received from RepSpace
+ // "+remoteID, e);
+ // If no problems, and the number of participants to here from is 0,
+ // then we're done
+ } else if (state == ISharedObjectContainerTransaction.VOTING
+ && participantIDs.size() == 0) {
// Success!
return true;
}
@@ -207,4 +189,67 @@ public class EclipseFileTransfer
return false;
}
+ private class FileReceiver implements Runnable {
+ private FileTransferSharedObject obj = null;
+ private File aFile = null;
+ private long length;
+ private float rate;
+
+ public FileReceiver(FileTransferSharedObject obj, File aFile, long length, float rate) {
+ this.obj = obj;
+ this.aFile = aFile;
+ this.length = length;
+ this.rate = rate;
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ boolean isServer = false;
+
+ if (ClientPlugin.getDefault().getPluginPreferences().getBoolean(ClientPlugin.PREF_CONFIRM_FILE_RECEIVE)) {
+ Display d = ClientPlugin.getDefault().getActiveShell().getDisplay();
+ MessageDialog dialog = new MessageDialog(ClientPlugin.getDefault().getActiveShell(), "File Receive Confirmation", null, "Accept file?", MessageDialog.QUESTION, null , 0);
+ dialog.setBlockOnOpen(true);
+ int response = dialog.open();
+
+ if (response == MessageDialog.CANCEL) {
+ return;
+ }
+ }
+ // First, find out if our local environment has access to an
+ // EclipseCollabSharedObject instance
+ try {
+ receiverStage = (EclipseCollabSharedObject) getContext()
+ .getSharedObjectManager().getSharedObject(eclipseStageID);
+ } catch (Exception e) {
+ // Should never happen
+ e.printStackTrace(System.err);
+ }
+
+ try {
+ isServer = getContext().isGroupServer();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ if (receiverStage != null) {
+ receiverUI = receiverStage.getFileReceiverUI(EclipseFileTransfer.this, transferParams);
+ }
+ localFile = makePath(receiverStage, isServer, aFile, length, rate);
+ // Our superclass depends upon the transferParams.getRemoteFile() call
+ // to give a valid file.
+ // We modify this to the new local file we've decided upon
+ transferParams.setRemoteFile(localFile);
+
+ if (receiverUI != null) {
+ receiverUI.receiveStart(getHomeContainerID(), localFile, length,
+ rate);
+ } else {
+ System.out.println("Receiving to local file: " + localFile);
+ }
+ }
+
+ }
+
} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatComposite.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatComposite.java
index aa2239d45..0be26a427 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatComposite.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatComposite.java
@@ -36,7 +36,10 @@ import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
@@ -45,6 +48,7 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -63,6 +67,9 @@ import org.eclipse.ui.PlatformUI;
public class ChatComposite extends Composite {
private static final String CHAT_OUTPUT_FONT = "ChatFont";
private final LineChatClientView view;
+ private Color meColor = null;
+ private Color otherColor = null;
+ private Color systemColor = null;
Action appShare = null;
@@ -112,6 +119,21 @@ public class ChatComposite extends Composite {
super(parent, options);
this.view = view;
this.chatWindow = chatWindow;
+
+ this.meColor = new Color(getShell().getDisplay(), 23, 135, 65);
+ this.otherColor = new Color(getShell().getDisplay(), 65, 13, 165);
+ this.systemColor = new Color(getShell().getDisplay(), 123, 135, 165);
+
+ this.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ meColor.dispose();
+ otherColor.dispose();
+ systemColor.dispose();
+ }
+
+ });
+
cl = new ChatLayout(DEFAULT_INPUT_HEIGHT, DEFAULT_INPUT_SEPARATOR);
setLayout(cl);
treeView = tree;
@@ -193,13 +215,46 @@ public class ChatComposite extends Composite {
this(view, parent, tree, SWT.NULL, initText);
}
- public void appendText(String text) {
- if (text == null || textoutput == null)
- return;
+ public void appendText(ChatLine text) {
StyledText st = textoutput.getTextWidget();
- if (st == null)
+
+
+ if (text == null || textoutput == null || st == null)
return;
- st.append(text);
+
+ int startRange = st.getText().length();
+ StringBuffer sb = new StringBuffer();
+
+ if (text.getOriginator() != null) {
+ sb.append(text.getOriginator().getNickname() + ": ");
+ StyleRange sr = new StyleRange();
+ sr.start = startRange;
+ sr.length = sb.length();
+ if (view.userdata.getUserID().equals(text.getOriginator().getUserID())) { //we rote this
+ sr.foreground = meColor;
+ } else {
+ sr.foreground = otherColor;
+ }
+ st.append(sb.toString());
+ st.setStyleRange(sr);
+ }
+
+ int beforeMessageIndex = st.getText().length();
+
+ st.append(text.getText());
+
+ if (text.getOriginator() == null) {
+ StyleRange sr = new StyleRange();
+ sr.start = beforeMessageIndex;
+ sr.length = text.getText().length();
+ sr.foreground = systemColor;
+ st.setStyleRange(sr);
+ }
+
+ if (!text.isNoCRLF()) {
+ st.append("\n");
+ }
+
String t = st.getText();
if (t == null)
return;
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatLine.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatLine.java
new file mode 100644
index 000000000..6dbe4a1d3
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ChatLine.java
@@ -0,0 +1,100 @@
+/*
+ * Created on Feb 18, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.ecf.example.collab.ui;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.example.collab.share.User;
+
+
+
+/**
+ * @author kgilmer
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class ChatLine {
+ private User originator = null; //
+ private String text = null;
+ private boolean isPrivate = false;
+ private boolean isRaw = false;
+ private boolean noCRLF = false;
+
+ public ChatLine() {
+
+ }
+
+ public ChatLine(String text) {
+ this.text = text;
+
+ }
+
+ public ChatLine(String text, User user) {
+ this.text = text;
+ this.originator = user;
+ }
+ /**
+ * @return Returns the originator.
+ */
+ public User getOriginator() {
+ return originator;
+ }
+ /**
+ * @param originator The originator to set.
+ */
+ public void setOriginator(User originator) {
+ this.originator = originator;
+ }
+ /**
+ * @return Returns the text.
+ */
+ public String getText() {
+ return text;
+ }
+ /**
+ * @param text The text to set.
+ */
+ public void setText(String text) {
+ this.text = text;
+ }
+ /**
+ * @return Returns the isPrivate.
+ */
+ public boolean isPrivate() {
+ return isPrivate;
+ }
+ /**
+ * @param isPrivate The isPrivate to set.
+ */
+ public void setPrivate(boolean isPrivate) {
+ this.isPrivate = isPrivate;
+ }
+ /**
+ * @return Returns the isRaw.
+ */
+ public boolean isRaw() {
+ return isRaw;
+ }
+ /**
+ * @param isRaw The isRaw to set.
+ */
+ public void setRaw(boolean isRaw) {
+ this.isRaw = isRaw;
+ }
+ /**
+ * @return Returns the noCRLF.
+ */
+ public boolean isNoCRLF() {
+ return noCRLF;
+ }
+ /**
+ * @param noCRLF The noCRLF to set.
+ */
+ public void setNoCRLF(boolean noCRLF) {
+ this.noCRLF = noCRLF;
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ClientPreferencePage.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ClientPreferencePage.java
index fdcef7f1b..c8f791dc0 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ClientPreferencePage.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/ClientPreferencePage.java
@@ -34,6 +34,7 @@ public class ClientPreferencePage extends FieldEditorPreferencePage implements
//this.getPreferenceStore().setDefault(ClientPlugin.PREF_CHAT_FONT, "");
this.getPreferenceStore().setDefault(ClientPlugin.PREF_CONFIRM_FILE_SEND, true);
+ this.getPreferenceStore().setDefault(ClientPlugin.PREF_CONFIRM_FILE_RECEIVE, true);
this.getPreferenceStore().setDefault(ClientPlugin.PREF_CONFIRM_REMOTE_VIEW, true);
}
@@ -48,7 +49,8 @@ public class ClientPreferencePage extends FieldEditorPreferencePage implements
getFieldEditorParent()));
addField(new BooleanFieldEditor(ClientPlugin.PREF_DISPLAY_TIMESTAMP,
"Show time for each chat entry", getFieldEditorParent()));
- addField(new FontFieldEditor(ClientPlugin.PREF_CHAT_FONT, "Chat window font", getFieldEditorParent()));
+ addField(new FontFieldEditor(ClientPlugin.PREF_CHAT_FONT, "Chat window font:", getFieldEditorParent()));
+ addField(new BooleanFieldEditor(ClientPlugin.PREF_CONFIRM_FILE_RECEIVE, "Confirm before receiving file.", getFieldEditorParent()));
/*IntegerFieldEditor rate = new IntegerFieldEditor(ClientPlugin.PREF_FILE_TRANSFER_RATE,
"Maximum transfer rate for file transfers.", getFieldEditorParent());*/
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatClientView.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatClientView.java
index 4fb6f790c..183fc718e 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatClientView.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatClientView.java
@@ -150,14 +150,14 @@ public class LineChatClientView implements FileSenderUI {
myNames.put(userID, username);
final String str = existingName + " changed name to "
+ username;
- showText(str);
+ showText(new ChatLine(str));
}
return false;
} else {
myNames.put(userID, username);
final String str = makeChatLine(username + " " + ENTER_STRING);
addUserToTree(ud);
- showText(str);
+ showText(new ChatLine(str));
return true;
}
}
@@ -189,11 +189,11 @@ public class LineChatClientView implements FileSenderUI {
refreshTreeView();
}
- protected void appendAndScrollToBottom(final String str) {
+ protected void appendAndScrollToBottom(final ChatLine str) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (teamChat != null)
- teamChat.appendText(str + "\n");
+ teamChat.appendText(str);
}
});
}
@@ -314,14 +314,14 @@ public class LineChatClientView implements FileSenderUI {
}
protected void handleTextInput(String text) {
- String fullString = null;
- if (lch == null) {
- fullString = "<Unknown> " + CLIENT_PREFIX + text;
- } else {
- fullString = getPrefix(userdata.getUserID()) + text;
+ ChatLine line = new ChatLine(text);
+
+ if (lch != null) {
+ line.setOriginator(userdata);
}
- appendAndScrollToBottom(fullString);
+ appendAndScrollToBottom(line);
teamChat.clearInput();
+
if (lch != null)
lch.inputText(text);
}
@@ -451,7 +451,7 @@ public class LineChatClientView implements FileSenderUI {
String name = getUserData(id);
if (name != null) {
final String str = makeChatLine(" " + name + " " + LEFT_STRING);
- showText(str);
+ showText(new ChatLine(str));
}
myNames.remove(id);
removeUserFromTree(id);
@@ -486,10 +486,10 @@ public class LineChatClientView implements FileSenderUI {
public void sendDone(File aFile, Exception e) {
if (e != null) {
- showText("Exception '" + e.getMessage() + "' sending file '"
- + aFile.getName());
+ showText(new ChatLine("Exception '" + e.getMessage() + "' sending file '"
+ + aFile.getName()));
} else {
- showText("\tSend of '" + aFile.getName() + "' completed");
+ showText(new ChatLine("\tSend of '" + aFile.getName() + "' completed"));
if (lch != null)
lch.refreshProject();
}
@@ -497,7 +497,7 @@ public class LineChatClientView implements FileSenderUI {
public void sendStart(File aFile, long length, float rate) {
// present user with notification that file is being transferred
- showText("\tSending '" + aFile.getName() + "'");
+ showText(new ChatLine("\tSending '" + aFile.getName() + "'"));
}
public void setTitle(String title) {
@@ -509,21 +509,10 @@ public class LineChatClientView implements FileSenderUI {
// teamChat.setVisible(visible);
}
- public void showLine(ID user, String line) {
- final String fullString = getPrefix(user) + line;
- appendAndScrollToBottom(fullString);
+ public void showLine(ChatLine line) {
+ appendAndScrollToBottom(line);
}
- public void showPrivate(ID user, String line) {
- final String fullString = getPrivatePrefix(user) + line;
- appendAndScrollToBottom(fullString);
- }
-
- public void showRawLine(ID sender, String str) {
- if (getUserData(sender) != null) {
- appendAndScrollToBottom(str);
- }
- }
public void startedTyping(final User user) {
Display.getDefault().asyncExec(new Runnable() {
@@ -534,8 +523,8 @@ public class LineChatClientView implements FileSenderUI {
});
}
- protected void showText(final String str) {
- appendAndScrollToBottom(str);
+ protected void showText(final ChatLine line) {
+ appendAndScrollToBottom(line);
}
public void toFront() {
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatView.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatView.java
index a61db5fa4..2f0d48972 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatView.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/LineChatView.java
@@ -30,7 +30,7 @@ import org.eclipse.ui.part.ViewPart;
public class LineChatView extends ViewPart {
// The single view
- private static final String COLLABORATION_PROJECTS_ARE_NOT_AVAILABLE_ = "No project collaboration sessions joined\n\nTo join a project collaboration session, select a project in either the Navigator or Package Explorer view,\nright-click to open context menu for project, choose ECF menu, and choose 'Join ECF Collaboration...'";
+ private static final String COLLABORATION_PROJECTS_ARE_NOT_AVAILABLE_ = "No project collaboration sessions joined.\n\nTo join a project collaboration session, select a project in either the Navigator or Package Explorer view,\nright-click to open context menu for project, choose ECF menu, and choose 'Join ECF Collaboration...'.";
static protected LineChatView singleton = null;
static protected Hashtable clientViews = new Hashtable();
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/TeamChat.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/TeamChat.java
index 1f1df3a77..c920b2f5b 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/TeamChat.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/TeamChat.java
@@ -69,7 +69,7 @@ class TeamChat extends Composite {
}
}
- void appendText(String text) {
+ void appendText(ChatLine text) {
if (chatWindow != null
&& chatWindow.getShell() != null
&& !chatWindow.getShell().isDisposed()

Back to the top