KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > URLHyperlink


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.editors.text;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.jface.text.IRegion;
17
18 import org.eclipse.ui.PartInitException;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.browser.IWebBrowser;
21 import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
22
23
24 /**
25  * URL hyperlink.
26  *
27  * @since 3.1
28  */

29 final class URLHyperlink extends org.eclipse.jface.text.hyperlink.URLHyperlink {
30     
31     private String JavaDoc fURLString;
32     
33     /**
34      * Creates a new URL hyperlink.
35      *
36      * @param region
37      * @param urlString
38      */

39     public URLHyperlink(IRegion region, String JavaDoc urlString) {
40         super(region, urlString);
41         fURLString= urlString;
42     }
43     
44     /*
45      * @see org.eclipse.jface.text.hyperlink.URLHyperlink#open()
46      * @since 3.1
47      */

48     public void open() {
49         // Create the browser
50
IWorkbenchBrowserSupport support= PlatformUI.getWorkbench().getBrowserSupport();
51         IWebBrowser browser;
52         try {
53             browser= support.createBrowser(null);
54         } catch (PartInitException e) {
55             EditorsPlugin.logErrorStatus("Could not create Web browser for URLHyperlink", e.getStatus()); //$NON-NLS-1$
56
super.open();
57             return;
58         }
59
60         try {
61             browser.openURL(new URL JavaDoc(fURLString));
62         } catch (PartInitException e) {
63             super.open();
64         } catch (MalformedURLException JavaDoc e) {
65             super.open();
66         }
67     }
68 }
69
Popular Tags