user3873909
user3873909

Reputation: 191

Browser.evaluate() method showing error

I have written a simple Java program using the SWT API. I have instantiated a browser in the app and trying to use the browser.evaluate() method . But It shows me the following error

The method evaluate(String) is undefined for the type Browser

Here is my complete programe

    import java.awt.event.MouseEvent;

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.SWTError;
    import org.eclipse.swt.custom.CTabFolder;
    import org.eclipse.swt.custom.CTabItem;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.browser.*;
    import org.eclipse.swt.printing.*;
    import org.eclipse.swt.events.*;



    public class example {

     public static void main(String args[])
     {
        final Display display = new Display();
        final Shell shell=new Shell(display);
        shell.setText("Informatica Business Glossary Desktop");

        final Browser browser = new Browser(shell,SWT.NONE);

        final String SCRIPT01 = "var html = \"\";"+
                "if (typeof window.getSelection != \"undefined\") {"+
                    "var sel = window.getSelection();"+
                    "if (sel.rangeCount) {"+
                        "var container = document.createElement(\"div\");"+
                        "for (var i = 0, len = sel.rangeCount; i < len; ++i) {"+
                            "container.appendChild(sel.getRangeAt(i).cloneContents());"+
                        "}"+
                        "html = container.innerHTML;"+
                    "}"+
                "} else if (typeof document.selection != \"undefined\") {"+
                    "if (document.selection.type == \"Text\") {"+
                        "html = document.selection.createRange().htmlText;"+
                    "}" +
                "}" +
                "return html";
        //final Browser browser;


    if(browser!=null)
{

    browser.setUrl("https://www.google.com");
}

        browser.addMouseListener(new MouseListener(){

            @Override
            public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) {
                String selection = (String)browser .evaluate(SCRIPT01);
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseDown(org.eclipse.swt.events.MouseEvent e) {

                // TODO Auto-generated method stub

            }

            @Override
            public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
                String selection = (String) browser.evaluate(SCRIPT01);
                // TODO Auto-generated method stub

            }



        });
     }  
    }

Error is shown at

String selection = (String) browser.evaluate(SCRIPT01);  

I am using Eclipse Juno

Upvotes: 0

Views: 408

Answers (1)

greg-449
greg-449

Reputation: 111217

The JavaDoc for the evaluate method of the Browser class says it was added for SWT version 3.5 so you need to have at least that version.

The latest version for Eclipse Luna is here

Upvotes: 1

Related Questions