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;
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations