1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.help.ui.browser;
import java.util.Hashtable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.help.browser.IBrowser;
import org.eclipse.help.internal.browser.BrowserManager;
import org.eclipse.help.ui.internal.HelpUIPlugin;
import org.eclipse.help.ui.internal.Messages;
import org.eclipse.help.ui.internal.util.ErrorUtil;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
/**
* Action that launches a URL in a browser.
* <p>
* This class is intended to be specified as a value of a class attribute of an
* action element in plugin.xml for extensions of org.eclipse.ui.actionSets
* extension point. The URL to launch must be specified in the markup in one of
* two ways.
* </p>
* <p>
* The action element can have an attribute named url, in addition to markup
* required by org.eclipse.ui.actionSets extension point specification. The
* value of the url attribute should specify a URL to be opened in a browser.
* </p>
* <p>
* Alternatively, since 3.1, instead of a class attribute on the action element,
* the extension can specify a nested class element with a class attribute and
* URL specified in a parameter sub-element. For example:
* </p>
*
* <pre>
* <class class="org.eclipse.help.ui.browser.LaunchURL">
* <parameter name="url" value="http://eclipse.org/" />
* </class>
* </pre>
*/
public class LaunchURL implements IWorkbenchWindowActionDelegate,
IExecutableExtension {
private String url;
@Override
public void dispose() {
}
@Override
public void init(IWorkbenchWindow window) {
}
@Override
@SuppressWarnings("unchecked")
public void setInitializationData(IConfigurationElement config,
String propertyName, Object data) throws CoreException {
if (data != null && data instanceof Hashtable) {
url = ((Hashtable<String, String>) data).get("url"); //$NON-NLS-1$
}
if (url == null || url.length() == 0)
url = config.getAttribute("url"); //$NON-NLS-1$
}
@Override
public void run(IAction action) {
if (url == null || "".equals(url)) { //$NON-NLS-1$
return;
}
IBrowser browser = BrowserManager.getInstance().createBrowser(true);
try {
browser.displayURL(url);
} catch (Exception e) {
HelpUIPlugin.logError("Exception occurred when opening URL: " + url //$NON-NLS-1$
+ ".", e); //$NON-NLS-1$
ErrorUtil.displayErrorDialog(Messages.LaunchURL_exception);
}
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
}
}
|