Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-09-03 00:25:49 +0000
committerslewis2008-09-03 00:25:49 +0000
commitdc2ea7362b075d06e5cbfe68f1e116318f606c2f (patch)
treecd973ae44f15cb2d407ab11f2c8f960cfdda1519
parentde1bf8ed8510dd87139bb630cc7363577b53830f (diff)
downloadorg.eclipse.ecf-dc2ea7362b075d06e5cbfe68f1e116318f606c2f.tar.gz
org.eclipse.ecf-dc2ea7362b075d06e5cbfe68f1e116318f606c2f.tar.xz
org.eclipse.ecf-dc2ea7362b075d06e5cbfe68f1e116318f606c2f.zip
Fix for bug 238976.
-rw-r--r--framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/Messages.java7
-rw-r--r--framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/messages.properties7
-rw-r--r--framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/DocShare.java95
-rw-r--r--framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/menu/DocShareRosterMenuHandler.java61
4 files changed, 128 insertions, 42 deletions
diff --git a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/Messages.java b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/Messages.java
index 3c57da218..ea67a066e 100644
--- a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/Messages.java
+++ b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/Messages.java
@@ -27,15 +27,16 @@ public class Messages extends NLS {
public static String DocShare_EXCEPTION_RECEIVING_MESSAGE_MESSAGE;
public static String DocShare_EXCEPTION_RECEIVING_MESSAGE_TITLE;
public static String DocShare_EXCEPTION_SEND_MESSAGE;
+ public static String DocShare_STOP_SHARED_EDITOR_REMOTE;
+ public static String DocShare_STOP_SHARED_EDITOR_TITLE;
+ public static String DocShare_STOP_SHARED_EDITOR_US;
public static String DocShareRosterMenuContributionItem_SHARE_EDITOR_MENU_TEXT;
public static String DocShareRosterMenuContributionItem_STOP_SHARE_EDITOR_MENU_TEXT;
- public static String DocShareRosterMenuHandler_ERROR_ALREADY_PARTICIPATING;
+ public static String DocShareRosterMenuHandler_DOCSHARE_START_ERROR_TITLE;
public static String DocShareRosterMenuHandler_ERROR_EDITOR_ALREADY_SHARING;
- public static String DocShareRosterMenuHandler_ERROR_NO_DOCUMENT_CONTENT;
public static String DocShareRosterMenuHandler_ERROR_NO_SENDER;
public static String DocShareRosterMenuHandler_ERROR_NOT_CONNECTED;
public static String DocShareRosterMenuHandler_EXCEPTION_EDITOR_NOT_TEXT;
- public static String DocShareRosterMenuHandler_EXCEPTION_SEND_INITIATE;
public static String DocShareRosterMenuHandler_NO_FILENAME_WITH_CONTENT;
public static String ECFStart_ERROR_CONTAINER_MANAGER_NOT_AVAILABLE;
public static String ECFStart_ERROR_DOCUMENT_SHARE_NOT_CREATED;
diff --git a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/messages.properties b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/messages.properties
index fca1709ef..ef8639fb8 100644
--- a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/messages.properties
+++ b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/docshare/messages.properties
@@ -17,15 +17,16 @@ DocShare_EXCEPTION_INVALID_MESSAGE=message is invalid type {0}
DocShare_EXCEPTION_RECEIVING_MESSAGE_MESSAGE=Exception handling start message {0}
DocShare_EXCEPTION_RECEIVING_MESSAGE_TITLE=Exception receiving message
DocShare_EXCEPTION_SEND_MESSAGE=send message error
+DocShare_STOP_SHARED_EDITOR_REMOTE=The remote user was disconnected, and shared editing stopped
+DocShare_STOP_SHARED_EDITOR_TITLE=Shared Editor Stopped
+DocShare_STOP_SHARED_EDITOR_US=Our account was disconnected, and shared editing stopped
DocShareRosterMenuContributionItem_SHARE_EDITOR_MENU_TEXT=Share Editor With
DocShareRosterMenuContributionItem_STOP_SHARE_EDITOR_MENU_TEXT=Stop Sharing Editor with {0}
-DocShareRosterMenuHandler_ERROR_ALREADY_PARTICIPATING=Already participating in editor sharing
+DocShareRosterMenuHandler_DOCSHARE_START_ERROR_TITLE=Error Starting Docshare
DocShareRosterMenuHandler_ERROR_EDITOR_ALREADY_SHARING=Editor is already sharing
-DocShareRosterMenuHandler_ERROR_NO_DOCUMENT_CONTENT=No document content
DocShareRosterMenuHandler_ERROR_NO_SENDER=No sender available
DocShareRosterMenuHandler_ERROR_NOT_CONNECTED=Not connected
DocShareRosterMenuHandler_EXCEPTION_EDITOR_NOT_TEXT=Editor is not text editor
-DocShareRosterMenuHandler_EXCEPTION_SEND_INITIATE=send initiate
DocShareRosterMenuHandler_NO_FILENAME_WITH_CONTENT=No file name associated with content
ECFStart_ERROR_CONTAINER_MANAGER_NOT_AVAILABLE=Container manager not available
ECFStart_ERROR_DOCUMENT_SHARE_NOT_CREATED=Document share for container {0} not created.
diff --git a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/DocShare.java b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/DocShare.java
index 92e0cf9c1..0a3382830 100644
--- a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/DocShare.java
+++ b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/DocShare.java
@@ -19,6 +19,7 @@ import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.core.util.Trace;
@@ -29,12 +30,13 @@ import org.eclipse.ecf.internal.docshare.*;
import org.eclipse.ecf.internal.provisional.docshare.cola.ColaSynchronizer;
import org.eclipse.ecf.internal.provisional.docshare.cola.ColaUpdateMessage;
import org.eclipse.ecf.internal.provisional.docshare.messages.*;
+import org.eclipse.ecf.presence.IPresenceContainerAdapter;
+import org.eclipse.ecf.presence.roster.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.*;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.IDocumentProvider;
@@ -64,6 +66,41 @@ public class DocShare extends AbstractShare {
* Text editor
*/
ITextEditor editor;
+
+ IRosterManager rosterManager;
+
+ IRosterListener rosterListener = new IRosterListener() {
+ public void handleRosterEntryAdd(IRosterEntry entry) {
+ // XXX nothing to do
+ }
+
+ public void handleRosterEntryRemove(IRosterEntry entry) {
+ // XXX nothing to do
+ }
+
+ public void handleRosterUpdate(IRoster roster, IRosterItem changedValue) {
+ if (changedValue instanceof IRosterEntry) {
+ ID changedID = ((IRosterEntry) changedValue).getUser().getID();
+ ID oID = null;
+ ID otherID = null;
+ Shell shell = null;
+ synchronized (stateLock) {
+ oID = getOurID();
+ otherID = getOtherID();
+ shell = editor.getSite().getShell();
+ }
+ if (oID != null && changedID.equals(oID)) {
+ localStopShare();
+ showStopShareMessage(shell, Messages.DocShare_STOP_SHARED_EDITOR_US);
+ } else if (otherID != null && changedID.equals(otherID)) {
+ localStopShare();
+ showStopShareMessage(shell, Messages.DocShare_STOP_SHARED_EDITOR_REMOTE);
+ }
+ }
+ }
+
+ };
+
/**
* Content that we have received via start message, before user has
* responded to question about whether or not to display in editor. Should
@@ -198,7 +235,7 @@ public class DocShare extends AbstractShare {
* @param fileName the file name of the file to be shared (with suffix type extension). Must not be <code>null</code>.
* @param editorPart the text editor currently showing the contents of this editor. Must not be <code>null</code>.
*/
- public void startShare(final ID our, final String fromName, final ID toID, final String fileName, final ITextEditor editorPart) {
+ public void startShare(final IRosterManager rm, final ID our, final String fromName, final ID toID, final String fileName, final ITextEditor editorPart) {
Trace.entering(Activator.PLUGIN_ID, DocshareDebugOptions.METHODS_ENTERING, DocShare.class, "startShare", new Object[] {our, fromName, toID, fileName, editorPart}); //$NON-NLS-1$
Assert.isNotNull(our);
final String fName = (fromName == null) ? our.getName() : fromName;
@@ -213,7 +250,7 @@ public class DocShare extends AbstractShare {
// send start message
send(toID, new StartMessage(our, fName, toID, content, fileName));
// Set local sharing start (to setup doc listener)
- localStartShare(our, our, toID, editorPart);
+ localStartShare(rm, our, our, toID, editorPart);
} catch (final Exception e) {
logError(Messages.DocShare_ERROR_STARTING_EDITOR_TITLE, e);
showErrorToUser(Messages.DocShare_ERROR_STARTING_EDITOR_TITLE, NLS.bind(Messages.DocShare_ERROR_STARTING_EDITOR_MESSAGE, e.getLocalizedMessage()));
@@ -268,7 +305,7 @@ public class DocShare extends AbstractShare {
/**
* This method called by the {@link #handleMessage(ID, byte[])} method if
* the type of the message received is a start message (sent by remote party
- * via {@link #startShare(ID, String, ID, String, ITextEditor)}.
+ * via {@link #startShare(IRosterManager, ID, String, ID, String, ITextEditor)}.
*
* @param message
* the UpdateMessage received.
@@ -307,7 +344,7 @@ public class DocShare extends AbstractShare {
// Then open up text editor
final ITextEditor ep = (ITextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(dsei, getEditorIdForFileName(filename));
// Then change our local state
- localStartShare(our, senderID, our, ep);
+ localStartShare(getLocalRosterManager(), our, senderID, our, ep);
} else {
// Send stop message to initiator
sendStopMessage();
@@ -322,6 +359,17 @@ public class DocShare extends AbstractShare {
});
}
+ IRosterManager getLocalRosterManager() {
+ IContainer container = (IContainer) this.adapter.getAdapter(IContainer.class);
+ if (container != null) {
+ IPresenceContainerAdapter presenceContainerAdapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
+ if (presenceContainerAdapter != null) {
+ return presenceContainerAdapter.getRosterManager();
+ }
+ }
+ return null;
+ }
+
void modifyStartContent(int offset, int length, String text) {
final StringBuffer result = new StringBuffer(startContent.substring(0, offset));
result.append(text);
@@ -415,8 +463,32 @@ public class DocShare extends AbstractShare {
}
protected void handleDisconnectEvent(IChannelDisconnectEvent cde) {
- super.handleDisconnectEvent(cde);
+ boolean weDisconnected = (ourID != null && ourID.equals(cde.getTargetID()));
+ Shell shell = null;
+ if (isSharing()) {
+ shell = editor.getSite().getShell();
+ }
+ // Stop things and *then* notify user
localStopShare();
+ if (shell != null) {
+ if (weDisconnected)
+ showStopShareMessage(shell, Messages.DocShare_STOP_SHARED_EDITOR_US);
+ else
+ showStopShareMessage(shell, Messages.DocShare_STOP_SHARED_EDITOR_REMOTE);
+ }
+ }
+
+ /**
+ * @param shell must not be <code>null</code>
+ * @param message message content for message dialog
+ */
+ void showStopShareMessage(final Shell shell, final String message) {
+ Display display = shell.getDisplay();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ MessageDialog.openInformation(shell, Messages.DocShare_STOP_SHARED_EDITOR_TITLE, message);
+ }
+ });
}
IFileStore getTempFileStore(String fromUsername, String fileName, String content) throws IOException, CoreException {
@@ -489,9 +561,13 @@ public class DocShare extends AbstractShare {
}
}
- void localStartShare(ID our, ID initiator, ID receiver, ITextEditor edt) {
+ void localStartShare(final IRosterManager rm, ID our, ID initiator, ID receiver, ITextEditor edt) {
synchronized (stateLock) {
localStopShare();
+ this.rosterManager = rm;
+ if (this.rosterManager != null) {
+ this.rosterManager.addRosterListener(rosterListener);
+ }
this.ourID = our;
this.initiatorID = initiator;
this.receiverID = receiver;
@@ -509,6 +585,9 @@ public class DocShare extends AbstractShare {
void localStopShare() {
synchronized (stateLock) {
+ if (rosterManager != null)
+ rosterManager.removeRosterListener(rosterListener);
+ this.rosterManager = null;
this.ourID = null;
this.initiatorID = null;
this.receiverID = null;
diff --git a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/menu/DocShareRosterMenuHandler.java b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/menu/DocShareRosterMenuHandler.java
index caf244f36..1051d1070 100644
--- a/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/menu/DocShareRosterMenuHandler.java
+++ b/framework/bundles/org.eclipse.ecf.docshare/src/org/eclipse/ecf/internal/provisional/docshare/menu/DocShareRosterMenuHandler.java
@@ -11,23 +11,19 @@
package org.eclipse.ecf.internal.provisional.docshare.menu;
-import org.eclipse.ecf.internal.provisional.docshare.DocShare;
-
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.user.IUser;
import org.eclipse.ecf.internal.docshare.Activator;
import org.eclipse.ecf.internal.docshare.Messages;
-import org.eclipse.ecf.presence.roster.IRosterEntry;
+import org.eclipse.ecf.internal.provisional.docshare.DocShare;
+import org.eclipse.ecf.presence.roster.*;
import org.eclipse.ecf.presence.ui.menu.AbstractRosterMenuHandler;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.ui.*;
import org.eclipse.ui.texteditor.ITextEditor;
/**
@@ -67,26 +63,35 @@ public class DocShareRosterMenuHandler extends AbstractRosterMenuHandler {
return null;
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.presence.ui.menu.AbstractRosterMenuHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ private void showErrorMessage(String errorMessage) {
+ ErrorDialog.openError(null, Messages.DocShareRosterMenuHandler_DOCSHARE_START_ERROR_TITLE, errorMessage, new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage, null));
+ }
+
+ /**
+ * @throws ExecutionException
*/
public Object execute(ExecutionEvent arg0) throws ExecutionException {
- final IContainer container = (IContainer) getRosterEntry().getRoster().getPresenceContainerAdapter().getAdapter(IContainer.class);
- if (container.getConnectedID() == null)
- throw new ExecutionException(Messages.DocShareRosterMenuHandler_ERROR_NOT_CONNECTED);
- final DocShare sender = Activator.getDefault().getDocShare(container.getID());
- if (sender == null)
- throw new ExecutionException(Messages.DocShareRosterMenuHandler_ERROR_NO_SENDER);
- if (sender.isSharing())
- throw new ExecutionException(Messages.DocShareRosterMenuHandler_ERROR_EDITOR_ALREADY_SHARING);
- final ITextEditor textEditor = getTextEditor();
- if (textEditor == null)
- throw new ExecutionException(Messages.DocShareRosterMenuHandler_EXCEPTION_EDITOR_NOT_TEXT);
- final String fileName = getFileName(textEditor);
- if (fileName == null)
- throw new ExecutionException(Messages.DocShareRosterMenuHandler_NO_FILENAME_WITH_CONTENT);
- final IUser user = getRosterEntry().getRoster().getUser();
- sender.startShare(user.getID(), user.getName(), getRosterEntry().getUser().getID(), fileName, textEditor);
+ IRosterEntry rosterEntry = getRosterEntry();
+ if (rosterEntry != null) {
+ IRoster roster = rosterEntry.getRoster();
+ IRosterManager rosterManager = roster.getPresenceContainerAdapter().getRosterManager();
+ final IContainer container = (IContainer) roster.getPresenceContainerAdapter().getAdapter(IContainer.class);
+ if (container.getConnectedID() == null)
+ showErrorMessage(Messages.DocShareRosterMenuHandler_ERROR_NOT_CONNECTED);
+ final DocShare sender = Activator.getDefault().getDocShare(container.getID());
+ if (sender == null)
+ showErrorMessage(Messages.DocShareRosterMenuHandler_ERROR_NO_SENDER);
+ if (sender.isSharing())
+ showErrorMessage(Messages.DocShareRosterMenuHandler_ERROR_EDITOR_ALREADY_SHARING);
+ final ITextEditor textEditor = getTextEditor();
+ if (textEditor == null)
+ showErrorMessage(Messages.DocShareRosterMenuHandler_EXCEPTION_EDITOR_NOT_TEXT);
+ final String fileName = getFileName(textEditor);
+ if (fileName == null)
+ showErrorMessage(Messages.DocShareRosterMenuHandler_NO_FILENAME_WITH_CONTENT);
+ final IUser user = roster.getUser();
+ sender.startShare(rosterManager, user.getID(), user.getName(), rosterEntry.getUser().getID(), fileName, textEditor);
+ }
return null;
}
}

Back to the top