KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > editor > completion > GsfCompletionDoc


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.retouche.editor.completion;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.net.URL JavaDoc;
23 import javax.swing.AbstractAction JavaDoc;
24 import javax.swing.Action JavaDoc;
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 /**
37  * Produce completion-popup help for elements
38  *
39  * @author Tor Norbye
40  */

41 public class GsfCompletionDoc implements CompletionDocumentation {
42     private String JavaDoc content = null;
43     private URL JavaDoc docURL = null;
44     private AbstractAction JavaDoc goToSource = null;
45     private ElementHandle elementHandle;
46
47     private GsfCompletionDoc(final CompilationController controller, final ElementHandle elementHandle,
48         URL JavaDoc 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 JavaDoc() {
64                         public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc getText() {
91         return content;
92     }
93
94     public URL JavaDoc getURL() {
95         return docURL;
96     }
97
98     public CompletionDocumentation resolveLink(String JavaDoc link) {
99         throw new RuntimeException JavaDoc("Not yet implemented");
100     }
101
102     public Action JavaDoc getGotoSourceAction() {
103         return goToSource;
104     }
105 }
106
Popular Tags