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