Search in sources :

Example 6 with XMLMultiPageEditorPart

use of org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart 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)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)6 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)6 XMLMultiPageEditorPart (org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart)6 IEditorPart (org.eclipse.ui.IEditorPart)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 SapphireEditorForXml (org.eclipse.sapphire.ui.swt.xml.editor.SapphireEditorForXml)1 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)1