Search in sources :

Example 11 with LineStyleProvider

use of org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider in project webtools.sourceediting by eclipse.

the class NewJSPTemplatesWizardPage method createViewer.

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 *
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationJSP();

        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    // $NON-NLS-1$
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 12 with LineStyleProvider

use of org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider in project webtools.sourceediting by eclipse.

the class StructuredTextViewer method updateHighlighter.

private void updateHighlighter(IStructuredDocument document) {
    boolean documentSet = false;
    // if highlighter has not been created yet, initialize and install it
    if (fRecHighlighter == null && fConfiguration instanceof StructuredTextViewerConfiguration) {
        String[] types = fConfiguration.getConfiguredContentTypes(this);
        for (int i = 0; i < types.length; i++) {
            String t = types[i];
            // add highlighter/linestyleprovider
            LineStyleProvider[] providers = ((StructuredTextViewerConfiguration) fConfiguration).getLineStyleProviders(this, t);
            if (providers != null) {
                for (int j = 0; j < providers.length; ++j) {
                    if (fRecHighlighter == null) {
                        fRecHighlighter = new ReconcilerHighlighter();
                        ((StructuredTextViewerConfiguration) fConfiguration).setHighlighter(fRecHighlighter);
                    }
                    if (providers[j] instanceof AbstractLineStyleProvider) {
                        ((AbstractLineStyleProvider) providers[j]).init(document, fRecHighlighter);
                        fRecHighlighter.addProvider(t, providers[j]);
                    } else {
                        // init with compatibility instance
                        if (fHighlighter == null) {
                            fHighlighter = new CompatibleHighlighter();
                        }
                        // $NON-NLS-1$
                        Logger.log(Logger.INFO_DEBUG, "CompatibleHighlighter installing compatibility for " + providers[j].getClass());
                        providers[j].init(document, fHighlighter);
                        fHighlighter.addProvider(t, providers[j]);
                    }
                }
            }
        }
        if (fRecHighlighter != null)
            fRecHighlighter.install(this);
        if (fHighlighter != null) {
            fHighlighter.setDocumentPartitioning(fConfiguration.getConfiguredDocumentPartitioning(this));
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=203347
            // make sure to set document before install
            fHighlighter.setDocument(document);
            fHighlighter.install(this);
            documentSet = true;
        }
    }
    if (fHighlighter != null && !documentSet)
        fHighlighter.setDocument(document);
    // install content type independent plugins
    if (fPresentationReconciler != null)
        fPresentationReconciler.uninstall();
    // 228847 - XSL Content Assist tests fail with Null Pointer on Highlighter
    if (fConfiguration != null)
        fPresentationReconciler = fConfiguration.getPresentationReconciler(this);
    if (fPresentationReconciler != null)
        fPresentationReconciler.install(this);
}
Also used : ReconcilerHighlighter(org.eclipse.wst.sse.ui.internal.provisional.style.ReconcilerHighlighter) CompatibleHighlighter(org.eclipse.wst.sse.ui.internal.provisional.style.CompatibleHighlighter) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) AbstractLineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) AbstractLineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider) Point(org.eclipse.swt.graphics.Point)

Example 13 with LineStyleProvider

use of org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider in project webtools.sourceediting by eclipse.

the class TestXSLLineStyleProvider method initializeProvider.

private LineStyleProvider initializeProvider() {
    LineStyleProvider[] lineStyleProviders = getLineStyleProviders();
    LineStyleProvider lineStyleProvider = lineStyleProviders[0];
    Highlighter highlighter = new Highlighter();
    lineStyleProvider.init(document, highlighter);
    return lineStyleProvider;
}
Also used : LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) Highlighter(org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter)

Aggregations

LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)13 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)10 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)8 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)8 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)8 IDocument (org.eclipse.jface.text.IDocument)7 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)7 StructuredTextViewerConfigurationJSP (org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP)2 Point (org.eclipse.swt.graphics.Point)2 AbstractLineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider)2 CompatibleHighlighter (org.eclipse.wst.sse.ui.internal.provisional.style.CompatibleHighlighter)2 ReconcilerHighlighter (org.eclipse.wst.sse.ui.internal.provisional.style.ReconcilerHighlighter)2 StructuredTextViewerConfigurationXSL (org.eclipse.wst.xsl.ui.internal.StructuredTextViewerConfigurationXSL)2 ArrayList (java.util.ArrayList)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)1 IContentAssistantExtension2 (org.eclipse.jface.text.contentassist.IContentAssistantExtension2)1 IContentAssistantExtension4 (org.eclipse.jface.text.contentassist.IContentAssistantExtension4)1 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)1