Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse SWT browser and Firebug lite?

Is there a way to use Firebug lite "bookmarklet" feature within eclipse SWT browser?

like image 969
kofucii Avatar asked Dec 27 '22 19:12

kofucii


1 Answers

Depends on the system browser which your SWT browser is using. For Win7 and IE8, you can have something like this:

Output

enter image description here

Code

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 >> I have used the setUrl() API. You can try the execute() but I am not sure whether it would work.

like image 61
Favonius Avatar answered Dec 29 '22 07:12

Favonius