Search in sources :

Example 41 with StructuredTextEditor

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

the class ExtendedEditorDropTargetAdapter method drop.

/**
 */
public void drop(DropTargetEvent event) {
    if (event.operations == DND.DROP_NONE)
        return;
    Transfer[] ts = getTransfers();
    for (int i = 0; i < ts.length; i++) {
        if (ts[i].isSupportedType(event.currentDataType)) {
            if (doDrop(ts[i], event)) {
                IEditorPart part = targetEditor;
                if (targetEditor instanceof StructuredTextEditor) {
                    part = ((StructuredTextEditor) targetEditor).getEditorPart();
                }
                targetEditor.getSite().getPage().activate(part);
                break;
            }
        }
    }
}
Also used : FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) Point(org.eclipse.swt.graphics.Point)

Example 42 with StructuredTextEditor

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

the class CSSCodeFoldingTest 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>
 *
 * @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, "org.eclipse.wst.css.core.csssource.source", true);
            if (editorPart instanceof StructuredTextEditor) {
                editor = ((StructuredTextEditor) editorPart);
                standardizeLineEndings(editor);
            } else {
                fail("Unable to open structured text editor: " + editorPart.getClass().getName());
            }
            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) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 43 with StructuredTextEditor

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

the class TestHTMLContentAssistComputers 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, "org.eclipse.wst.html.core.htmlsource.source", true);
            if (editorPart instanceof MultiPageEditorPart) {
                MultiPageEditorPart mpEditorPart = (MultiPageEditorPart) editorPart;
                editor = mpEditorPart.getAdapter(StructuredTextEditor.class);
            } else if (editorPart instanceof StructuredTextEditor) {
                editor = ((StructuredTextEditor) editorPart);
            } else {
                fail("Unable to open structured text editor: " + editorPart.getClass().getName());
            }
            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) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 44 with StructuredTextEditor

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

the class ContentAssistTestUtilities method getProposals.

/**
 * <p>
 * Invoke content assist on the given editor at the given offset, for the given number of pages
 * and return the results of each page
 * </p>
 */
private static ICompletionProposal[][] getProposals(AbstractTextEditor editor, int offset, int pageCount) throws Exception {
    ICompletionProposal[][] pages = null;
    /* if JS editor
		 * else if HTML editor */
    if (editor instanceof JavaEditor) {
        // setup the viewer
        ISourceViewer viewer = ((JavaEditor) editor).getViewer();
        JavaScriptSourceViewerConfiguration configuration = new JavaScriptSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), JavaScriptPlugin.getDefault().getCombinedPreferenceStore(), editor, IJavaScriptPartitions.JAVA_PARTITIONING);
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        // 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
        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);
    } else if (editor instanceof StructuredTextEditor) {
        // setup the viewer
        StructuredTextViewer viewer = ((StructuredTextEditor) editor).getTextViewer();
        StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML();
        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
        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 : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) Method(java.lang.reflect.Method) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JavaEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JavaScriptSourceViewerConfiguration(org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 45 with StructuredTextEditor

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

the class ContentAssistTestUtilities method getHTMLProposals.

/**
 * <p>
 * Returns the content assist proposals when invoked at the offset provided.
 * </p>
 *
 * @param fileNum
 * @param lineNum
 * @param lineRelativeCharOffset
 * @param numOfPages
 */
private static ICompletionProposal[][] getHTMLProposals(TestProjectSetup testProject, String filePath, int lineNum, int lineRelativeCharOffset, int numOfPages) throws Exception {
    IFile file = testProject.getFile(filePath);
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();
    IEditorPart part = IDE.openEditor(page, file, "org.eclipse.wst.html.core.htmlsource.source");
    StructuredTextEditor editor = (StructuredTextEditor) part.getAdapter(ITextEditor.class);
    IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    int offset = doc.getLineOffset(lineNum) + lineRelativeCharOffset;
    ICompletionProposal[][] pages = getHTMLProposals(editor, offset, numOfPages);
    return pages;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument)

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