Search in sources :

Example 46 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class TestXMLContentAssistComputers method testXMLLinkedPositions.

public void testXMLLinkedPositions() throws Exception {
    IFile file = getFile("test1.xml");
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineOffset(13);
    ICompletionProposal[][] pages = getProposals(viewer, offset, 4);
    assertNotNull("No proposals returned.", pages);
    assertTrue("Not enough pages.", pages.length > 0);
    assertTrue("Not enough proposals.", pages[0].length > 0);
    ICompletionProposalExtension2 proposal = null;
    // Check for the member proposal
    for (int i = 0; i < pages[0].length; i++) {
        if ("Member".equals(pages[0][i].getDisplayString())) {
            assertTrue("Proposal not of the proper type", pages[0][i] instanceof ICompletionProposalExtension2);
            proposal = (ICompletionProposalExtension2) pages[0][i];
            break;
        }
    }
    assertNotNull("No appropriate proposal found.", proposal);
    proposal.apply(viewer, (char) 0, 0, offset);
    String[] categories = viewer.getDocument().getPositionCategories();
    String category = null;
    for (int i = 0; i < categories.length; i++) {
        if (categories[i].startsWith("org.eclipse.jface.text.link.LinkedModeModel")) {
            category = categories[i];
        }
    }
    assertNotNull("Could not find the linked model position category.", category);
    assertTrue("No linked positions were generated.", viewer.getDocument().getPositions(category).length > 0);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 47 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class TestXMLContentAssistComputers method runProposalTest.

/**
 * <p>Run a proposal test by opening the given file and invoking content assist for
 * each expected proposal count at the given line number and line character
 * offset and then compare the number of proposals for each invocation (pages) to the
 * expected number of proposals.</p>
 *
 * @param fileName
 * @param lineNum
 * @param lineRelativeCharOffset
 * @param expectedProposalCounts
 * @throws Exception
 */
private static void runProposalTest(String fileName, int lineNum, int lineRelativeCharOffset, int[] expectedProposalCounts) throws Exception {
    IFile file = getFile(fileName);
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;
    ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);
    verifyProposalCounts(pages, expectedProposalCounts);
}
Also used : IFile(org.eclipse.core.resources.IFile) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 48 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class TestViewerConfigurationXML method setUpViewerConfiguration.

private void setUpViewerConfiguration() {
    // some test environments might not have a "real" display
    if (Display.getCurrent() != null) {
        Shell shell = null;
        Composite parent = null;
        if (PlatformUI.isWorkbenchRunning()) {
            shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        } else {
            shell = new Shell(Display.getCurrent());
        }
        parent = new Composite(shell, SWT.NONE);
        // dummy viewer
        fViewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
        fConfig = new StructuredTextViewerConfigurationXML();
    } else {
        fDisplayExists = false;
        Logger.log(Logger.INFO, "Remember, viewer configuration tests are not run because workbench is not open (normal on build machine)");
    }
}
Also used : StructuredTextViewerConfigurationXML(org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 49 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class TestStructuredTextEditor method testGetTextViewer.

public void testGetTextViewer() {
    StructuredTextViewer viewer = fEditor.getTextViewer();
    assertNotNull("Editor's text viewer was null", viewer);
}
Also used : StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 50 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project webtools.sourceediting by eclipse.

the class NewCSSTemplatesWizardPage 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 StructuredTextViewerConfigurationCSS();

        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(ContentTypeIdForCSS.ContentTypeID_CSS);
    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) 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) StructuredTextViewerConfigurationCSS(org.eclipse.wst.css.ui.StructuredTextViewerConfigurationCSS) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)62 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)21 IDocument (org.eclipse.jface.text.IDocument)19 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)18 IFile (org.eclipse.core.resources.IFile)14 SourceViewer (org.eclipse.jface.text.source.SourceViewer)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)14 Composite (org.eclipse.swt.widgets.Composite)13 Shell (org.eclipse.swt.widgets.Shell)13 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)12 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)9 LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)8 ArrayList (java.util.ArrayList)7 BadLocationException (org.eclipse.jface.text.BadLocationException)6 Position (org.eclipse.jface.text.Position)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6 List (java.util.List)5 Action (org.eclipse.jface.action.Action)4 IContributionManager (org.eclipse.jface.action.IContributionManager)4 Separator (org.eclipse.jface.action.Separator)4