Search in sources :

Example 11 with StructuredTextViewerConfiguration

use of org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration 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 StructuredTextViewerConfiguration

use of org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration 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)

Aggregations

StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)12 LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)10 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)9 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)9 SourceViewer (org.eclipse.jface.text.source.SourceViewer)8 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)8 IDocument (org.eclipse.jface.text.IDocument)7 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)7 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)2 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 Method (java.lang.reflect.Method)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)1 IContentAssistantExtension2 (org.eclipse.jface.text.contentassist.IContentAssistantExtension2)1 IContentAssistantExtension4 (org.eclipse.jface.text.contentassist.IContentAssistantExtension4)1