1 19 20 21 package org.netbeans.modules.javadoc.search; 22 23 import javax.swing.JEditorPane ; 24 import org.openide.cookies.EditorCookie; 25 import org.openide.nodes.Node; 26 import org.openide.util.HelpCtx; 27 import org.openide.util.NbBundle; 28 import org.openide.util.actions.CookieAction; 29 import org.openide.windows.TopComponent; 30 31 import java.awt.*; 32 33 41 public final class ShowDocAction extends CookieAction { 42 43 static final long serialVersionUID =3578357584245478L; 44 45 public ShowDocAction() { 46 putValue("noIconInMenu", Boolean.TRUE); } 48 52 public String getName () { 53 return NbBundle.getBundle( ShowDocAction.class ).getString ("CTL_SHOWDOC_MenuItem"); } 55 56 58 protected final Class [] cookieClasses () { 59 return new Class [] { EditorCookie.class }; 60 } 61 62 64 protected int mode () { 65 return MODE_EXACTLY_ONE; 66 } 67 68 71 public HelpCtx getHelpCtx () { 72 return new HelpCtx (ShowDocAction.class); 73 } 74 75 80 public void performAction ( Node[] nodes ) { 81 IndexSearch indexSearch = IndexSearch.getDefault(); 82 83 if( nodes.length == 1 && nodes[0] != null ) { 84 String toFind = findTextFromNode(nodes[0]); 85 if (toFind != null) 86 indexSearch.setTextToFind( toFind ); 87 } 88 indexSearch.open (); 89 indexSearch.requestActive(); 90 } 91 92 95 private String findTextFromNode(Node n) { 96 EditorCookie ec = (EditorCookie)n.getCookie(EditorCookie.class); 97 if (ec != null) { 99 JEditorPane [] panes = ec.getOpenedPanes(); 100 if (panes != null) { 101 TopComponent activetc = TopComponent.getRegistry().getActivated(); 102 for (int i = 0; i < panes.length; i++) { 103 if (activetc.isAncestorOf(panes[i])) { 104 String s = GetJavaWord.forPane(panes[i]); 106 if (s != null) 107 return s; 108 else 109 break; 110 } 111 } 112 } 113 } 114 return n.getName(); 115 } 116 117 protected boolean asynchronous() { 118 return false; 119 } 120 } 121 | Popular Tags |