通过插件以编程方式显示SWT浏览器 [英] Display a SWT Browser programmatically from plugin

查看:207
本文介绍了通过插件以编程方式显示SWT浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开Eclipse的内部浏览器( org.eclipse.swt.browser.Browser )通过从Eclipse插件的代码调用。



到目前为止,我实际上可以实例化一个,我可以打开一个URL(我可以感谢我设置的监听器的日志)。但没有什么出现。由于shell被用作浏览器的复合父级,所以我预计它将会启动。



我在这个特定问题上找不到任何资源,大多数示例片段不是关于插件。



这是我的代码到目前为止:

  final Shell shell = myActiveWorkbenchWindow.getShell(); 
final浏览器浏览器=新浏览器(shell,SWT.NONE);
//设置监听器在加载时记录url
browser.setUrl(getLoginUrl());那么,我怎么能让浏览器出现(作为一个弹出窗口或者在我的Eclipse窗口中)?

解决方案

而不是想像浏览器像一个拥有自己的窗口chrome的对象,想像一个专门的面板或可以包含HTML数据的UI区域。上面的例子中的问题是你正在将一个新的UI面板插入一个现有的窗口小部件中(子窗口小部件通过以父作为构造函数的参数来创建自己)。



使用浏览器对象在新窗口中打开URL的一个更好的例子可能是:

  Shell parentShell = Activator.getDefault ).getWorkbench()getActiveWorkbenchWindow()getShell()。; 
Shell myShell = new Shell(parentShell,SWT.SHELL_TRIM);
//非常重要的是,父母一般都必须有一个布局设置来显示孩子
myShell.setLayout(new FillLayout());
浏览器浏览器=新浏览器(myShell,SWT.NONE);
browser.setUrl(getLoginUrl());
myShell.layout();
myShell.open();


I am trying to open the internal browser of Eclipse (org.eclipse.swt.browser.Browser) by calling it from an Eclipse plugin's code.

So far, I could actually instantiate one and I can "open" a URL (I can tell thanks to a log from the listener I set up). But nothing appears. As the shell is used as the Composite parent of the Browser, I expect it will just launch.

I could not find any resource on this specific issue, most example snippets not being about plugins.

Here is my code so far:

  final Shell shell = myActiveWorkbenchWindow.getShell();
  final Browser browser = new Browser(shell, SWT.NONE);
   // set up listener to log the url when loaded
  browser.setUrl(getLoginUrl());

So, how could I make the browser appear (either as a popup or in my Eclipse window)?

解决方案

Instead of thinking of "Browser" like an object with all its own window chrome, think of it like a dedicated panel or UI area that can contain HTML data. The problem in the above example is that you are inserting a new UI panel into an existing widget (child widgets create themselves by taking the parent as a parameter to the constructor).

A better example to open a URL in a new window using the Browser object might be:

Shell parentShell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
Shell myShell = new Shell (parentShell, SWT.SHELL_TRIM);
// Very important, generally parents must have a layout set to display children
myShell.setLayout (new FillLayout()); 
Browser browser = new Browser (myShell, SWT.NONE);
browser.setUrl (getLoginUrl());
myShell.layout();
myShell.open();

这篇关于通过插件以编程方式显示SWT浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆