Search in sources :

Example 21 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);
    System.out.println(fTestProject.getLocation().toOSString());
    assertNotNull("Test Case in error. Could not find file " + filePath, file);
    IPath locationPath = file.getLocation();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(locationPath, null);
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
    IDocumentPartitioner setupPartitioner = null;
    if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
        setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    } else {
        setupPartitioner = document.getDocumentPartitioner();
    }
    assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
    bufferManager.disconnect(locationPath, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) 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 22 with IDocumentPartitioner

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

the class TestModelsFromFiles method doTestNotEmptyDocument.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private void doTestNotEmptyDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    String contents = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredDocument document = modelManager.createStructuredDocumentFor(file);
    assertNotNull(document);
    assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
    IDocumentPartitioner setupPartitioner = null;
    if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
        setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    } else {
        setupPartitioner = document.getDocumentPartitioner();
    }
    assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
    contents = document.get();
    assertNotNull("contents were null", contents);
    assertTrue("contents were empty", contents.length() > 0);
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 23 with IDocumentPartitioner

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

the class TestModelsFromFiles method doTestCreate.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private String doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    String contents = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    // file will be null if the resource does not exist
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredModel model = modelManager.getNewModelForEdit(file, true);
    try {
        assertNotNull(model);
        IStructuredDocument document = model.getStructuredDocument();
        assertNotNull(document);
        contents = document.get();
        assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
        IDocumentPartitioner setupPartitioner = null;
        if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
            setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
        } else {
            setupPartitioner = document.getDocumentPartitioner();
        }
        assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
        testClone(model);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
    return contents;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 24 with IDocumentPartitioner

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

the class TestModelsFromFiles method doTestNonExistentDocument.

private void doTestNonExistentDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    String contents = null;
    boolean expectedExceptionCaught = false;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredDocument document = null;
    try {
        document = modelManager.createStructuredDocumentFor(file);
    } catch (FileNotFoundException e) {
        expectedExceptionCaught = true;
    }
    if (expectedExceptionCaught) {
        document = modelManager.createNewStructuredDocumentFor(file);
        assertNotNull(document);
        assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
        IDocumentPartitioner setupPartitioner = null;
        if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
            setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
        } else {
            setupPartitioner = document.getDocumentPartitioner();
        }
        assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
        contents = document.get();
        assertNotNull("contents were null", contents);
        assertTrue("contents were *not* empty as expected", contents.length() == 0);
    } else {
        assertTrue("FileNotFound exception was *not* thrown as expected", false);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) FileNotFoundException(java.io.FileNotFoundException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 25 with IDocumentPartitioner

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

the class BasicStructuredDocument method getPartition.

public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException {
    if ((0 > offset) || (offset > getLength()))
        throw new BadLocationException();
    ITypedRegion result = null;
    IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
    if (partitioner instanceof IDocumentPartitionerExtension2) {
        result = ((IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions);
    } else if (partitioner != null) {
        result = partitioner.getPartition(offset);
    } else if (IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING.equals(partitioning)) {
        result = new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE);
    } else
        throw new BadPartitioningException();
    return result;
}
Also used : BadPartitioningException(org.eclipse.jface.text.BadPartitioningException) IDocumentPartitionerExtension2(org.eclipse.jface.text.IDocumentPartitionerExtension2) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITypedRegion(org.eclipse.jface.text.ITypedRegion) TypedRegion(org.eclipse.jface.text.TypedRegion) ITypedRegion(org.eclipse.jface.text.ITypedRegion) 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