1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.net.URL ; 23 import java.net.MalformedURLException ; 24 import org.openide.ErrorManager; 25 import org.openide.awt.HtmlBrowser; 26 import org.openide.awt.StatusDisplayer; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.URLMapper; 29 import org.openide.nodes.Node; 30 import org.openide.util.NbBundle; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.actions.NodeAction; 33 34 37 43 final class ShowJavadocAction extends NodeAction { 44 45 50 public static interface JavadocProvider { 51 52 56 public abstract boolean hasJavadoc(); 57 58 61 public abstract void showJavadoc(); 62 } 63 64 protected void performAction(Node[] activatedNodes) { 65 if (activatedNodes.length!=1) { 66 return; 67 } 68 JavadocProvider jd = (JavadocProvider) activatedNodes[0].getLookup().lookup(JavadocProvider.class); 69 if (jd == null) { 70 return; 71 } 72 jd.showJavadoc(); 73 } 74 75 protected boolean enable(Node[] activatedNodes) { 76 if (activatedNodes.length!=1) { 77 return false; 78 } 79 JavadocProvider jd = (JavadocProvider) activatedNodes[0].getLookup().lookup(JavadocProvider.class); 80 if (jd == null) { 81 return false; 82 } 83 return jd.hasJavadoc(); 84 } 85 86 public final String getName() { 87 return NbBundle.getMessage(ShowJavadocAction.class,"CTL_ShowJavadoc"); 88 } 89 90 public final HelpCtx getHelpCtx() { 91 return new HelpCtx(ShowJavadocAction.class); 92 } 93 94 public final boolean asynchronous() { 95 return false; 96 } 97 98 104 static void showJavaDoc(URL javadoc, String displayName) { 105 if (javadoc!=null) { 106 HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc); 107 } else { 108 StatusDisplayer.getDefault().setStatusText( 109 NbBundle.getMessage(ShowJavadocAction.class, "TXT_NoJavadoc", 110 displayName)); 111 } 112 } 113 114 120 static URL findJavadoc(String resource, URL urls[]) { 121 for (int i = 0; i < urls.length; i++) { 122 String base = urls[i].toExternalForm(); 123 if (!base.endsWith("/")) { base+="/"; } 126 try { 127 URL u = new URL (base+resource); 128 FileObject fo = URLMapper.findFileObject(u); 129 if (fo != null) { 130 return u; 131 } 132 } catch (MalformedURLException ex) { 133 ErrorManager.getDefault().log(ErrorManager.ERROR, 134 "Cannot create URL for " + base + resource + ". " + ex.toString()); continue; 136 } 137 } 138 return null; 139 } 140 141 } 142 | Popular Tags |