Search in sources :

Example 61 with IDocumentPartitioner

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

the class StructuredTextViewerConfiguration method getContentFormatter.

/**
 * Returns the content formatter ready to be used with the given source
 * viewer.
 * <p>
 * It is not recommended that clients override this method as it may
 * become <code>final</code> in the future and replaced by an extensible
 * framework.
 * </p>
 *
 * @param sourceViewer
 *            the source viewer to be configured by this configuration
 * @return a content formatter or <code>null</code> if formatting should
 *         not be supported
 */
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
    // try to use the StructuredTextMultiPassContentFormatter so that it
    // picks up any additional formatting strategies contributed via the
    // editorConfiguration extension point
    IContentFormatter formatter = null;
    if (sourceViewer != null) {
        IDocument document = sourceViewer.getDocument();
        if (document instanceof IDocumentExtension3) {
            String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) document).getDocumentPartitioner(partitioning);
            if (partitioner instanceof StructuredTextPartitioner) {
                String defaultPartitionType = ((StructuredTextPartitioner) partitioner).getDefaultPartitionType();
                formatter = new StructuredTextMultiPassContentFormatter(partitioning, defaultPartitionType);
            }
        }
    }
    return formatter;
}
Also used : IContentFormatter(org.eclipse.jface.text.formatter.IContentFormatter) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IDocument(org.eclipse.jface.text.IDocument) StructuredTextPartitioner(org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner)

Example 62 with IDocumentPartitioner

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

the class PageDirectiveAdapterImpl method setLanguage.

/**
 * This is public access method, used especially from loader, for JSP
 * Fragment support.
 */
public void setLanguage(String newLanguage) {
    this.cachedLanguage = newLanguage;
    IDocumentPartitioner partitioner = ((IDocumentExtension3) model.getStructuredDocument()).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    if (partitioner instanceof StructuredTextPartitionerForJSP) {
        ((StructuredTextPartitionerForJSP) partitioner).setLanguage(newLanguage);
    }
}
Also used : StructuredTextPartitionerForJSP(org.eclipse.jst.jsp.core.internal.text.StructuredTextPartitionerForJSP) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner)

Example 63 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project liferay-ide by liferay.

the class LiferayPropertiesContentAssistProcessor method _getPartitioner.

@SuppressWarnings("restriction")
private IDocumentPartitioner _getPartitioner(IDocument document) {
    IDocumentPartitioner retval = null;
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 doc3 = (IDocumentExtension3) document;
        retval = doc3.getDocumentPartitioner(org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING);
    }
    return retval;
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner)

Example 64 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project liferay-ide by liferay.

the class LiferayPropertiesContentAssistProcessor method computeCompletionProposals.

public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    ICompletionProposal[] retval = null;
    String currentPartitionType = null;
    IDocument document = viewer.getDocument();
    IDocumentPartitioner partitioner = _getPartitioner(document);
    if (partitioner != null) {
        ITypedRegion p = partitioner.getPartition(offset);
        if (p != null) {
            currentPartitionType = p.getType();
        }
    }
    if ((currentPartitionType != null) && currentPartitionType.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
        // now we need to check to see if we have a partial key
        int rewindOffset = _rewindOffsetToNearestNonDefaultPartition(partitioner, offset);
        String partialKey = _getPartialKey(document, rewindOffset, offset);
        List<ICompletionProposal> proposals = new ArrayList<>();
        if (_propKeys != null) {
            for (PropKey key : _propKeys) {
                if ((partialKey != null) && key.getKey().startsWith(partialKey)) {
                    proposals.add(new PropertyCompletionProposal(key.getKey(), key.getComment(), offset, rewindOffset));
                }
            }
        }
        retval = proposals.toArray(new ICompletionProposal[0]);
    }
    return retval;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IDocument(org.eclipse.jface.text.IDocument)

Example 65 with IDocumentPartitioner

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

the class ABSDocumentProvider method createDocument.

@Override
protected IDocument createDocument(Object element) throws CoreException {
    // Avoid ResourceException if you open a file that has disappeared.
    if (isDeleted(element))
        return super.createEmptyDocument();
    IDocument document = super.createDocument(element);
    if (document == null) {
        if (element instanceof IURIEditorInput) {
            IURIEditorInput ei = (IURIEditorInput) element;
            document = createEmptyDocument();
            InputStream is = null;
            try {
                is = ei.getURI().toURL().openStream();
                setDocumentContent(document, is, getEncoding(element));
            } catch (IOException ex) {
                throw new CoreException(new Status(IStatus.ERROR, Constants.PLUGIN_ID, "ABS Editor", ex));
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException ex) {
                        throw new CoreException(new Status(IStatus.ERROR, Constants.PLUGIN_ID, "ABS Editor", ex));
                    }
                }
            }
        } else
            throw new CoreException(new Status(IStatus.ERROR, Constants.PLUGIN_ID, "Don't know how to open " + element.toString()));
    }
    ABSPartitionScanner scanner = new ABSPartitionScanner();
    IDocumentPartitioner partitioner = new FastPartitioner(scanner, PARTITION_TYPES);
    document.setDocumentPartitioner(partitioner);
    partitioner.connect(document);
    return document;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IURIEditorInput(org.eclipse.ui.IURIEditorInput) CoreException(org.eclipse.core.runtime.CoreException) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) InputStream(java.io.InputStream) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IOException(java.io.IOException) IDocument(org.eclipse.jface.text.IDocument)

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