Search in sources :

Example 31 with StructuredTextEditor

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

the class CommonMultiPageEditor method createSourcePage.

protected void createSourcePage() {
    structuredTextEditor = new StructuredTextEditor();
    try {
        int index = addPage(structuredTextEditor, getEditorInput());
        setPageText(index, Messages._UI_LABEL_SOURCE);
        structuredTextEditor.update();
        structuredTextEditor.setEditorPart(this);
        structuredTextEditor.addPropertyListener(this);
        firePropertyChange(PROP_TITLE);
    } catch (PartInitException e) {
        // $NON-NLS-1$
        ErrorDialog.openError(getSite().getShell(), "Error creating nested text editor", null, e.getStatus());
    }
}
Also used : PartInitException(org.eclipse.ui.PartInitException) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) Point(org.eclipse.draw2d.geometry.Point)

Example 32 with StructuredTextEditor

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

the class TestReconcilerXML method setUp.

protected void setUp() throws Exception {
    // only create project and file once
    if (!fIsSetup) {
        // create project
        createProject(PROJECT_NAME);
        fFile = getOrCreateFile(PROJECT_NAME + "/" + FILE_NAME);
        fIsSetup = true;
    }
    // editor is opened each time
    if (fIsSetup && fEditor == null) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        fEditor = IDE.openEditor(page, fFile, true, true);
        if (!((fEditor instanceof XMLMultiPageEditorPart) || (fEditor instanceof StructuredTextEditor)))
            assertTrue("Unable to open structured text editor", false);
    }
    // turn on reconciling
    IPreferenceStore store = SSEUIPlugin.getDefault().getPreferenceStore();
    fReconcilerPref = store.getBoolean(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS);
    if (!fReconcilerPref)
        store.setValue(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS, true);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XMLMultiPageEditorPart(org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 33 with StructuredTextEditor

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

the class XMLCodeFoldingTest method testComments.

/**
 * <p><b>TEST:</b> test the folding of comments</p>
 */
public void testComments() throws Exception {
    IFile file = getFile("XMLFoldingCommentTest.xml");
    StructuredTextEditor editor = getEditor(file);
    List expectedPositions = new ArrayList();
    expectedPositions.add(new Position(275, 36));
    expectedPositions.add(new Position(124, 49));
    expectedPositions.add(new Position(179, 81));
    expectedPositions.add(new Position(39, 281));
    expectedPositions.add(new Position(191, 56));
    expectedPositions.add(new Position(64, 31));
    expectedPositions.add(new Position(99, 172));
    expectedPositions.add(new Position(47, 13));
    expectedPositions.add(new Position(108, 13));
    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 34 with StructuredTextEditor

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

the class XMLCodeFoldingTest 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 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: " + editorPart.getClass().getName());
            }
            standardizeLineEndings(editor);
            if (editor != null) {
                fFileToEditorMap.put(file, editor);
            } else {
                fail("Could not open viewer 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) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 35 with StructuredTextEditor

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

the class XMLCodeFoldingTest method testRemoveNode.

/**
 * <p><b>TEST:</b> that folding annotations are updated after node is removed</p>
 */
public void testRemoveNode() throws Exception {
    IFile file = getFile("XMLFoldingTest1.xml");
    StructuredTextEditor editor = getEditor(file);
    try {
        StructuredTextViewer viewer = editor.getTextViewer();
        IDocument doc = viewer.getDocument();
        doc.replace(87, 49, "");
        editor.doSave(null);
        final List expectedPositions = new ArrayList();
        expectedPositions.add(new Position(93, 16));
        expectedPositions.add(new Position(124, 36));
        expectedPositions.add(new Position(39, 130));
        expectedPositions.add(new Position(71, 13));
        expectedPositions.add(new Position(62, 58));
        expectedPositions.add(new Position(47, 13));
        waitForReconcileThenVerify(viewer, expectedPositions);
    } catch (BadLocationException e) {
        fail("Test is broken, replace location has become invalid.\n" + e.getMessage());
    }
}
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) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

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