Search in sources :

Example 6 with StructuredTextViewerConfigurationHTML

use of org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML in project webtools.sourceediting by eclipse.

the class ViewerTestHTML method setupViewerForEditor.

/**
 * Sets up the viewer with the same document/input as the given editor
 *
 * @param ITextEditor
 *            editor - the editor to use *cannot to be null*
 */
void setupViewerForEditor(ITextEditor editor) {
    // if was following selection, stop
    stopFollowSelection();
    IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    fSourceViewer.setDocument(doc);
    // need to reconfigure after set document just so highlighter works
    fSourceViewer.configure(new StructuredTextViewerConfigurationHTML());
}
Also used : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IDocument(org.eclipse.jface.text.IDocument)

Example 7 with StructuredTextViewerConfigurationHTML

use of org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML in project webtools.sourceediting by eclipse.

the class ContentAssistTestUtilities method getProposals.

/**
 * <p>
 * Invoke content assist on the given editor at the given offset, for the given number of pages
 * and return the results of each page
 * </p>
 */
private static ICompletionProposal[][] getProposals(AbstractTextEditor editor, int offset, int pageCount) throws Exception {
    ICompletionProposal[][] pages = null;
    /* if JS editor
		 * else if HTML editor */
    if (editor instanceof JavaEditor) {
        // setup the viewer
        ISourceViewer viewer = ((JavaEditor) editor).getViewer();
        JavaScriptSourceViewerConfiguration configuration = new JavaScriptSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), JavaScriptPlugin.getDefault().getCombinedPreferenceStore(), editor, IJavaScriptPartitions.JAVA_PARTITIONING);
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        // get the processor
        String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
        // fire content assist session about to start
        Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
        privateFireSessionBeginEventMethod.setAccessible(true);
        privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
        // get content assist suggestions
        pages = new ICompletionProposal[pageCount][];
        for (int p = 0; p < pageCount; ++p) {
            pages[p] = processor.computeCompletionProposals(viewer, offset);
        }
        // fire content assist session ending
        Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
        privateFireSessionEndEventMethod.setAccessible(true);
        privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    } else if (editor instanceof StructuredTextEditor) {
        // setup the viewer
        StructuredTextViewer viewer = ((StructuredTextEditor) editor).getTextViewer();
        StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML();
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        viewer.configure(configuration);
        viewer.setSelectedRange(offset, 0);
        // get the processor
        String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
        // fire content assist session about to start
        Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
        privateFireSessionBeginEventMethod.setAccessible(true);
        privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
        // get content assist suggestions
        pages = new ICompletionProposal[pageCount][];
        for (int p = 0; p < pageCount; ++p) {
            pages[p] = processor.computeCompletionProposals(viewer, offset);
        }
        // fire content assist session ending
        Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
        privateFireSessionEndEventMethod.setAccessible(true);
        privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    }
    return pages;
}
Also used : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) Method(java.lang.reflect.Method) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JavaEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JavaScriptSourceViewerConfiguration(org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 8 with StructuredTextViewerConfigurationHTML

use of org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML in project webtools.sourceediting by eclipse.

the class TestEmbededCSSContentAssistComputers method getProposals.

/**
 * <p>Invoke content assist on the given viewer at the given offset, for the given number of pages
 * and return the results of each page</p>
 *
 * @param viewer
 * @param offset
 * @param pageCount
 * @return
 * @throws Exception
 */
private static ICompletionProposal[][] getProposals(StructuredTextViewer viewer, int offset, int pageCount) throws Exception {
    // setup the viewer
    StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML();
    ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
    viewer.configure(configuration);
    viewer.setSelectedRange(offset, 0);
    // get the processor
    String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
    IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
    // fire content assist session about to start
    Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
    privateFireSessionBeginEventMethod.setAccessible(true);
    privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
    // get content assist suggestions
    ICompletionProposal[][] pages = new ICompletionProposal[pageCount][];
    for (int p = 0; p < pageCount; ++p) {
        pages[p] = processor.computeCompletionProposals(viewer, offset);
    }
    // fire content assist session ending
    Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
    privateFireSessionEndEventMethod.setAccessible(true);
    privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    return pages;
}
Also used : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Method(java.lang.reflect.Method) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant)

Aggregations

StructuredTextViewerConfigurationHTML (org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML)8 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)4 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)4 Method (java.lang.reflect.Method)3 ContentAssistant (org.eclipse.jface.text.contentassist.ContentAssistant)3 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 IDocument (org.eclipse.jface.text.IDocument)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 IContributionManager (org.eclipse.jface.action.IContributionManager)1 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)1 SourceViewer (org.eclipse.jface.text.source.SourceViewer)1 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1 CSSContentAssistProcessor (org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor)1 JavaEditor (org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor)1 JavaScriptSourceViewerConfiguration (org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)1 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)1