在Eclipse PDE视图中以编程方式打开编辑器。

huangapple go评论68阅读模式
英文:

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) {
            
        }
    }
}

在Eclipse PDE视图中以编程方式打开编辑器。

英文:

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(&quot;Courier&quot;, 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() &amp;&amp; fileStore.fetchInfo().exists()) {
			IWorkbenchPage page = getViewSite().getPage();
		    try {
		        IDE.openEditor(page, fileURI, &quot;net.sourceforge.javahexeditor&quot;, true);
		    } catch (PartInitException e) {
		        
		    }
		}
	}

在Eclipse PDE视图中以编程方式打开编辑器。

答案1

得分: 0

链接并没有说编辑器会在视图中打开,它只是告诉你如何从视图中打开编辑器。编辑器始终会在编辑器区域中单独打开。

你不能在视图中拥有一个编辑器。你可以在视图中使用核心编辑器类,比如TextViewerSourceViewer,但这意味着你不能重用来自现有编辑器的代码,除非它被设计成允许这样做。

英文:

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.

huangapple
  • 本文由 发表于 2020年8月7日 05:21:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63291924.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定