Search in sources :

Example 1 with LineStyleProvider

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

the class StructuredTextViewer method configure.

/**
 * Should be identical to superclass version. Plus, we get our own special
 * Highlighter. Plus we uninstall before installing.
 */
public void configure(SourceViewerConfiguration configuration) {
    if (getTextWidget() == null)
        return;
    setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this));
    // always uninstall highlighter and null it out on new configuration
    if (fHighlighter != null) {
        fHighlighter.uninstall();
        fHighlighter = null;
    }
    if (fRecHighlighter != null) {
        fRecHighlighter.uninstall();
        fRecHighlighter = null;
    }
    // Bug 230297 - Uninstall presentation reconciler in preparation of a new one
    if (fPresentationReconciler != null) {
        fPresentationReconciler.uninstall();
        fPresentationReconciler = null;
    }
    IReconciler newReconciler = configuration.getReconciler(this);
    if (newReconciler != fReconciler || newReconciler == null || fReconciler == null) {
        if (fReconciler != null) {
            fReconciler.uninstall();
        }
        fReconciler = newReconciler;
        if (fReconciler != null) {
            fReconciler.install(this);
            // still need set document on the reconciler (strategies)
            if (fReconciler instanceof StructuredRegionProcessor)
                ((StructuredRegionProcessor) fReconciler).setDocument(getDocument());
        }
    }
    IContentAssistant newAssistant = configuration.getContentAssistant(this);
    if (newAssistant != fContentAssistant || newAssistant == null || fContentAssistant == null) {
        if (fContentAssistant != null)
            fContentAssistant.uninstall();
        fContentAssistant = newAssistant;
        if (fContentAssistant != null) {
            fContentAssistant.install(this);
            if (fContentAssistant instanceof IContentAssistantExtension2 && fContentAssistant instanceof IContentAssistantExtension4)
                fContentAssistantFacade = new ContentAssistantFacade(fContentAssistant);
            fContentAssistantInstalled = true;
        } else {
            // 248036
            // disable the content assist operation if no content
            // assistant
            enableOperation(CONTENTASSIST_PROPOSALS, false);
            fContentAssistantInstalled = false;
        }
    }
    IQuickAssistAssistant quickAssistant = configuration.getQuickAssistAssistant(this);
    if (quickAssistant != fQuickAssistAssistant || quickAssistant == null || fQuickAssistAssistant == null) {
        if (fQuickAssistAssistant != null)
            fQuickAssistAssistant.uninstall();
        fQuickAssistAssistant = quickAssistant;
        if (fQuickAssistAssistant != null) {
            fQuickAssistAssistant.install(this);
            fQuickAssistAssistantInstalled = true;
        } else {
            // 248036
            // disable the content assist operation if no content
            // assistant
            enableOperation(QUICK_ASSIST, false);
            fQuickAssistAssistantInstalled = false;
        }
    }
    fContentFormatter = configuration.getContentFormatter(this);
    // do not uninstall old information presenter if it's the same
    IInformationPresenter newInformationPresenter = configuration.getInformationPresenter(this);
    if (newInformationPresenter == null || fInformationPresenter == null || !(newInformationPresenter.equals(fInformationPresenter))) {
        if (fInformationPresenter != null)
            fInformationPresenter.uninstall();
        fInformationPresenter = newInformationPresenter;
        if (fInformationPresenter != null)
            fInformationPresenter.install(this);
    }
    // disconnect from the old undo manager before setting the new one
    if (fUndoManager != null) {
        fUndoManager.disconnect();
    }
    setUndoManager(configuration.getUndoManager(this));
    // release old annotation hover before setting new one
    if (fAnnotationHover instanceof StructuredTextAnnotationHover) {
        ((StructuredTextAnnotationHover) fAnnotationHover).release();
    }
    setAnnotationHover(configuration.getAnnotationHover(this));
    // release old annotation hover before setting new one
    if (fOverviewRulerAnnotationHover instanceof StructuredTextAnnotationHover) {
        ((StructuredTextAnnotationHover) fOverviewRulerAnnotationHover).release();
    }
    setOverviewRulerAnnotationHover(configuration.getOverviewRulerAnnotationHover(this));
    getTextWidget().setTabs(configuration.getTabWidth(this));
    setHoverControlCreator(configuration.getInformationControlCreator(this));
    // if hyperlink manager has already been created, uninstall it
    if (fHyperlinkManager != null) {
        setHyperlinkDetectors(null, SWT.NONE);
    }
    setHyperlinkPresenter(configuration.getHyperlinkPresenter(this));
    IHyperlinkDetector[] hyperlinkDetectors = configuration.getHyperlinkDetectors(this);
    int eventStateMask = configuration.getHyperlinkStateMask(this);
    setHyperlinkDetectors(hyperlinkDetectors, eventStateMask);
    String[] types = configuration.getConfiguredContentTypes(this);
    // clear autoindent/autoedit strategies
    fAutoIndentStrategies = null;
    for (int i = 0; i < types.length; i++) {
        String t = types[i];
        setAutoEditStrategies(configuration.getAutoEditStrategies(this, t), t);
        setTextDoubleClickStrategy(configuration.getDoubleClickStrategy(this, t), t);
        int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(this, t);
        if (stateMasks != null) {
            for (int j = 0; j < stateMasks.length; j++) {
                int stateMask = stateMasks[j];
                setTextHover(configuration.getTextHover(this, t, stateMask), t, stateMask);
            }
        } else {
            setTextHover(configuration.getTextHover(this, t), t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
        }
        String[] prefixes = configuration.getIndentPrefixes(this, t);
        if (prefixes != null && prefixes.length > 0)
            setIndentPrefixes(prefixes, t);
        prefixes = configuration.getDefaultPrefixes(this, t);
        if (prefixes != null && prefixes.length > 0)
            setDefaultPrefixes(prefixes, t);
        // the document is set
        if (getDocument() != null) {
            // add highlighter/linestyleprovider
            LineStyleProvider[] providers = ((StructuredTextViewerConfiguration) configuration).getLineStyleProviders(this, t);
            if (providers != null) {
                for (int j = 0; j < providers.length; ++j) {
                    if (fRecHighlighter == null) {
                        fRecHighlighter = new ReconcilerHighlighter();
                        ((StructuredTextViewerConfiguration) configuration).setHighlighter(fRecHighlighter);
                    }
                    if (providers[j] instanceof AbstractLineStyleProvider) {
                        ((AbstractLineStyleProvider) providers[j]).init((IStructuredDocument) getDocument(), 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((IStructuredDocument) getDocument(), fHighlighter);
                        fHighlighter.addProvider(t, providers[j]);
                    }
                }
            }
        }
    }
    // initialize highlighter after linestyleproviders were added
    if (fHighlighter != null) {
        fHighlighter.setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this));
        fHighlighter.setDocument((IStructuredDocument) getDocument());
        fHighlighter.install(this);
    }
    if (fRecHighlighter != null)
        fRecHighlighter.install(this);
    activatePlugins();
    fConfiguration = configuration;
    // Update the viewer's presentation reconciler
    fPresentationReconciler = configuration.getPresentationReconciler(this);
    if (fPresentationReconciler != null)
        fPresentationReconciler.install(this);
}
Also used : ReconcilerHighlighter(org.eclipse.wst.sse.ui.internal.provisional.style.ReconcilerHighlighter) StructuredRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) CompatibleHighlighter(org.eclipse.wst.sse.ui.internal.provisional.style.CompatibleHighlighter) AbstractLineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider) Point(org.eclipse.swt.graphics.Point) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) AbstractLineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider) IContentAssistantExtension2(org.eclipse.jface.text.contentassist.IContentAssistantExtension2) IContentAssistantExtension4(org.eclipse.jface.text.contentassist.IContentAssistantExtension4) IInformationPresenter(org.eclipse.jface.text.information.IInformationPresenter) ContentAssistantFacade(org.eclipse.jface.text.source.ContentAssistantFacade) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) IQuickAssistAssistant(org.eclipse.jface.text.quickassist.IQuickAssistAssistant)

Example 2 with LineStyleProvider

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

the class StructuredTextViewerConfiguration method getPresentationReconciler.

/**
 * See <code>getLineStyleProviders(ISourceViewer, String)</code> for
 * alternative way to provide highlighting information.
 *
 * @param sourceViewer
 *            the source viewer to be configured by this configuration
 * @return always returns null
 * @see #getLineStyleProviders(ISourceViewer, String)
 */
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    StructuredPresentationReconciler reconciler = new StructuredPresentationReconciler();
    reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
    String[] contentTypes = getConfiguredContentTypes(sourceViewer);
    if (contentTypes != null) {
        StructuredDocumentDamagerRepairer dr = null;
        for (int i = 0; i < contentTypes.length; i++) {
            if (fHighlighter != null) {
                LineStyleProvider provider = fHighlighter.getProvider(contentTypes[i]);
                if (provider == null)
                    continue;
                dr = new StructuredDocumentDamagerRepairer(provider);
                dr.setDocument(sourceViewer.getDocument());
                reconciler.setDamager(dr, contentTypes[i]);
                reconciler.setRepairer(dr, contentTypes[i]);
            }
        }
    }
    return reconciler;
}
Also used : StructuredPresentationReconciler(org.eclipse.wst.sse.ui.internal.provisional.style.StructuredPresentationReconciler) StructuredDocumentDamagerRepairer(org.eclipse.wst.sse.ui.internal.rules.StructuredDocumentDamagerRepairer) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)

Example 3 with LineStyleProvider

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

the class NewHTMLTemplatesWizardPage 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 StructuredTextViewerConfigurationHTML();

        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(ContentTypeIdForHTML.ContentTypeID_HTML);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) 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 4 with LineStyleProvider

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

the class NewTagTemplatesWizardPage 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_JSPTAG);
    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 5 with LineStyleProvider

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

the class ResultView method createViewer.

private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXSL();

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

        @Override
        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$
    ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    viewer.configure(sourceViewerConfiguration);
    viewer.setEditable(false);
    return viewer;
}
Also used : 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) StructuredTextViewerConfigurationXSL(org.eclipse.wst.xsl.ui.internal.StructuredTextViewerConfigurationXSL) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

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