1 19 package org.netbeans.modules.retouche.editor.completion; 20 21 import java.awt.event.ActionEvent ; 22 import java.net.URL ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import org.netbeans.api.editor.completion.Completion; 26 import org.netbeans.api.gsf.Completable; 27 import org.netbeans.api.gsf.Parser; 28 import org.netbeans.api.gsf.Element; 29 import org.netbeans.api.gsf.ElementHandle; 30 import org.netbeans.api.retouche.source.CompilationController; 31 import org.netbeans.api.retouche.source.UiUtils; 32 import org.netbeans.modules.gsf.Language; 33 import org.netbeans.spi.editor.completion.CompletionDocumentation; 34 35 36 41 public class GsfCompletionDoc implements CompletionDocumentation { 42 private String content = null; 43 private URL docURL = null; 44 private AbstractAction goToSource = null; 45 private ElementHandle elementHandle; 46 47 private GsfCompletionDoc(final CompilationController controller, final ElementHandle elementHandle, 48 URL url) { 49 Language language = controller.getLanguage(); 50 Completable completer = language.getCompletionProvider(); 51 final Parser parser = language.getParser(); 52 final Element resolved; 53 if ((completer != null) && (parser != null)) { 54 resolved = parser.resolveHandle(controller, elementHandle); 55 } else { 56 resolved = null; 57 } 58 59 this.elementHandle = elementHandle; 60 61 if (elementHandle != null) { 62 goToSource = 63 new AbstractAction () { 64 public void actionPerformed(ActionEvent evt) { 65 Completion.get().hideAll(); 66 UiUtils.open(controller.getSource(), elementHandle); 67 } 68 }; 69 if (url != null) { 70 docURL = url; 71 } else { 72 docURL = null; 73 } 74 } 75 76 if (resolved != null) { 77 this.content = completer.document(controller, resolved); 78 } 79 80 if (this.content == null) { 81 Completion.get().hideDocumentation(); 82 } 83 } 84 85 public static final GsfCompletionDoc create(CompilationController controller, 86 ElementHandle elementHandle) { 87 return new GsfCompletionDoc(controller, elementHandle, null); 88 } 89 90 public String getText() { 91 return content; 92 } 93 94 public URL getURL() { 95 return docURL; 96 } 97 98 public CompletionDocumentation resolveLink(String link) { 99 throw new RuntimeException ("Not yet implemented"); 100 } 101 102 public Action getGotoSourceAction() { 103 return goToSource; 104 } 105 } 106 | Popular Tags |