1 11 package org.eclipse.ui.internal.browser; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.commands.AbstractHandler; 17 import org.eclipse.core.commands.ExecutionEvent; 18 import org.eclipse.core.commands.ExecutionException; 19 import org.eclipse.ui.PartInitException; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.browser.IWebBrowser; 22 import org.eclipse.ui.browser.IWorkbenchBrowserSupport; 23 24 public class OpenBrowserHandler extends AbstractHandler { 25 26 private static final String PARAM_ID_URL = "url"; 28 private static final String PARAM_ID_BROWSER_ID = "browserId"; 30 private static final String PARAM_ID_NAME = "name"; 32 private static final String PARAM_ID_TOOLTIP = "tooltip"; 34 public Object execute(ExecutionEvent event) throws ExecutionException { 35 36 String urlText = event.getParameter(PARAM_ID_URL); 37 URL url; 38 if (urlText == null) { 39 url = null; 40 } else { 41 try { 42 url = new URL (urlText); 43 } catch (MalformedURLException ex) { 44 throw new ExecutionException("malformed URL:" + urlText, ex); } 46 } 47 48 String browserId = event.getParameter(PARAM_ID_BROWSER_ID); 49 String name = event.getParameter(PARAM_ID_NAME); 50 String tooltip = event.getParameter(PARAM_ID_TOOLTIP); 51 52 try { 53 IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench() 54 .getBrowserSupport(); 55 IWebBrowser browser = browserSupport.createBrowser( 56 IWorkbenchBrowserSupport.LOCATION_BAR 57 | IWorkbenchBrowserSupport.NAVIGATION_BAR, 58 browserId, name, tooltip); 59 browser.openURL(url); 60 } catch (PartInitException ex) { 61 throw new ExecutionException("error opening browser", ex); } 63 64 return null; 65 } 66 } 67 | Popular Tags |