KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > browser > OpenBrowserHandler


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.browser;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
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 JavaDoc PARAM_ID_URL = "url"; //$NON-NLS-1$
27

28     private static final String JavaDoc PARAM_ID_BROWSER_ID = "browserId"; //$NON-NLS-1$
29

30     private static final String JavaDoc PARAM_ID_NAME = "name"; //$NON-NLS-1$
31

32     private static final String JavaDoc PARAM_ID_TOOLTIP = "tooltip"; //$NON-NLS-1$
33

34     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
35
36         String JavaDoc urlText = event.getParameter(PARAM_ID_URL);
37         URL JavaDoc url;
38         if (urlText == null) {
39             url = null;
40         } else {
41             try {
42                 url = new URL JavaDoc(urlText);
43             } catch (MalformedURLException JavaDoc ex) {
44                 throw new ExecutionException("malformed URL:" + urlText, ex); //$NON-NLS-1$
45
}
46         }
47
48         String JavaDoc browserId = event.getParameter(PARAM_ID_BROWSER_ID);
49         String JavaDoc name = event.getParameter(PARAM_ID_NAME);
50         String JavaDoc 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); //$NON-NLS-1$
62
}
63
64         return null;
65     }
66 }
67
Popular Tags