Search in sources :

Example 1 with StructuredTextViewerConfigurationJSP

use of org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP in project webtools.sourceediting by eclipse.

the class TestJSPContentAssistComputers 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
    StructuredTextViewerConfigurationJSP configuration = new StructuredTextViewerConfigurationJSP();
    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 : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) 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)

Example 2 with StructuredTextViewerConfigurationJSP

use of org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP 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 3 with StructuredTextViewerConfigurationJSP

use of org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP in project webtools.sourceediting by eclipse.

the class TestContentFormatter method formatAndAssertEquals.

private void formatAndAssertEquals(String beforePath, String afterPath, boolean resetPreferences) throws UnsupportedEncodingException, IOException, CoreException {
    IStructuredModel beforeModel = null, afterModel = null;
    try {
        beforeModel = getModelForEdit(beforePath);
        assertNotNull("could not retrieve structured model for : " + beforePath, beforeModel);
        afterModel = getModelForEdit(afterPath);
        assertNotNull("could not retrieve structured model for : " + afterPath, afterModel);
        if (resetPreferences) {
            resetPreferencesToDefault();
        }
        SourceViewerConfiguration configuration = new StructuredTextViewerConfigurationJSP();
        IContentFormatterExtension formatter = (IContentFormatterExtension) configuration.getContentFormatter(null);
        IDocument document = beforeModel.getStructuredDocument();
        Region region = new Region(0, document.getLength());
        fContext.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
        formatter.format(document, fContext);
        ByteArrayOutputStream formattedBytes = new ByteArrayOutputStream();
        // "beforeModel" should now be
        beforeModel.save(formattedBytes);
        // after the formatter
        ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
        afterModel.save(afterBytes);
        String expectedContents = new String(afterBytes.toByteArray(), UTF_8);
        expectedContents = StringUtils.replace(expectedContents, "\r\n", "\r");
        expectedContents = StringUtils.replace(expectedContents, "\r", "\n");
        String actualContents = new String(formattedBytes.toByteArray(), UTF_8);
        actualContents = StringUtils.replace(actualContents, "\r\n", "\r");
        actualContents = StringUtils.replace(actualContents, "\r", "\n");
        assertTrue(onlyWhiteSpaceDiffers(expectedContents, actualContents));
        assertEquals("Formatted document differs from the expected.", expectedContents, actualContents);
    } finally {
        if (beforeModel != null)
            beforeModel.releaseFromEdit();
        if (afterModel != null)
            afterModel.releaseFromEdit();
    }
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) Region(org.eclipse.jface.text.Region) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentFormatterExtension(org.eclipse.jface.text.formatter.IContentFormatterExtension) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with StructuredTextViewerConfigurationJSP

use of org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP in project webtools.sourceediting by eclipse.

the class ViewerTestJSP 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*
 */
private 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 StructuredTextViewerConfigurationJSP());
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with StructuredTextViewerConfigurationJSP

use of org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP in project webtools.sourceediting by eclipse.

the class ViewerTestJSP method createPartControl.

/**
 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(Composite)
 */
public void createPartControl(Composite parent) {
    IContributionManager mgr = getViewSite().getActionBars().getMenuManager();
    addActions(mgr);
    // create source viewer & its content type-specific viewer
    // configuration
    fSourceViewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
    fConfig = new StructuredTextViewerConfigurationJSP();
    // set up the viewer with a document & viewer config
    setupViewerForNew();
    setupViewerPreferences();
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IContributionManager(org.eclipse.jface.action.IContributionManager)

Aggregations

StructuredTextViewerConfigurationJSP (org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP)7 IDocument (org.eclipse.jface.text.IDocument)4 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)4 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 SourceViewer (org.eclipse.jface.text.source.SourceViewer)2 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)2 LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Method (java.lang.reflect.Method)1 IContributionManager (org.eclipse.jface.action.IContributionManager)1 Region (org.eclipse.jface.text.Region)1 ContentAssistant (org.eclipse.jface.text.contentassist.ContentAssistant)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)1 IContentFormatterExtension (org.eclipse.jface.text.formatter.IContentFormatterExtension)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1