Search in sources :

Example 31 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.

the class FileBufferDocumentTester method doTestCreate.

private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
    IFile file = (IFile) fTestProject.findMember(filePath);
    assertNotNull("Test Case in error. Could not find file " + filePath, file);
    IPath fullPath = file.getFullPath();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(fullPath, LocationKind.IFILE, null);
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(fullPath);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertTrue("wrong class of document: " + (document != null ? document.getClass() : null), expectedDocumentClass.isInstance(document));
    assertTrue("document does not implement IDocumentExtension3", document instanceof IDocumentExtension3);
    IDocumentPartitioner actualPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    assertTrue("wrong partitioner in document: " + actualPartitioner, expectedPartioner.isInstance(actualPartitioner));
    bufferManager.disconnect(fullPath, LocationKind.IFILE, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 32 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project dbeaver by serge-rider.

the class XMLEditor method setupDocument.

private void setupDocument() {
    IDocument document = getDocument();
    if (document != null) {
        IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
        partitioner.connect(document);
        ((IDocumentExtension3) document).setDocumentPartitioner(XMLPartitionScanner.XML_PARTITIONING, partitioner);
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IDocument(org.eclipse.jface.text.IDocument)

Example 33 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project dbeaver by serge-rider.

the class JSONTextEditor method setupDocument.

private void setupDocument() {
    IDocument document = getDocument();
    if (document != null) {
        IDocumentPartitioner partitioner = new FastPartitioner(new JSONPartitionScanner(), new String[] { JSONPartitionScanner.JSON_STRING });
        partitioner.connect(document);
        ((IDocumentExtension3) document).setDocumentPartitioner(JSONPartitionScanner.JSON_PARTITIONING, partitioner);
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IDocument(org.eclipse.jface.text.IDocument)

Example 34 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project xtext-xtend by eclipse.

the class PartitionTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    document = get(XtextDocument.class);
    IDocumentPartitioner partitioner = get(IDocumentPartitioner.class);
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument)

Example 35 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project xtext-xtend by eclipse.

the class RichStringAwareSourceViewer method shift.

@SuppressWarnings("deprecation")
@Override
protected void shift(boolean useDefaultPrefixes, boolean right, boolean ignoreWhitespace) {
    if (useDefaultPrefixes && ignoreWhitespace) {
        // let's assume we toggled comments
        if (fUndoManager != null)
            fUndoManager.beginCompoundChange();
        IDocument d = getDocument();
        Map<String, IDocumentPartitioner> partitioners = null;
        DocumentRewriteSession rewriteSession = null;
        try {
            ITextSelection selection = (ITextSelection) getSelection();
            IRegion block = copiedGetTextBlockFromSelection(selection);
            ITypedRegion[] regions = TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false);
            regions = merger.merge(regions);
            int lineCount = 0;
            // [start line, end line, start line, end line, ...]
            int[] lines = new int[regions.length * 2];
            for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
                // start line of region
                lines[j] = copiedGetFirstCompleteLineOfRegion(regions[i]);
                // end line of region
                int length = regions[i].getLength();
                int offset = regions[i].getOffset() + length;
                if (length > 0)
                    offset--;
                lines[j + 1] = (lines[j] == -1 ? -1 : d.getLineOfOffset(offset));
                lineCount += lines[j + 1] - lines[j] + 1;
            }
            if (d instanceof IDocumentExtension4) {
                IDocumentExtension4 extension = (IDocumentExtension4) d;
                rewriteSession = extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
            } else {
                setRedraw(false);
                startSequentialRewriteMode(true);
            }
            if (lineCount >= 20)
                partitioners = TextUtilities.removeDocumentPartitioners(d);
            // Perform the shift operation.
            @SuppressWarnings("rawtypes") Map map = fDefaultPrefixChars;
            for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
                String[] prefixes = (String[]) copiedSelectContentTypePlugin(regions[i].getType(), map);
                if (prefixes != null && prefixes.length > 0 && lines[j] >= 0 && lines[j + 1] >= 0) {
                    if (right)
                        copiedShiftRight(lines[j], lines[j + 1], prefixes[0]);
                    else
                        copiedShiftLeft(lines[j], lines[j + 1], prefixes, ignoreWhitespace);
                }
            }
        } catch (BadLocationException x) {
            log.debug(x.getMessage(), x);
        } finally {
            if (partitioners != null)
                TextUtilities.addDocumentPartitioners(d, partitioners);
            if (d instanceof IDocumentExtension4) {
                IDocumentExtension4 extension = (IDocumentExtension4) d;
                extension.stopRewriteSession(rewriteSession);
            } else {
                stopSequentialRewriteMode();
                setRedraw(true);
            }
            if (fUndoManager != null)
                fUndoManager.endCompoundChange();
        }
    } else {
        super.shift(useDefaultPrefixes, right, ignoreWhitespace);
    }
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion) DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITypedRegion(org.eclipse.jface.text.ITypedRegion) Map(java.util.Map) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)72 IDocument (org.eclipse.jface.text.IDocument)27 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)27 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)25 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)12 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 IFile (org.eclipse.core.resources.IFile)7 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)7 IStructuredTextPartitioner (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)6 BadLocationException (org.eclipse.jface.text.BadLocationException)5 ITypedRegion (org.eclipse.jface.text.ITypedRegion)5 DocumentEvent (org.eclipse.jface.text.DocumentEvent)4 IDocumentListener (org.eclipse.jface.text.IDocumentListener)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)3 IPath (org.eclipse.core.runtime.IPath)3 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)3 SQLDocument (com.cubrid.common.ui.query.editor.SQLDocument)2 SQLPartitionScanner (com.cubrid.common.ui.query.editor.SQLPartitionScanner)2