Search in sources :

Example 81 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class AbstractSiblingNavigationHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        ISelection selection = textEditor.getSelectionProvider().getSelection();
        if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
            Object o = ((IStructuredSelection) selection).getFirstElement();
            if (o instanceof Node) {
                Node sibling = null;
                if (((Node) o).getNodeType() == Node.ATTRIBUTE_NODE) {
                    o = ((Attr) o).getOwnerElement();
                }
                if (moveForward()) {
                    sibling = ((Node) o).getNextSibling();
                    while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) {
                        sibling = sibling.getNextSibling();
                    }
                    if (sibling == null) {
                        sibling = ((Node) o).getParentNode().getFirstChild();
                        while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) {
                            sibling = sibling.getNextSibling();
                        }
                    }
                } else {
                    sibling = ((Node) o).getPreviousSibling();
                    while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) {
                        sibling = sibling.getPreviousSibling();
                    }
                    if (sibling == null) {
                        sibling = ((Node) o).getParentNode().getLastChild();
                        while (sibling != null && sibling.getNodeType() == Node.TEXT_NODE && sibling.getNodeValue().trim().length() == 0) {
                            sibling = sibling.getPreviousSibling();
                        }
                    }
                }
                // The only child is a Text Node, go to the parent Node
                if (((Node) o).getNodeType() == Node.TEXT_NODE && o.equals(sibling)) {
                    sibling = ((Node) o).getParentNode();
                }
                if (sibling != null) {
                    textEditor.getSelectionProvider().setSelection(new StructuredSelection(sibling));
                }
            }
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Node(org.w3c.dom.Node) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 82 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class SourceEditorActionBarContributor method setActivePage.

public void setActivePage(IEditorPart activeEditor) {
    // check is added.
    if (multiPageEditor != null) {
        if ((activeEditor != null) && (activeEditor instanceof ITextEditor)) {
            activateSourcePage(activeEditor);
        } else {
            activateDesignPage(activeEditor);
        }
    }
    updateToolbarActions();
    IActionBars actionBars = getActionBars();
    if (actionBars != null) {
        // update menu bar and tool bar
        actionBars.updateActionBars();
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IActionBars(org.eclipse.ui.IActionBars)

Example 83 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class TestReconcilerXML method testWellFormed.

/**
 * Tests reconciler by verifying no errors/warnings found with well-formed
 * xml.
 */
public void testWellFormed() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    ITextEditor textEditor = fEditor.getAdapter(ITextEditor.class);
    IAnnotationModel annoModel = textEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
    DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    // verify well-formed xml
    try {
        Thread.sleep(5000);
        Iterator iter = annoModel.getAnnotationIterator();
        // make sure the only problem we find is the lack of a specified grammar
        while (iter.hasNext()) {
            Annotation anno = (Annotation) iter.next();
            String annoType = anno.getType();
            if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
                assertTrue("testReconciler: Unexpected initial annotations" + anno.getText(), anno.getText().indexOf("No grammar constraints") > -1);
            }
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation)

Example 84 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class TestReconcilerXML method testIllFormedNoAttrValue.

/**
 * Tests reconciler by verifying error/warning found with ill-formed xml.
 * (missing attribute value)
 */
public void testIllFormedNoAttrValue() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    ITextEditor textEditor = fEditor.getAdapter(ITextEditor.class);
    IAnnotationModel annoModel = textEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
    DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    // verify ill-formed xml
    try {
        doc.replace(6, 6, "<body hello>");
        Thread.sleep(5000);
        boolean errorFound = false;
        Iterator iter = annoModel.getAnnotationIterator();
        StringBuffer buffer = new StringBuffer();
        while (iter.hasNext()) {
            Annotation anno = (Annotation) iter.next();
            String annoType = anno.getType();
            buffer.append("\n");
            buffer.append(anno.getText());
            if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
                errorFound = true;
            }
        }
        assertTrue("testReconciler: Did not find expected errors in: " + doc.get() + buffer, errorFound);
    } catch (BadLocationException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 85 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class TestReconcilerXML method testIllFormedNoCloseBracket.

/**
 * Tests reconciler by verifying error/warning found with ill-formed xml.
 * (missing close bracket)
 */
public void testIllFormedNoCloseBracket() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    ITextEditor textEditor = fEditor.getAdapter(ITextEditor.class);
    IAnnotationModel annoModel = textEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
    DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    // verify ill-formed xml
    try {
        doc.replace(6, 6, "<body ");
        Thread.sleep(5000);
        boolean errorFound = false;
        Iterator iter = annoModel.getAnnotationIterator();
        StringBuffer buffer = new StringBuffer();
        while (iter.hasNext()) {
            Annotation anno = (Annotation) iter.next();
            String annoType = anno.getType();
            buffer.append("\n");
            buffer.append(anno.getText());
            if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
                errorFound = true;
            }
        }
        assertTrue("testReconciler: Did not find expected errors in: " + doc.get() + buffer.toString(), errorFound);
    } catch (BadLocationException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)236 IEditorPart (org.eclipse.ui.IEditorPart)92 IDocument (org.eclipse.jface.text.IDocument)76 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)42 IFile (org.eclipse.core.resources.IFile)36 ITextSelection (org.eclipse.jface.text.ITextSelection)34 Test (org.junit.Test)33 BadLocationException (org.eclipse.jface.text.BadLocationException)28 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 CoreException (org.eclipse.core.runtime.CoreException)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 TextSelection (org.eclipse.jface.text.TextSelection)12