use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class SegmentedModeTest method testShowNothing.
/*
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465684
*/
@Test
public void testShowNothing() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
while (Display.getDefault().readAndDispatch()) {
}
IEditorPart part = IDE.openEditor(page, fFile);
try {
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
editor.showHighlightRangeOnly(true);
editor.setHighlightRange(0, 0, true);
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
StyledText styledText = (StyledText) control;
String text = styledText.getText();
assertEquals("", text);
}
}
} finally {
page.saveEditor(part, false);
}
} catch (PartInitException e) {
assertTrue(false);
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class EditorAnnotationManager method getAnnotationModel.
private static IAnnotationModel getAnnotationModel(IWorkbenchPart part) {
IAnnotationModel model = null;
model = part.getAdapter(IAnnotationModel.class);
if (model == null) {
ITextEditor textEditor = null;
if (part instanceof ITextEditor) {
textEditor = (ITextEditor) part;
}
if (textEditor != null) {
IDocumentProvider dp = textEditor.getDocumentProvider();
if (dp != null)
model = dp.getAnnotationModel(textEditor.getEditorInput());
}
}
return model;
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class EditorAnnotationManager method getDocument.
private static IDocument getDocument(IWorkbenchPart part) {
IDocument doc = null;
doc = part.getAdapter(IDocument.class);
if (doc == null) {
ITextEditor textEditor = null;
if (part instanceof ITextEditor) {
textEditor = (ITextEditor) part;
}
if (textEditor != null) {
IDocumentProvider dp = textEditor.getDocumentProvider();
if (dp != null)
doc = dp.getDocument(textEditor.getEditorInput());
}
}
return doc;
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class RetrieverAction method extractSearchTextFromEditor.
protected final String extractSearchTextFromEditor(IEditorPart editor) {
if (editor != null) {
ITextSelection selection = null;
ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
if (provider != null) {
ISelection s = provider.getSelection();
if (s instanceof ITextSelection) {
selection = (ITextSelection) s;
}
}
if (selection != null) {
if (selection.getLength() == 0) {
ITextEditor txtEditor = getTextEditor(editor);
if (txtEditor != null) {
IDocument document = txtEditor.getDocumentProvider().getDocument(txtEditor.getEditorInput());
selection = expandSelection(selection, document, null);
}
}
if (selection.getLength() > 0 && selection.getText() != null) {
return trimSearchString(selection.getText());
}
}
}
return null;
}
use of org.eclipse.ui.texteditor.ITextEditor in project eclipse.platform.text by eclipse.
the class AnnotationManagerTest method testAddAnnotation.
@Test
public void testAddAnnotation() throws Exception {
NewSearchUI.runQueryInForeground(null, fQuery1);
AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
Object[] files = result.getElements();
try {
for (int i = 0; i < files.length; i++) {
IFile file = (IFile) files[i];
ITextEditor editor = (ITextEditor) SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
annotationModel.getAnnotationIterator();
HashSet<Position> positions = new HashSet<>();
for (Iterator<Annotation> iter = annotationModel.getAnnotationIterator(); iter.hasNext(); ) {
Annotation annotation = iter.next();
if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(NewSearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) {
positions.add(annotationModel.getPosition(annotation));
}
}
Match[] matches = result.getMatches(file);
for (int j = 0; j < matches.length; j++) {
Position position = new Position(matches[j].getOffset(), matches[j].getLength());
// $NON-NLS-1$
assertTrue("position not found at: " + j, positions.remove(position));
}
assertEquals(0, positions.size());
}
} finally {
SearchPlugin.getActivePage().closeAllEditors(false);
}
}
Aggregations