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;
}
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;
}
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;
}
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);
}
}
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);
}
}
}
}
Aggregations