2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.clientproject.ui;
45
import java.net.MalformedURLException;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import org.openide.awt.HtmlBrowser;
49
import org.openide.awt.StatusDisplayer;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.URLMapper;
52
import org.openide.nodes.Node;
53
import org.openide.util.NbBundle;
54
import org.openide.util.HelpCtx;
55
import org.openide.util.actions.NodeAction;
59
* Action for showing Javadoc. The action looks up
60
* the {@link ShowJavadocAction.JavadocProvider} in the
61
* activated node's Lookup and delegates to it.
62
* @author Tomas Zezula
64
final class ShowJavadocAction extends NodeAction {
65
private static final long serialVersionUID = 1L;
68
* Implementation of this interfaces has to be placed
69
* into the node's Lookup to allow {@link ShowJavadocAction}
72
public static interface JavadocProvider {
75
* Checks if the node can provide Javaodc
76
* @return true if the action should be enabled
78
public abstract boolean hasJavadoc ();
81
* Opens javadoc page in the browser
83
public abstract void showJavadoc ();
86
protected void performAction(Node[] activatedNodes) {
87
if (activatedNodes.length!=1) {
90
JavadocProvider jd = activatedNodes[0].getLookup().lookup(JavadocProvider.class);
97
protected boolean enable(Node[] activatedNodes) {
98
if (activatedNodes.length!=1) {
101
JavadocProvider jd = activatedNodes[0].getLookup().lookup(JavadocProvider.class);
105
return jd.hasJavadoc();
108
public final String getName() {
109
return NbBundle.getMessage(ShowJavadocAction.class,"CTL_ShowJavadoc");
112
public final HelpCtx getHelpCtx() {
113
return new HelpCtx (ShowJavadocAction.class);
117
public final boolean asynchronous () {
122
* Opens the IDE default browser with given URL
123
* @param javadoc URL of the javadoc page
124
* @param displayName the name of file to be displayed, typically the package name for class
125
* or project name for project.
127
static void showJavaDoc (URL javadoc, String displayName) {
129
HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc);
132
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ShowJavadocAction.class,
133
"TXT_NoJavadoc", displayName)); //NOI18N
138
* Locates a javadoc page by a relative name and an array of javadoc roots
139
* @param resource the relative name of javadoc page
140
* @param urls the array of javadoc roots
141
* @return the URL of found javadoc page or null if there is no such a page.
143
static URL findJavadoc (String resource, URL urls[]) {
144
for (int i = 0; i < urls.length; i++) {
145
String base = urls[i].toExternalForm();
146
if (!base.endsWith("/")) { // NOI18N
150
URL u = new URL(base+resource);
151
FileObject fo = URLMapper.findFileObject(u);
155
} catch (MalformedURLException ex) {
156
Logger.getLogger("global").log(Level.SEVERE, "Cannot create URL for " + base + resource + ". " + ex.toString());