use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class GcovAnnotationModel method clear.
public static void clear(ITextEditor editor) {
IDocumentProvider provider = editor.getDocumentProvider();
if (provider == null) {
return;
}
IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
if (!(model instanceof IAnnotationModelExtension)) {
return;
}
IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
IAnnotationModel coverageModel = modelex.getAnnotationModel(KEY);
if (coverageModel instanceof GcovAnnotationModel) {
((GcovAnnotationModel) coverageModel).clear();
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class GcovAnnotationModel method attach.
/**
* Attaches a coverage annotation model for the given editor if the editor
* can be annotated. Does nothing if the model is already attached.
*
* @param editor Editor to which an annotation model should be attached
*/
public static void attach(ITextEditor editor) {
IDocumentProvider provider = editor.getDocumentProvider();
if (provider == null) {
return;
}
IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
if (!(model instanceof IAnnotationModelExtension)) {
return;
}
IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
IDocument document = provider.getDocument(editor.getEditorInput());
GcovAnnotationModel coveragemodel = (GcovAnnotationModel) modelex.getAnnotationModel(KEY);
if (coveragemodel == null) {
coveragemodel = new GcovAnnotationModel(editor, document);
modelex.addAnnotationModel(KEY, coveragemodel);
} else {
coveragemodel.updateAnnotations(false);
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class OpenSourceFileAction method openAnnotatedSourceFile.
public static void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, IPath realLocation, int lineNumber) {
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
IWorkbenchPage page = CUIPlugin.getActivePage();
if (page != null) {
IFileStore fs = getFileStore(project, realLocation);
if (fs == null && !realLocation.isAbsolute() && binary != null) {
IPath p = binary.getProjectRelativePath().removeLastSegments(1);
fs = getFileStore(project, p.append(realLocation));
}
if (fs == null) {
try {
page.openEditor(new STAnnotatedSourceNotFoundEditorInput(project, sourceFile, realLocation, lineNumber), STAnnotatedSourceNotFoundEditor.ID, true);
} catch (PartInitException e) {
Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
Activator.getDefault().getLog().log(s);
}
} else {
try {
IEditorPart editor = IDE.openEditorOnFileStore(page, fs);
if (lineNumber > 0 && editor instanceof ITextEditor) {
IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
IDocument document = provider.getDocument(editor.getEditorInput());
try {
int start = document.getLineOffset(lineNumber - 1);
((ITextEditor) editor).selectAndReveal(start, 0);
} catch (BadLocationException e) {
// ignore
}
IWorkbenchPage p = editor.getSite().getPage();
p.activate(editor);
}
} catch (PartInitException e) {
Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
Activator.getDefault().getLog().log(s);
}
}
}
});
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class GNUFormat method getDocument.
public IDocument getDocument(IEditorPart currentEditor) {
AbstractTextEditor castEditor = (AbstractTextEditor) currentEditor;
IDocumentProvider provider = castEditor.getDocumentProvider();
return provider.getDocument(castEditor.getEditorInput());
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class GNUFormatTest method tearDown.
@After
public void tearDown() throws Exception {
// content to the empty string).
if (changelogEditorPart != null) {
// testFormatDateLine does not use it
AbstractTextEditor castEditor = (AbstractTextEditor) changelogEditorPart;
IDocumentProvider iDocProvider = castEditor.getDocumentProvider();
IDocument changelogContentDoc = iDocProvider.getDocument(castEditor.getEditorInput());
// empty content
changelogContentDoc.set("");
changelogEditorPart.doSave(null);
// Also close open editor in order for default content to work.
// I.e. avoid spill over from previous test runs
closeEditor(changelogEditorPart);
}
// dispose
project.getTestProject().delete(true, true, null);
}
Aggregations