在插件开发中如何获取到活动的工作区页面?
2017-08-10 00:00
323 查看
摘要: 在插件开发中如何获取到活动的工作区页面?
缺点:返回null当活动窗口不存在的时候
其他的方式
Similarly, actions contributed to the popupMenus extension point always have an initialization method that sets the current part before the action's run method is called. All wizard extension points also have an IWorkbenchWizard init method that supplies the wizard with the current workbench window before the wizard is launched. In short, if you look carefully, you can almost always get at the current window or page, no matter where you are in the Eclipse UI.
在插件开发中如何获取到活动的工作区页面?
第一种方法IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = win.getActiveWorkbenchPage(); // on new versions it may need to be changed to: IWorkbenchPage page = win.getActivePage();
缺点:返回null当活动窗口不存在的时候
其他的方式
在一个Part里的时候
`1IWorkbenchPage page = getSite().getPage();` `// Workbench sites are IServiceLocator.`
在一个命令句柄里的时候
The HandlerUtil class provides a number of helper methods to obtain the active window, editor, part, etc. from the ExecutionEvent provided to the handler. A special case is a handler that implements IElementUpdater as the updateElements() method is provided an UIElement rather than an ExecutionEvent. But the UIElement does provide an IServiceLocator.
在一个Action里的时候
From an action defined in a workbench action set, you can access the window from the init method:class MyAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; ... public void init(IWorkbenchWindow win) { this.window = win; } }
Similarly, actions contributed to the popupMenus extension point always have an initialization method that sets the current part before the action's run method is called. All wizard extension points also have an IWorkbenchWizard init method that supplies the wizard with the current workbench window before the wizard is launched. In short, if you look carefully, you can almost always get at the current window or page, no matter where you are in the Eclipse UI.
从IEclipseContext or IServiceLocator对象中获取
Service locators are similar to Eclipse Contexts (IEclipseContext):IServiceLocator locator = …; IWorkbenchWindow window = locator.get(IWorkbenchWindow.class);
相关文章推荐
- NPAPI插件开发详细记录:实用功能——获取插件路径、页面路径、资源路径
- wordpress二次开发教程手记:如何使客户在启用我所开发的主题或插件后转跳到指定的页面
- rcp(插件开发) 插件中如何获取MANIFEST.MF 文件,并解析?
- rcp(插件开发)如何获取显示在编辑区的所有编辑器及获取其中之一
- WinForm开发浏览器,WebBrowser获取页面内容,如何解决中文乱码
- 黄聪:二、如何通过URL获取其他网页源代码内容(火狐插件扩展开发教程)
- rcp(插件开发) 如何获取视图、编辑器;隐藏视图、编辑器
- rcp(插件开发)如何获取MenuBar上的菜单
- rcp(插件开发)如何获取IWorkbenchPage对象?
- Rcp(插件开发) 如何获取当前视图选中的对象
- rcp(插件开发)如何获取视图(view)中当前选择的元素
- WinForm开发浏览器,WebBrowser获取页面内容,如何解决中文乱码
- rcp(插件开发) 如何获取eclipse or rcp的安装目录
- Cordova webapp实战开发:(6)如何写一个iOS下获取APP版本号的插件?
- NPAPI插件开发详细记录:实用功能——获取插件路径、页面路径、资源路径
- WinForm开发浏览器,WebBrowser获取页面内容,如何解决中文乱码
- eclipse插件开发获取Eclipse相关的文件根目录
- iOS开发之如何做一个可上下左右滑动的页面
- 谈谈iOS开发如何写个人中心这类页面--静态tableView页面的编写
- [Web 开发] 获取页面元素的坐标及大小