[英]How To set Active Page in IWorkbenchPage
I am running an application as Eclipse
application where some operation is getting performed on a file and correspondingly other file is modified 我正在将应用程序作为Eclipse
应用程序运行,其中正在对文件执行某些操作,并相应地修改了其他文件
I am getting the file like this : 我正在得到这样的文件 :
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage activePage = workbenchWindow.getActivePage();
IEditorPart editor = activePage.getActiveEditor();
IEditorInput input = editor.getEditorInput();
IPath path = ((FileEditorInput)input).getPath();
}
}});
I am performing some operation on different file based on some input, and i want to set that as active page in running eclipse
application. 我正在基于一些输入对不同文件执行一些操作,并且我想在运行eclipse
应用程序中将其设置为活动页面。
I am not able to figure out how to set that active page. 我无法弄清楚如何设置该活动页面。
I went through question but have not found exact question. 我遇到了问题,但没有找到确切的问题。
There is only one page in a workbench window. 工作台窗口中只有一页。 Editors are all on the same page. 编辑者都在同一页面上。
For a file in the workspace you use IFile
to reference the file. 对于工作空间中的文件,可以使用IFile
来引用该文件。
There are lots of ways to get the IFile
, for example if you have the path relative to the workspace root use: 有很多方法可以获取IFile
,例如,如果您具有相对于工作空间root使用的相对路径:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFile(new Path("path relative to workspace root"));
If you have an absolute path File
you can use: 如果您有绝对路径File
,则可以使用:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
URI location = file.toURI();
IFile[] files = root.findFilesForLocationURI(location);
Once you have the IFile
you can open the default editor for the file using: 拥有IFile
您可以使用以下方法打开文件的默认编辑器:
IDE.openEditor(activePage, file);
or you can specify a specific editor id with: 或者,您可以通过以下方式指定特定的编辑者ID:
IDE.openEditor(activePage, file, "the editor id");
IDE
is org.eclipse.ui.ide.IDE
IDE
是org.eclipse.ui.ide.IDE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.