Smarty77
Smarty77

Reputation: 1358

Eclipse display browser in view

I am trying to create a plug-in, which will show local .html file inside internal browser. Currently i am extending class ViewPart, and writing code into its createPartControl method. Most of people are using this snippet

IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("SOMELABEL");
browser.openURL(url);

Problem is that this snippet opens another view where internal browser is opened, but in my case it needs to be in this view... I also tried other forms of createBrowser method, e.g.

createBrowser(int style, String browserId, String name, String tooltip); 

where i tried to configure flags, but all of these options just open another view or editor. Is there a way do draw HTML inside my view?

Upvotes: 2

Views: 485

Answers (1)

Smarty77
Smarty77

Reputation: 1358

I have found the solution. Yes i have tried Browser control before, but i did not created Browser properly (wrong arguments). If anybody else tries to implement ViewPart displaying html pages via SWT, here is the code snippet.

public class CustomView extends ViewPart {

    private static final String URL = "file:///d:/playground/d3/project.html";
    @Override
    public void createPartControl(Composite parent) {       
        final Browser browser = new Browser(parent, SWT.NONE); 
        browser.setUrl(URL);        
    }

    @Override
    public void setFocus() {        
    }
}

Upvotes: 2

Related Questions