Eclipse SWT浏览器和Firebug lite?

时间:2012-08-17 09:56:59

标签: eclipse debugging swt

有没有办法在eclipse SWT浏览器中使用Firebug lite“bookmarklet”功能?

3 个答案:

答案 0 :(得分:10)

取决于您的SWT浏览器正在使用的系统浏览器。对于Win7和IE8,你可以这样:

输出

enter image description here

代码

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class FirebugLite 
{
    public static void main(String[] args) {
        new FirebugLite().start();
    }

    public void start()
    {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));
        GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
        gridData.widthHint = SWT.DEFAULT;
        gridData.heightHint = SWT.DEFAULT;
        shell.setLayoutData(gridData);
        shell.setText("Firebug Lite for SWT ;)");

        final Browser browser = new Browser(shell, SWT.NONE);
        GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
        gridData2.widthHint = SWT.DEFAULT;
        gridData2.heightHint = SWT.DEFAULT;
        browser.setLayoutData(gridData2);

        Button button = new Button(shell, SWT.PUSH);
        button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,    false));
        button.setText("Install");
        button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                browser.setUrl("javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');");
            }
        });

        browser.setUrl("http://stackoverflow.com/questions/12003602/eclipse-swt-browser-and-firebug-lite");

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

Note >> 我使用了setUrl() API。您可以尝试execute(),但我不确定它是否有用。

答案 1 :(得分:0)

我无法在Linux上运行。出现例外网页:“无法显示网址”。

答案 2 :(得分:0)

我稍稍调整了Favonius的解决方案。在我的情况下,我们想看看内部的iframe。我修改了setUrl以在最后一个iframe中加载firebug。在我的情况下,它做了我们想要的。

browser.setUrl("javascript: function lastIframeDocument(curr){while(curr.getElementsByTagName('iframe')[0]!=null){curr=curr.getElementsByTagName('iframe')[0].contentWindow.document;}return curr;}(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(lastIframeDocument(document),'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');");
相关问题