Search in sources :

Example 1 with IDocumentChange

use of org.eclipse.ecf.sync.doc.IDocumentChange in project ecf by eclipse.

the class ColaSynchronizationStrategy method registerLocalChange.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.sync.doc.IDocumentSynchronizationStrategy#registerLocalChange
	 * (org.eclipse.ecf.sync.doc.IModelChange)
	 */
public IModelChangeMessage[] registerLocalChange(IModelChange localChange) {
    List results = new ArrayList();
    Trace.entering(Activator.PLUGIN_ID, SyncDebugOptions.METHODS_ENTERING, this.getClass(), "registerLocalChange", // $NON-NLS-1$
    localChange);
    if (localChange instanceof IDocumentChange) {
        final IDocumentChange docChange = (IDocumentChange) localChange;
        final ColaDocumentChangeMessage colaMsg = new ColaDocumentChangeMessage(new DocumentChangeMessage(docChange.getOffset(), docChange.getLengthOfReplacedText(), docChange.getText()), localOperationsCount, remoteOperationsCount);
        // to results
        if (!colaMsg.isReplacement()) {
            unacknowledgedLocalOperations.add(colaMsg);
            localOperationsCount++;
            results.add(colaMsg);
        } else {
            // It *is a replacement message, so we add both a delete and an
            // insert message
            // First create/add a delete message (text set to "")...
            ColaDocumentChangeMessage delMsg = new ColaDocumentChangeMessage(new DocumentChangeMessage(docChange.getOffset(), docChange.getLengthOfReplacedText(), ""), localOperationsCount, remoteOperationsCount);
            unacknowledgedLocalOperations.add(delMsg);
            localOperationsCount++;
            results.add(delMsg);
            // Then create/add the insert message (length set to 0)
            ColaDocumentChangeMessage insMsg = new ColaDocumentChangeMessage(new DocumentChangeMessage(docChange.getOffset(), 0, docChange.getText()), localOperationsCount, remoteOperationsCount);
            unacknowledgedLocalOperations.add(insMsg);
            localOperationsCount++;
            results.add(insMsg);
        }
        Trace.exiting(Activator.PLUGIN_ID, SyncDebugOptions.METHODS_EXITING, this.getClass(), "registerLocalChange", // $NON-NLS-1$
        colaMsg);
    }
    return (IModelChangeMessage[]) results.toArray(new IModelChangeMessage[] {});
}
Also used : IDocumentChange(org.eclipse.ecf.sync.doc.IDocumentChange) DocumentChangeMessage(org.eclipse.ecf.sync.doc.DocumentChangeMessage)

Example 2 with IDocumentChange

use of org.eclipse.ecf.sync.doc.IDocumentChange in project ecf by eclipse.

the class ColaSynchronizationStrategy method transformRemoteChange.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.sync.doc.IDocumentSynchronizationStrategy#
	 * transformRemoteChange(org.eclipse.ecf.sync.doc.IModelChangeMessage)
	 */
public IModelChange[] transformRemoteChange(IModelChange remoteChange) {
    if (!(remoteChange instanceof DocumentChangeMessage))
        return new IDocumentChange[0];
    final DocumentChangeMessage m = (DocumentChangeMessage) remoteChange;
    final List l = this.transformIncomingMessage(m);
    return (IDocumentChange[]) l.toArray(new IDocumentChange[] {});
}
Also used : IDocumentChange(org.eclipse.ecf.sync.doc.IDocumentChange) DocumentChangeMessage(org.eclipse.ecf.sync.doc.DocumentChangeMessage)

Example 3 with IDocumentChange

use of org.eclipse.ecf.sync.doc.IDocumentChange in project ecf by eclipse.

the class SharedDocClient method processRemoteMessage.

private void processRemoteMessage(byte[] msg) {
    if (msg != null) {
        try {
            synchronized (this.getClass()) {
                IModelChange change = syncStrategy.deserializeRemoteChange(msg);
                System.out.println(name + ";received=" + change);
                IDocumentChange[] documentChanges = (IDocumentChange[]) syncStrategy.transformRemoteChange(change);
                for (int i = 0; i < documentChanges.length; i++) {
                    applyChangeToLocalDocument(false, documentChanges[i]);
                }
            }
        } catch (SerializationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : SerializationException(org.eclipse.ecf.sync.SerializationException) IModelChange(org.eclipse.ecf.sync.IModelChange) IDocumentChange(org.eclipse.ecf.sync.doc.IDocumentChange)

Aggregations

IDocumentChange (org.eclipse.ecf.sync.doc.IDocumentChange)3 DocumentChangeMessage (org.eclipse.ecf.sync.doc.DocumentChangeMessage)2 IModelChange (org.eclipse.ecf.sync.IModelChange)1 SerializationException (org.eclipse.ecf.sync.SerializationException)1