Search in sources :

Example 51 with StructuredTextEditor

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

the class XMLCodeFoldingTest method testConfigTypeHierarchyExploration.

/**
 * <p><b>TEST:</b> that even though .xsl documents do not have a specifically specified
 * folding strategy that by the power of hierarchical content types the XML folding
 * strategy is used for the XSLT document.
 */
public void testConfigTypeHierarchyExploration() throws Exception {
    IFile file = getFile("XSLFoldingTest1.xsl");
    StructuredTextEditor editor = getEditor(file);
    List expectedPositions = new ArrayList();
    expectedPositions.add(new Position(120, 88));
    expectedPositions.add(new Position(147, 44));
    expectedPositions.add(new Position(39, 187));
    waitForReconcileThenVerify(editor.getTextViewer(), expectedPositions);
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 52 with StructuredTextEditor

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

the class TestPropertySheetConfiguration method setUp.

protected void setUp() throws Exception {
    if (!fIsSetup) {
        // create project
        createProject(PROJECT_NAME);
        fFile = getOrCreateFile(PROJECT_NAME + "/" + FILE_NAME);
        fIsSetup = true;
    }
    // editor is opened each time
    if (fIsSetup && fMainEditor == null) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        fMainEditor = IDE.openEditor(page, fFile, true, true);
        if (fMainEditor instanceof StructuredTextEditor)
            fEditor = (StructuredTextEditor) fMainEditor;
        else if (fMainEditor != null) {
            Object adapter = fMainEditor.getAdapter(ITextEditor.class);
            if (adapter instanceof StructuredTextEditor)
                fEditor = (StructuredTextEditor) adapter;
        }
        if (fEditor == null)
            assertTrue("Unable to open structured text editor " + ((fMainEditor != null) ? fMainEditor.getClass().getName() : ""), false);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 53 with StructuredTextEditor

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

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

the class TestXMLContentAssistComputers method getEditor.

/**
 * <p>Given a <code>file</code> get an editor for it. If an editor has already
 * been retrieved for the given <code>file</code> then return the same already
 * open editor.</p>
 *
 * <p>When opening the editor it will also standardized the line
 * endings to <code>\n</code></p>
 *
 * @param file open and return an editor for this
 * @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
 */
private static StructuredTextEditor getEditor(IFile file) {
    StructuredTextEditor editor = (StructuredTextEditor) fFileToEditorMap.get(file);
    if (editor == null) {
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            IWorkbenchPage page = workbenchWindow.getActivePage();
            IEditorPart editorPart = IDE.openEditor(page, file, true, true);
            if (editorPart instanceof XMLMultiPageEditorPart) {
                XMLMultiPageEditorPart xmlEditorPart = (XMLMultiPageEditorPart) editorPart;
                editor = (StructuredTextEditor) xmlEditorPart.getAdapter(StructuredTextEditor.class);
            } else if (editorPart instanceof StructuredTextEditor) {
                editor = ((StructuredTextEditor) editorPart);
            } else {
                fail("Unable to open structured text editor");
            }
            if (editor != null) {
                standardizeLineEndings(editor);
                fFileToEditorMap.put(file, editor);
            } else {
                fail("Could not open editor for " + file);
            }
        } catch (Exception e) {
            fail("Could not open editor for " + file + " exception: " + e.getMessage());
        }
    }
    return editor;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XMLMultiPageEditorPart(org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 55 with StructuredTextEditor

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

Aggregations

StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)67 IFile (org.eclipse.core.resources.IFile)29 IEditorPart (org.eclipse.ui.IEditorPart)28 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)18 IDocument (org.eclipse.jface.text.IDocument)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)15 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)12 Position (org.eclipse.jface.text.Position)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 BadLocationException (org.eclipse.jface.text.BadLocationException)9 ITextSelection (org.eclipse.jface.text.ITextSelection)6 PartInitException (org.eclipse.ui.PartInitException)6 XMLMultiPageEditorPart (org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Action (org.eclipse.jface.action.Action)4 Separator (org.eclipse.jface.action.Separator)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 IFileEditorInput (org.eclipse.ui.IFileEditorInput)3