Search in sources :

Example 51 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class DocumentSetupParticipant method setup.

@Override
public void setup(final IDocument document) {
    if (document instanceof IDocumentExtension3) {
        final IDocumentExtension3 extension3 = (IDocumentExtension3) document;
        final IDocumentPartitioner partitioner = new FastPartitioner(Activator.getDefault().getTestFilePartitionScanner(), TestFile.PARTITION_TYPES);
        extension3.setDocumentPartitioner("__rts_partitioning", partitioner);
        partitioner.connect(document);
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner)

Example 52 with IDocumentPartitioner

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

the class TestModelsFromFiles method doTestReload.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private void doTestReload(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IFile file = (IFile) fTestProject.findMember(filePath);
    if (file == null) {
        file = fTestProject.getFile(filePath);
    }
    IStructuredModel model = modelManager.getNewModelForEdit(file, true);
    try {
        assertNotNull(model);
        IStructuredDocument document = model.getStructuredDocument();
        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));
        InputStream inStream = null;
        try {
            inStream = file.getContents();
            model.reload(inStream);
            assertNotNull(model);
            IStructuredDocument documentReloaded = model.getStructuredDocument();
            // note: NOT same instance of document
            // FIXME: this test has to be changed back, once the reload
            // API is
            // fixed to work with different document.
            // assertFalse(document == documentReloaded);
            assertTrue(document == documentReloaded);
        } finally {
            if (inStream != null) {
                inStream.close();
            }
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) InputStream(java.io.InputStream) 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 53 with IDocumentPartitioner

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

the class TestModelsFromFiles method doTestCreateModelWithNonExistIFile.

/**
 * @param string
 * @param class1
 * @param class2
 * @throws CoreException
 * @throws IOException
 * @throws ResourceInUse
 * @throws ResourceAlreadyExists
 */
private String doTestCreateModelWithNonExistIFile(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, false);
    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));
    } 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 54 with IDocumentPartitioner

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

the class TestStructuredPartitionerHTML method testGetDefaultPartitionType.

public void testGetDefaultPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            String defaultPartitionType = stp.getDefaultPartitionType();
            assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Example 55 with IDocumentPartitioner

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

the class AbstractDocumentLoader method createNewStructuredDocument.

/**
 * This method must return a new instance of IEncodedDocument, that has
 * been initialized with appropriate parser. For many loaders, the
 * (default) parser used is known for any input. For others, the correct
 * parser (and its initialization) is normally dependent on the content of
 * the file. This no-argument method should assume "empty input" and would
 * therefore return the default parser for the default contentType.
 */
public IEncodedDocument createNewStructuredDocument() {
    IEncodedDocument structuredDocument = newEncodedDocument();
    // Make sure every structuredDocument has an Encoding Memento,
    // which is the default one for "empty" structuredDocuments
    String charset = ContentTypeEncodingPreferences.useDefaultNameRules(getDocumentEncodingDetector());
    String specDefaultCharset = getDocumentEncodingDetector().getSpecDefaultEncoding();
    structuredDocument.setEncodingMemento(CodedIO.createEncodingMemento(charset, EncodingMemento.DEFAULTS_ASSUMED_FOR_EMPTY_INPUT, specDefaultCharset));
    String lineDelimiter = getPreferredNewLineDelimiter(null);
    if (lineDelimiter != null)
        structuredDocument.setPreferredLineDelimiter(lineDelimiter);
    IDocumentPartitioner defaultPartitioner = getDefaultDocumentPartitioner();
    if (structuredDocument instanceof IDocumentExtension3) {
        ((IDocumentExtension3) structuredDocument).setDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, defaultPartitioner);
    } else {
        structuredDocument.setDocumentPartitioner(defaultPartitioner);
    }
    defaultPartitioner.connect(structuredDocument);
    return structuredDocument;
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

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