Wednesday, March 11, 2009

Launching a url using a browser component

If you need to launch a url in Lotus Expeditor based clients, you have several options depending on how you want to present it.

Here's a few ways on how to do it:
  • Using a Browser Widget ( added to a Composite)
  • Using the EmbeddedBrowser View

Using a Browser Widget ( added to a Composite)
Eclipse and Lotus Expeditor offers each a simple browser widget that can be added to a composite. They a very much alike.

Here's a sample using the core Eclipse SWT browser widget:

Browser browser;
try {

browser = new Browser(composite, SWT.NONE);
browser.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true));
browser.setUrl("http://www.ibm.com");

} catch (SWTError e) {
// Handle any errors.
}

And here's a sample with the Lotus Expeditor equivalent:

WebBrowser browser;
try {

browser = new WebBrowser(composite, SWT.NONE);
browser.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true));
browser.setUrl("http://www.ibm.com");

} catch (SWTError e) {
// Handle any errors.
}


You can use the browser.setText("...") method to add custom HTML content into the browser, if needed.
You also have the ability to listen to events and traverse the DOM (Document Object Model).

Using the EmbeddedBrowser View
The Lotus Expeditor platform also gives you a viewpart based browser component.

// Every instance needs it's own unique id.
String id = "com.rcpcompany.lotus.notes.spy.browserview.sample";

// Create a map with all the needed properties.
Map configMap = new HashMap();
configMap.put(BrowserPreference.ID, id);
configMap.put(BrowserPreference.INITIAL_URL, url);

// Get the active page
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();

// Create the browser instance.
EmbeddedBrowser browser = BrowserFactory.launch(page, configMap, id);

// Maximize the new browser view if needed.
page.setPartState(page.getActivePartReference(), IWorkbenchPage.STATE_MAXIMIZED);

1 comment:

Unknown said...

Hi Ronnie,

The browser.seturl method does not seem to work when using the filelocator to locate a file inside the plugin...


Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL url = FileLocator.find(bundle, new Path("welcome.html"), null);
try {
url = FileLocator.resolve(url);
setTitle(url.getFile());
//welcomeBrowser.setUrl("/users/user/Documents/workspace/titanapp/welcome.html");
welcomeBrowser.setUrl(url.getFile());


} catch (IOException e) {
/// TODO Auto-generated catch block
e.printStackTrace();
}


welcome.html is included in the root of the plugin and included in the build.

This works from within eclipse but does not when exported to a product.

Hope you can help,
Raghu.

Search This Blog

Eclipse Live: Equinox Ganymede

The creator of an Eclipse Bible, introduces Equinox and its building blocks for creating applications. We overview the architecture and technology, and demonstrate many of the building blocks.
by Jeff McAffer (Code 9)