Search in sources :

Example 36 with StructuredTextEditor

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

the class DTDCodeFoldingTest method testAddNode.

/**
 * <p><b>TEST:</b> that folding annotations are updated after node is removed</p>
 * Removed because it keeps failing during builds but running locally and smoke testing
 * presents no problems.
 */
/*public void testRemoveNode() throws Exception {
		IFile file = getFile("DTDFoldingTest1.dtd");
		
		StructuredTextEditor editor  = getEditor(file);
		
		try {
			StructuredTextViewer viewer = editor.getTextViewer();
			IDocument doc = viewer.getDocument();
			doc.replace(337, 159, "");
			editor.doSave(null);
			
			final List expectedPositions = new ArrayList();
			expectedPositions.add(new Position(1110, 28));
			expectedPositions.add(new Position(39, 296));
			expectedPositions.add(new Position(1140, 234));
			expectedPositions.add(new Position(339, 751));
			expectedPositions.add(new Position(1092, 17));
			
			waitForReconcileThenVerify(viewer, expectedPositions);
		} catch(BadLocationException e) {
			fail("Test is broken, replace location has become invalid.\n" + e.getMessage());
		}
	}*/
/**
 * <p><b>TEST:</b> that folding annotations are updated after node is added</p>
 */
public void testAddNode() throws Exception {
    IFile file = getFile("DTDFoldingTest2.dtd");
    StructuredTextEditor editor = getEditor(file);
    try {
        StructuredTextViewer viewer = editor.getTextViewer();
        IDocument doc = viewer.getDocument();
        String newNodeText = "<!ATTLIST BDO\n" + "%coreattrs;\t\t\t\t-- id, class, style, title --\n" + "lang\t%LanguageCode;\t#IMPLIED\t-- language code --\n" + "dir\t(ltr|rtl)\t#REQUIRED\t-- directionality --\n" + ">\n";
        doc.replace(597, 0, newNodeText);
        editor.doSave(null);
        List expectedPositions = new ArrayList();
        expectedPositions.add(new Position(1454, 234));
        expectedPositions.add(new Position(498, 906));
        expectedPositions.add(new Position(39, 296));
        expectedPositions.add(new Position(1406, 17));
        expectedPositions.add(new Position(337, 159));
        expectedPositions.add(new Position(1424, 28));
        waitForReconcileThenVerify(viewer, expectedPositions);
    } catch (BadLocationException e) {
        fail("Test is broken, add 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)

Example 37 with StructuredTextEditor

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

the class DTDCodeFoldingTest 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, true, true);
            if (editorPart instanceof StructuredTextEditor) {
                editor = ((StructuredTextEditor) editorPart);
                standardizeLineEndings(editor);
            } else {
                fail("Unable to open structured text 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) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 38 with StructuredTextEditor

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

the class DTDCodeFoldingTest method testInitFolding.

/**
 * <p><b>TEST:</b> the initially placed folding annotations</p>
 */
public void testInitFolding() throws Exception {
    IFile file = getFile("DTDFoldingTest1.dtd");
    StructuredTextEditor editor = getEditor(file);
    List expectedPositions = new ArrayList();
    expectedPositions.add(new Position(1299, 234));
    expectedPositions.add(new Position(39, 296));
    expectedPositions.add(new Position(498, 751));
    expectedPositions.add(new Position(1251, 17));
    expectedPositions.add(new Position(1269, 28));
    expectedPositions.add(new Position(337, 159));
    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 39 with StructuredTextEditor

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

the class XMLTableTreeActionBarContributor method getModelForEditorPart.

/**
 * @deprecated - not to be used
 */
protected IStructuredModel getModelForEditorPart(IEditorPart targetEditor) {
    IStructuredModel result = null;
    if (editorPart instanceof XMLMultiPageEditorPart) {
        StructuredTextEditor textEditor = ((XMLMultiPageEditorPart) targetEditor).getTextEditor();
        result = (textEditor != null) ? textEditor.getModel() : null;
    }
    return result;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 40 with StructuredTextEditor

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

the class XMLFindOccurencesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    boolean okay = false;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        if (document != null) {
            ITextSelection textSelection = getTextSelection(textEditor);
            FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
            if (findOccurrenceProcessor != null) {
                if (textEditor.getEditorInput() instanceof IFileEditorInput) {
                    IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
                    okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
                }
            }
        }
    }
    if (okay) {
        // clear status message
        PlatformStatusLineUtil.clearStatusLine();
    } else {
        // $NON-NLS-1$
        String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
        if (textEditor instanceof StructuredTextEditor) {
            PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) textEditor).getTextViewer(), errorMessage);
        } else {
            PlatformStatusLineUtil.displayErrorMessage(errorMessage);
            PlatformStatusLineUtil.addOneTimeClearListener();
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) XMLFindOccurrencesProcessor(org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

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