KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > browser > LaunchURL


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.help.ui.browser;
12
13 import java.util.Hashtable JavaDoc;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.help.browser.*;
17 import org.eclipse.help.internal.browser.*;
18 import org.eclipse.help.ui.internal.*;
19 import org.eclipse.help.ui.internal.util.*;
20 import org.eclipse.jface.action.*;
21 import org.eclipse.jface.viewers.*;
22 import org.eclipse.ui.*;
23
24 /**
25  * Action that launches a URL in a browser.
26  * <p>
27  * This class is intended to be specified as a value of a class attribute of an
28  * action element in plugin.xml for extensions of org.eclipse.ui.actionSets
29  * extension point. The URL to launch must be specified in the markup in one
30  * of two ways.
31  * </p>
32  * </p>
33  * The action element can have an attribute named url, in addition to markup
34  * required by org.eclipse.ui.actionSets extension point specification. The
35  * value of the url attribute should specify a URL to be opened in a browser.
36  * </p>
37  * </p>
38  * Alternatively, since 3.1, instead of a class attribute on the action element,
39  * the extension can specify a nested class element with a class attribute
40  * and URL specified in a parameter sub-element. For example:
41  * <pre> &lt;class class="org.eclipse.help.ui.browser.LaunchURL"&gt;
42  * &lt;parameter name="url" value="http://eclipse.org/" /&gt;
43  * &lt;/class&gt;</pre>
44  * </p>
45  */

46 public class LaunchURL implements IWorkbenchWindowActionDelegate,
47         IExecutableExtension {
48     private String JavaDoc url;
49
50     /**
51      * @see IWorkbenchWindowActionDelegate#dispose()
52      */

53     public void dispose() {
54     }
55
56     /**
57      * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
58      */

59     public void init(IWorkbenchWindow window) {
60     }
61
62     /**
63      * @see IExecutableExtension#setInitializationData(IConfigurationElement,
64      * String, Object)
65      */

66     public void setInitializationData(IConfigurationElement config,
67             String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
68         if (data != null && data instanceof Hashtable JavaDoc) {
69             url = (String JavaDoc) ((Hashtable JavaDoc) data).get("url"); //$NON-NLS-1$
70
}
71         if (url == null || url.length() == 0)
72             url = config.getAttribute("url"); //$NON-NLS-1$
73
}
74
75     /**
76      * @see IActionDelegate#run(IAction)
77      */

78     public void run(IAction action) {
79         if (url == null || "".equals(url)) { //$NON-NLS-1$
80
return;
81         }
82         IBrowser browser = BrowserManager.getInstance().createBrowser(true);
83         try {
84             browser.displayURL(url);
85         } catch (Exception JavaDoc e) {
86             HelpUIPlugin.logError("Exception occurred when opening URL: " + url //$NON-NLS-1$
87
+ ".", e); //$NON-NLS-1$
88
ErrorUtil.displayErrorDialog(Messages.LaunchURL_exception);
89         }
90     }
91
92     /**
93      * @see IActionDelegate#selectionChanged(IAction, ISelection)
94      */

95     public void selectionChanged(IAction action, ISelection selection) {
96     }
97
98 }
99
Popular Tags