Java 类org.eclipse.jface.text.projection.ProjectionDocument 实例源码

项目:bts    文件:XtextDocumentUtil.java   
public static IXtextDocument get(Object ctx) {
    if (ctx instanceof IXtextDocument)
        return (IXtextDocument) ctx;
    if (ctx instanceof ProjectionDocument)
        return get(((ProjectionDocument) ctx).getMasterDocument());
    if (ctx instanceof ITextViewer)
        return get(((ITextViewer) ctx).getDocument());
    if (ctx instanceof XtextEditor)
        return ((XtextEditor) ctx).getDocument();
    if (ctx instanceof IFile) {
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        return get(activePage.findEditor(new FileEditorInput((IFile) ctx)));
    }
    return null;
}
项目:statecharts    文件:XtextSourceViewerEx.java   
/**
 * Overwritten to handle offset properly.
 */
@Override
protected boolean updateSlaveDocument(IDocument slaveDocument,
        int modelRangeOffset, int modelRangeLength)
        throws BadLocationException {
    if (slaveDocument instanceof ProjectionDocument) {
        ProjectionDocument projection = (ProjectionDocument) slaveDocument;

        int offset = modelRangeOffset;
        int length = modelRangeLength;

        if (!isProjectionMode()) {
            // mimic original TextViewer behavior
            IDocument master = projection.getMasterDocument();
            int line = master.getLineOfOffset(modelRangeOffset);
            offset += master.getLineOffset(line);
            length = (modelRangeOffset - offset) + modelRangeLength;
        }

        try {
            // fHandleProjectionChanges= false;
            setPrivateHandleProjectionChangesField(false);
            projection.replaceMasterDocumentRanges(offset, length);
        } finally {
            // fHandleProjectionChanges= true;
            setPrivateHandleProjectionChangesField(true);
        }
        return true;
    }
    return false;
}
项目:PDFReporter-Studio    文件:XtextSourceViewerEx.java   
/**
 * Overwritten to handle offset properly.
 */
@Override
protected boolean updateSlaveDocument(IDocument slaveDocument,
        int modelRangeOffset, int modelRangeLength)
        throws BadLocationException {
    if (slaveDocument instanceof ProjectionDocument) {
        ProjectionDocument projection = (ProjectionDocument) slaveDocument;

        int offset = modelRangeOffset;
        int length = modelRangeLength;

        if (!isProjectionMode()) {
            // mimic original TextViewer behavior
            IDocument master = projection.getMasterDocument();
            int line = master.getLineOfOffset(modelRangeOffset);
            offset += master.getLineOffset(line);
            length = (modelRangeOffset - offset) + modelRangeLength;
        }

        try {
            // fHandleProjectionChanges= false;
            setPrivateHandleProjectionChangesField(false);
            projection.replaceMasterDocumentRanges(offset, length);
        } finally {
            // fHandleProjectionChanges= true;
            setPrivateHandleProjectionChangesField(true);
        }
        return true;
    }
    return false;
}