【发布时间】:2017-03-02 02:49:03
【问题描述】:
我有一个具有编辑器视图的 Eclipse 插件项目。所以我扩展了EditorPart 类。最初,init 方法被调用,我也可以在那里调用setPartName 方法来更新选项卡的标签,如:
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
//...
setPartName(filename);
}
setPartName 方法是受保护的方法。我现在有另一个类(比如说DataModel),它是我的编辑器的数据模型。是否可以从此类更新编辑器部分?因为DataModel 类中的文件重命名了,现在我想显示新文件名/替换旧文件名。
编辑:这是一个基于 gef4 的项目,View(扩展 AbstractFXEditor,扩展 EditorPart)在 init 方法中创建 DataModel 的实例:
IFile file = ((IFileEditorInput) input).getFile();
URI inputUri = URI.createURI(file.getFullPath().toString(), true);
getContentViewer().getContents().setAll(createContents(inputUri));
而createContents(URI) 方法创建DataModel 的实例。
谢谢
【问题讨论】:
-
因此,在您的编辑器中声明一个公共方法,该方法调用 setPartName 并从您的 DataModel 调用该方法。