use of org.eclipse.ui.texteditor.ITextEditor 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.ITextEditor in project erlide_eclipse by erlang.
the class DoubleClickListener method higlightCodePart.
public void higlightCodePart(final DuplicatedCodeInstanceElement codePart) {
final ITextEditor textEditor = (ITextEditor) WranglerUtils.openFile(codePart.getContainingFile());
WranglerUtils.highlightOffsetSelection(codePart.getStartOffset(), codePart.getEndOffset(), textEditor);
}
use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.
the class EditorTracker method clearAnnotations.
public void clearAnnotations(final IWorkbenchPart part) {
if (part != null) {
log.info(part.getTitle());
}
if (part instanceof ITextEditor) {
final ITextEditor editor = (ITextEditor) part;
final IAnnotationModel annMod = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
@SuppressWarnings("rawtypes") final Iterator it = annMod.getAnnotationIterator();
while (it.hasNext()) {
final Annotation annotation = (Annotation) it.next();
if (annotation.getType().equals(CoverageTypes.FULL_COVERAGE) || annotation.getType().equals(CoverageTypes.NO_COVERAGE)) {
annMod.removeAnnotation(annotation);
}
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.
the class EditorTracker method removeAnnotationsFragment.
/**
* Removes coverage annotations from a fragment of file
*
* @param fileName
* @param start
* @param end
*/
public void removeAnnotationsFragment(final String fileName, final int start, final int end) {
final IEditorPart currentEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (currentEditor.getTitle().equals(fileName) && currentEditor instanceof ITextEditor) {
final ITextEditor editor = (ITextEditor) currentEditor;
final IAnnotationModel annMod = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
final Set<LineResult> list = coverage.getLineSet(editor.getTitle());
for (final LineResult lr : list) {
if (lr.getLineNum() < start || end != -1 && lr.getLineNum() > end) {
continue;
}
log.info(lr.getLineNum());
if (coverage.containsAnnotation(editor.getTitle(), lr)) {
final Annotation ann = coverage.getAnnotation(editor.getTitle(), lr);
annMod.removeAnnotation(ann);
coverage.removeAnnotation(editor.getTitle(), lr);
}
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project erlide_eclipse by erlang.
the class ErlangAbstractHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final ITextEditor textEditor = (ITextEditor) HandlerUtil.getActiveEditor(event);
if (!validateEditorInputState(textEditor)) {
return null;
}
final ISelection sel = textEditor.getSelectionProvider().getSelection();
if (sel == null || sel.isEmpty() || !(sel instanceof ITextSelection)) {
return null;
}
ErlideEventTracer.getInstance().traceOperationStart(this);
try {
final IRunnableWithProgress myRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor0) {
final IProgressMonitor monitor = monitor0 != null ? monitor0 : new NullProgressMonitor();
try {
monitor.beginTask("Processing " + textEditor.getEditorInput().getName(), IProgressMonitor.UNKNOWN);
doAction(sel, textEditor);
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(myRunnableWithProgress);
} catch (final InvocationTargetException e) {
} catch (final InterruptedException e) {
}
} finally {
ErlideEventTracer.getInstance().traceOperationEnd(this);
}
return null;
}
Aggregations