1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.libraries; 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 35 41 final class ShowJavadocAction extends NodeAction { 42 43 48 public static interface JavadocProvider { 49 50 54 public abstract boolean hasJavadoc (); 55 56 59 public abstract void showJavadoc (); 60 } 61 62 protected void performAction(Node[] activatedNodes) { 63 if (activatedNodes.length!=1) { 64 return; 65 } 66 JavadocProvider jd = (JavadocProvider) activatedNodes[0].getLookup().lookup(JavadocProvider.class); 67 if (jd == null) { 68 return; 69 } 70 jd.showJavadoc(); 71 } 72 73 protected boolean enable(Node[] activatedNodes) { 74 if (activatedNodes.length!=1) { 75 return false; 76 } 77 JavadocProvider jd = (JavadocProvider) activatedNodes[0].getLookup().lookup(JavadocProvider.class); 78 if (jd == null) { 79 return false; 80 } 81 return jd.hasJavadoc(); 82 } 83 84 public final String getName() { 85 return NbBundle.getMessage(ShowJavadocAction.class,"CTL_ShowJavadoc"); 86 } 87 88 public final HelpCtx getHelpCtx() { 89 return new HelpCtx (ShowJavadocAction.class); 90 } 91 92 public final boolean asynchronous () { 93 return false; 94 } 95 96 102 static void showJavaDoc (URL javadoc, String displayName) { 103 if (javadoc!=null) { 104 HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc); 105 } 106 else { 107 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ShowJavadocAction.class, 108 "TXT_NoJavadoc", displayName)); } 110 } 111 112 118 static URL findJavadoc (String resource, URL urls[]) { 119 for (int i=0; i<urls.length; i++) { 120 String base = urls[i].toExternalForm(); 121 if (!base.endsWith("/")) { base+="/"; } 124 try { 125 URL u = new URL (base+resource); 126 FileObject fo = URLMapper.findFileObject(u); 127 if (fo != null) { 128 return u; 129 } 130 } catch (MalformedURLException ex) { 131 ErrorManager.getDefault().log(ErrorManager.ERROR, "Cannot create URL for "+base+resource+". "+ex.toString()); continue; 133 } 134 } 135 return null; 136 } 137 } 138 139 140 | Popular Tags |