1 19 20 package org.netbeans.modules.languages.css; 21 22 import org.netbeans.api.languages.ASTNode; 23 import org.netbeans.api.languages.ASTPath; 24 import org.netbeans.api.languages.SyntaxContext; 25 import org.netbeans.api.lexer.Token; 26 import org.netbeans.api.languages.Context; 27 import org.openide.cookies.OpenCookie; 28 import org.openide.filesystems.FileObject; 29 import org.openide.loaders.DataObject; 30 import org.openide.loaders.DataObjectNotFoundException; 31 import org.openide.util.Lookup; 32 import org.openide.windows.TopComponent; 33 34 38 public class CSS { 39 40 public static String tooltip (Context context) { 41 if (!(context instanceof SyntaxContext)) return null; 42 SyntaxContext syntaxContext = (SyntaxContext) context; 43 ASTPath path = syntaxContext.getASTPath (); 44 StringBuilder sb = new StringBuilder (); 45 sb.append ("<html>"); 46 sb.append ("<p style=\""); 47 ASTNode ruleset = (ASTNode) path.get (path.size () - 2); 48 ASTNode body = ruleset.getNode ("body"); 49 ASTNode declarations = body.getNode ("declarations"); 50 if (declarations == null) return null; 51 String s = declarations.getAsText (); 52 s = s.replaceAll ("\"", ""); 53 sb.append (s); 54 sb.append ("\">Text Preview.</p>"); 55 sb.append ("</html>"); 56 return sb.toString (); 57 } 58 59 public static String navigatorTooltip (Context context) { 60 if (!(context instanceof SyntaxContext)) return null; 61 ASTNode n = (ASTNode) ((SyntaxContext) context).getASTPath ().getLeaf (); 62 StringBuilder sb = new StringBuilder (); 63 sb.append ("<html>"); 64 sb.append ("<p style=\""); 65 ASTNode body = n.getNode ("body"); 66 if (body == null) return null; 67 ASTNode declarations = body.getNode ("declarations"); 68 if (declarations == null) return null; 69 String s = declarations.getAsText (); 70 s = s.replaceAll ("\"", ""); 71 sb.append (s); 72 sb.append ("\">Text Preview.</p>"); 73 sb.append ("</html>"); 74 return sb.toString (); 75 } 76 77 public static Runnable hyperlink (Context context) { 78 Token t = context.getTokenSequence ().token (); 79 String s = t.id ().name (); 80 s = s.substring (1, s.length () - 1); 81 s = s.replace ("%20", " "); Lookup l = TopComponent.getRegistry ().getActivated ().getLookup (); 83 DataObject dob = (DataObject) l.lookup (DataObject.class); 84 FileObject fo = dob.getPrimaryFile ().getParent (); 85 final FileObject file = fo.getFileObject (s); 86 if (file != null) 87 return new Runnable () { 88 public void run () { 89 try { 90 DataObject d = DataObject.find (file); 91 OpenCookie oc = (OpenCookie) d.getCookie (OpenCookie.class); 92 oc.open (); 93 } catch (DataObjectNotFoundException ex) { 94 } 95 } 96 }; 97 return null; 98 } 99 } 100 | Popular Tags |