英文:
Open Editor in an Eclipse PDE View programmatically
问题
我正在创建一个Eclipse插件,其中包含一个视图,名为DataView。我希望Java Hex编辑器在我创建的DataView中打开。我遵循了这篇 vogella 帖子中的步骤,该帖子指出使用getViewSite().getPage()
会强制编辑器在DataView中打开。然而,当我测试代码时,DataView和编辑器是分开打开的。注意:由于公司要求,我正在使用Java 8。
是否有任何方法可以修复这个问题? 我已附上我的代码和当前输出如下:
@Override
public void createPartControl(Composite parent) {
Text text = new Text(parent, SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
Font font = new Font(text.getDisplay(), new FontData("Courier", 12 , SWT.NONE));
text.setFont(font);
File file = FileData.getDataFile();
URI fileURI = file.toURI();
IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileURI);
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
IWorkbenchPage page = getViewSite().getPage();
try {
IDE.openEditor(page, fileURI, "net.sourceforge.javahexeditor", true);
} catch (PartInitException e) {
}
}
}
英文:
I am creating an eclipse plugin with a view, called DataView. I want the Java Hex Editor to open in my DataView that I created. I followed this vogella post, which stated that getViewSite().getPage(), would force the editor to open in the DataView. However, when I test the code, the DataView opens separately from the editor. Note: I am using Java 8 by company requirements.
Is there anyway to fix this? I have attached my code and my current output below:
<!-- language: lang-java -->
@Override
public void createPartControl(Composite parent) {
Text text = new Text(parent, SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
Font font = new Font(text.getDisplay(), new FontData("Courier", 12 , SWT.NONE));
text.setFont(font);
File file = FileData.getDataFile();
URI fileURI = file.toURI();
//String workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileURI);
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
IWorkbenchPage page = getViewSite().getPage();
try {
IDE.openEditor(page, fileURI, "net.sourceforge.javahexeditor", true);
} catch (PartInitException e) {
}
}
}
答案1
得分: 0
链接并没有说编辑器会在视图中打开,它只是告诉你如何从视图中打开编辑器。编辑器始终会在编辑器区域中单独打开。
你不能在视图中拥有一个编辑器。你可以在视图中使用核心编辑器类,比如TextViewer
和SourceViewer
,但这意味着你不能重用来自现有编辑器的代码,除非它被设计成允许这样做。
英文:
The link does not say that the editor will open in the view, it is just telling you how to open an editor from a view. Editors always open separately in the editor area.
You can't have an editor in a view. You can use the core editor classes such as TextViewer
and SourceViewer
in a view but that means you can't reuse code from an existing editor unless it is designed to allow this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论