|
Lines 16-21
Link Here
|
| 16 |
import java.io.*; |
16 |
import java.io.*; |
| 17 |
import org.eclipse.core.filesystem.EFS; |
17 |
import org.eclipse.core.filesystem.EFS; |
| 18 |
import org.eclipse.core.filesystem.IFileStore; |
18 |
import org.eclipse.core.filesystem.IFileStore; |
|
|
19 |
import org.eclipse.core.resources.IFile; |
| 20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 19 |
import org.eclipse.core.runtime.*; |
21 |
import org.eclipse.core.runtime.*; |
| 20 |
import org.eclipse.core.runtime.Assert; |
22 |
import org.eclipse.core.runtime.Assert; |
| 21 |
import org.eclipse.ecf.core.IContainer; |
23 |
import org.eclipse.ecf.core.IContainer; |
|
Lines 39-44
Link Here
|
| 39 |
import org.eclipse.swt.widgets.*; |
41 |
import org.eclipse.swt.widgets.*; |
| 40 |
import org.eclipse.ui.*; |
42 |
import org.eclipse.ui.*; |
| 41 |
import org.eclipse.ui.editors.text.EditorsUI; |
43 |
import org.eclipse.ui.editors.text.EditorsUI; |
|
|
44 |
import org.eclipse.ui.ide.IDE; |
| 45 |
import org.eclipse.ui.ide.ResourceUtil; |
| 42 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
46 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
| 43 |
import org.eclipse.ui.texteditor.ITextEditor; |
47 |
import org.eclipse.ui.texteditor.ITextEditor; |
| 44 |
|
48 |
|
|
Lines 220-234
Link Here
|
| 220 |
* a name to present to the receiver. If |
224 |
* a name to present to the receiver. If |
| 221 |
* <code>null, our.getName() will be used. |
225 |
* <code>null, our.getName() will be used. |
| 222 |
* @param toID the ID of the intended receiver. Must not be <code>null</code>. |
226 |
* @param toID the ID of the intended receiver. Must not be <code>null</code>. |
| 223 |
* @param fileName the file name of the file to be shared (with suffix type extension). Must not be <code>null</code>. |
227 |
* @param filePath the workspace-relative path of the file to be shared (with suffix type extension). Must not be <code>null</code>. |
| 224 |
* @param editorPart the text editor currently showing the contents of this editor. Must not be <code>null</code>. |
228 |
* @param editorPart the text editor currently showing the contents of this editor. Must not be <code>null</code>. |
| 225 |
*/ |
229 |
*/ |
| 226 |
public void startShare(final ID our, final String fromName, final ID toID, final String fileName, final ITextEditor editorPart) { |
230 |
public void startShare(final ID our, final String fromName, final ID toID, final String filePath, final ITextEditor editorPart) { |
| 227 |
Trace.entering(Activator.PLUGIN_ID, DocshareDebugOptions.METHODS_ENTERING, DocShare.class, "startShare", new Object[] {our, fromName, toID, fileName, editorPart}); //$NON-NLS-1$ |
231 |
Trace.entering(Activator.PLUGIN_ID, DocshareDebugOptions.METHODS_ENTERING, DocShare.class, "startShare", new Object[] {our, fromName, toID, filePath, editorPart}); //$NON-NLS-1$ |
| 228 |
Assert.isNotNull(our); |
232 |
Assert.isNotNull(our); |
| 229 |
final String fName = (fromName == null) ? our.getName() : fromName; |
233 |
final String fName = (fromName == null) ? our.getName() : fromName; |
| 230 |
Assert.isNotNull(toID); |
234 |
Assert.isNotNull(toID); |
| 231 |
Assert.isNotNull(fName); |
235 |
Assert.isNotNull(fName); |
|
|
236 |
Assert.isNotNull(filePath); |
| 232 |
Assert.isNotNull(editorPart); |
237 |
Assert.isNotNull(editorPart); |
| 233 |
Display.getDefault().syncExec(new Runnable() { |
238 |
Display.getDefault().syncExec(new Runnable() { |
| 234 |
public void run() { |
239 |
public void run() { |
|
Lines 240-246
Link Here
|
| 240 |
// Get content from local document |
245 |
// Get content from local document |
| 241 |
final String content = editorPart.getDocumentProvider().getDocument(editorPart.getEditorInput()).get(); |
246 |
final String content = editorPart.getDocumentProvider().getDocument(editorPart.getEditorInput()).get(); |
| 242 |
// Send start message with current content |
247 |
// Send start message with current content |
| 243 |
sendMessage(toID, new StartMessage(our, fName, toID, content, fileName).serialize()); |
248 |
sendMessage(toID, new StartMessage(our, fName, toID, content, filePath).serialize()); |
| 244 |
// Set local sharing start (to setup doc listener) |
249 |
// Set local sharing start (to setup doc listener) |
| 245 |
localStartShare(getLocalRosterManager(), our, our, toID, editorPart); |
250 |
localStartShare(getLocalRosterManager(), our, our, toID, editorPart); |
| 246 |
} catch (final Exception e) { |
251 |
} catch (final Exception e) { |
|
Lines 308-315
Link Here
|
| 308 |
Assert.isNotNull(senderUsername); |
313 |
Assert.isNotNull(senderUsername); |
| 309 |
final ID our = message.getReceiverID(); |
314 |
final ID our = message.getReceiverID(); |
| 310 |
Assert.isNotNull(our); |
315 |
Assert.isNotNull(our); |
| 311 |
final String filename = message.getFilename(); |
316 |
final String filePath = message.getFilename(); |
| 312 |
Assert.isNotNull(filename); |
317 |
Assert.isNotNull(filePath); |
| 313 |
final String documentContent = message.getDocumentContent(); |
318 |
final String documentContent = message.getDocumentContent(); |
| 314 |
Assert.isNotNull(documentContent); |
319 |
Assert.isNotNull(documentContent); |
| 315 |
|
320 |
|
|
Lines 334-346
Link Here
|
| 334 |
public void run() { |
339 |
public void run() { |
| 335 |
try { |
340 |
try { |
| 336 |
// First, ask user if they want to receive the doc |
341 |
// First, ask user if they want to receive the doc |
| 337 |
if (openReceiverDialog(senderID, senderUsername, filename)) { |
342 |
if (openReceiverDialog(senderID, senderUsername, filePath)) { |
| 338 |
// If so, then we create a new DocShareEditorInput |
343 |
IPath path = new Path(filePath); |
| 339 |
final DocShareEditorInput dsei = new DocShareEditorInput(getTempFileStore(senderUsername, filename, startContent), senderUsername, filename); |
344 |
String filename = path.lastSegment(); |
| 340 |
// Then open up text editor |
345 |
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 341 |
final ITextEditor ep = (ITextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(dsei, getEditorIdForFileName(filename)); |
346 |
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); |
| 342 |
// Then change our local state |
347 |
// check if the file exists |
| 343 |
localStartShare(getLocalRosterManager(), our, senderID, our, ep); |
348 |
if (file.exists()) { |
|
|
349 |
// if it does, prompt for overwrite |
| 350 |
if (openOverwritePrompt(filePath)) { |
| 351 |
int counter = 0; |
| 352 |
// Test.java -> Test.java.0 |
| 353 |
IFile backup = file.getParent().getFile(new Path(filename + '.' + counter)); |
| 354 |
while (backup.exists()) { |
| 355 |
// if the file exists, keep trying |
| 356 |
counter++; |
| 357 |
backup = file.getParent().getFile(new Path(filename + '.' + counter)); |
| 358 |
} |
| 359 |
|
| 360 |
// set the backup's contents to match the original's |
| 361 |
backup.create(file.getContents(), true, null); |
| 362 |
|
| 363 |
// find an existing editor for the backed up file |
| 364 |
ITextEditor textEditor = (ITextEditor) ResourceUtil.findEditor(page, file); |
| 365 |
if (textEditor == null) { |
| 366 |
// none found, open one |
| 367 |
textEditor = (ITextEditor) IDE.openEditor(page, file, getEditorIdForFileName(filePath)); |
| 368 |
} |
| 369 |
// retrieve the document |
| 370 |
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); |
| 371 |
// alter its contents to match the remote peer's |
| 372 |
document.set(startContent); |
| 373 |
// Then change our local state |
| 374 |
localStartShare(getLocalRosterManager(), our, senderID, our, textEditor); |
| 375 |
} else { |
| 376 |
// User doesn't want to overwrite with remote changes, send stop message to initiator |
| 377 |
sendStopMessage(); |
| 378 |
// Then we stop the local share |
| 379 |
localStopShare(); |
| 380 |
} |
| 381 |
} else { |
| 382 |
// The file doesn't exist, so we create a new DocShareEditorInput |
| 383 |
final DocShareEditorInput dsei = new DocShareEditorInput(getTempFileStore(senderUsername, filename, startContent), senderUsername, filename); |
| 384 |
// Then open up text editor |
| 385 |
final ITextEditor ep = (ITextEditor) page.openEditor(dsei, getEditorIdForFileName(filename)); |
| 386 |
// Then change our local state |
| 387 |
localStartShare(getLocalRosterManager(), our, senderID, our, ep); |
| 388 |
} |
| 344 |
} else { |
389 |
} else { |
| 345 |
// Send stop message to initiator |
390 |
// Send stop message to initiator |
| 346 |
sendStopMessage(); |
391 |
sendStopMessage(); |
|
Lines 473-478
Link Here
|
| 473 |
return MessageDialog.openQuestion(null, Messages.DocShare_EDITOR_SHARE_POPUP_TITLE, NLS.bind(Messages.DocShare_EDITOR_SHARE_POPUP_MESSAGE, fromUsername, fileName)); |
518 |
return MessageDialog.openQuestion(null, Messages.DocShare_EDITOR_SHARE_POPUP_TITLE, NLS.bind(Messages.DocShare_EDITOR_SHARE_POPUP_MESSAGE, fromUsername, fileName)); |
| 474 |
} |
519 |
} |
| 475 |
|
520 |
|
|
|
521 |
boolean openOverwritePrompt(String filePath) { |
| 522 |
return MessageDialog.openQuestion(null, Messages.DocShare_EDITOR_SHARE_POPUP_TITLE, NLS.bind(Messages.DocShare_EDITOR_SHARE_FILE_EXISTS_POPUP_MESSAGE, filePath)); |
| 523 |
} |
| 524 |
|
| 476 |
protected void handleDisconnectEvent(IChannelDisconnectEvent cde) { |
525 |
protected void handleDisconnectEvent(IChannelDisconnectEvent cde) { |
| 477 |
boolean weDisconnected = (ourID != null && ourID.equals(cde.getTargetID())); |
526 |
boolean weDisconnected = (ourID != null && ourID.equals(cde.getTargetID())); |
| 478 |
Shell shell = null; |
527 |
Shell shell = null; |