从IEDitorPart(Eclipse)获取ITextViewer [英] get ITextViewer from IEDitorPart (Eclipse)

查看:368
本文介绍了从IEDitorPart(Eclipse)获取ITextViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipse RCP问题

Eclipse RCP question

我打开文件:

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = IDE.openEditor(page, file);

我也得到文件:

IDocument doc = ((ITextEditor)editorPart).getDocumentProvider().getDocument(editorPart.getEditorInput());

我需要获取该文档的文本查看器(用于创建LinkedModeUI),是否有任何方法

I need to get to text viewer of that document (for creating LinkedModeUI), is there any way to do this?

推荐答案

以下内容适用于我:

IEditorPart editorPart = getSite().getPage().getActiveEditor();
if (editorPart != null) {
    ITextOperationTarget target =
            (ITextOperationTarget)editorPart.getAdapter(ITextOperationTarget.class);
    if (target instanceof ITextViewer) {
        ITextViewer textViewer = (ITextViewer)target;
        // ...
    } 
}

这篇关于从IEDitorPart(Eclipse)获取ITextViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆