Search in sources :

Example 41 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project cubrid-manager by CUBRID.

the class PropDocumentProvider method getDocument.

/**
	 * Retrieves the document to be edited.
	 * 
	 * @param element Object
	 * @return IDocument
	 */
public IDocument getDocument(Object element) {
    IDocument document = null;
    if (element instanceof IEditorInput) {
        IEditorInput ei = ((IEditorInput) element);
        DocumentProvider dp = (DocumentProvider) ei.getAdapter(DocumentProvider.class);
        if (dp != null) {
            document = dp.getDocument(element);
        }
    }
    if (document == null) {
        document = new Document();
    }
    IDocumentPartitioner partitioner = new FastPartitioner(new PropPartitionScanner(), PropPartitionScanner.LEGAL_CONTENT_TYPES);
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
    return document;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) DocumentProvider(com.cubrid.tool.editor.DocumentProvider) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 42 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project cubrid-manager by CUBRID.

the class XMLDocumentProvider method getDocument.

/**
	 * Retrieves the document to be edited.
	 * 
	 * @param element Object
	 * @return IDocument
	 */
public IDocument getDocument(Object element) {
    IDocument document = null;
    if (element instanceof IEditorInput) {
        IEditorInput ei = ((IEditorInput) element);
        DocumentProvider dp = (DocumentProvider) ei.getAdapter(DocumentProvider.class);
        if (dp != null) {
            document = dp.getDocument(element);
        }
    }
    if (document == null) {
        document = new Document();
    }
    IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
    return document;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) DocumentProvider(com.cubrid.tool.editor.DocumentProvider) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) XMLPartitionScanner(com.cubrid.tool.editor.xml.scanner.XMLPartitionScanner) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 43 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project eclipse.platform.text by eclipse.

the class XMLDocumentProvider method createDocument.

@Override
protected IDocument createDocument(Object element) throws CoreException {
    IDocument document = super.createDocument(element);
    if (document != null) {
        IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
        partitioner.connect(document);
        document.setDocumentPartitioner(partitioner);
    }
    return document;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IDocument(org.eclipse.jface.text.IDocument)

Example 44 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project eclipse.platform.text by eclipse.

the class MultiPassContentFormatter method formatSlaves.

/**
 * Formats the document specified in the formatting context with the slave
 * formatting strategies.
 * <p>
 * For each content type of the region to be formatted in the document
 * partitioning, the registered slave formatting strategy is used to format
 * that particular region. The region to be formatted is aligned on
 * partition boundaries of the underlying content type. If the content type
 * is the document's default content type, nothing happens.
 *
 * @param context The formatting context to use
 * @param document The document to operate on
 * @param offset The offset of the region to format
 * @param length The length of the region to format
 */
protected void formatSlaves(final IFormattingContext context, final IDocument document, final int offset, final int length) {
    Map<String, IDocumentPartitioner> partitioners = new HashMap<>(0);
    try {
        final ITypedRegion[] partitions = TextUtilities.computePartitioning(document, fPartitioning, offset, length, false);
        if (!fType.equals(partitions[0].getType()))
            partitions[0] = TextUtilities.getPartition(document, fPartitioning, partitions[0].getOffset(), false);
        if (partitions.length > 1) {
            if (!fType.equals(partitions[partitions.length - 1].getType()))
                partitions[partitions.length - 1] = TextUtilities.getPartition(document, fPartitioning, partitions[partitions.length - 1].getOffset(), false);
        }
        String type = null;
        ITypedRegion partition = null;
        partitioners = TextUtilities.removeDocumentPartitioners(document);
        for (int index = partitions.length - 1; index >= 0; index--) {
            partition = partitions[index];
            type = partition.getType();
            if (!fType.equals(type))
                formatSlave(context, document, partition.getOffset(), partition.getLength(), type);
        }
    } catch (BadLocationException exception) {
    // Should not happen
    } finally {
        TextUtilities.addDocumentPartitioners(document, partitioners);
    }
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) HashMap(java.util.HashMap) ITypedRegion(org.eclipse.jface.text.ITypedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 45 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project eclipse.platform.text by eclipse.

the class TextFileBufferOperation method run.

@Override
public void run(IFileBuffer fileBuffer, IProgressMonitor progressMonitor) throws CoreException, OperationCanceledException {
    if (fileBuffer instanceof ITextFileBuffer) {
        ITextFileBuffer textFileBuffer = (ITextFileBuffer) fileBuffer;
        IPath path = textFileBuffer.getLocation();
        String taskName = path == null ? getOperationName() : path.lastSegment();
        SubMonitor subMonitor = SubMonitor.convert(progressMonitor, taskName, 100);
        MultiTextEditWithProgress edit = computeTextEdit(textFileBuffer, subMonitor.split(10));
        if (edit != null) {
            Map<String, IDocumentPartitioner> stateData = startRewriteSession(textFileBuffer);
            try {
                applyTextEdit(textFileBuffer, edit, subMonitor.split(90));
            } finally {
                stopRewriteSession(textFileBuffer, stateData);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) SubMonitor(org.eclipse.core.runtime.SubMonitor)

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