KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > editor > completion > WSCompletionProvider


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
20 package org.netbeans.modules.websvc.editor.completion;
21
22 import javax.swing.text.Document JavaDoc;
23 import javax.swing.text.JTextComponent JavaDoc;
24 import org.netbeans.editor.Utilities;
25 // Retouche
26
//import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
27
import org.netbeans.spi.editor.completion.CompletionProvider;
28 import org.netbeans.spi.editor.completion.CompletionResultSet;
29 import org.netbeans.spi.editor.completion.CompletionTask;
30 import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
31 import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;
32
33 /**
34  *
35  * @author Marek Fukala
36  */

37 public class WSCompletionProvider implements CompletionProvider {
38     
39     public int getAutoQueryTypes(JTextComponent JavaDoc component, String JavaDoc typedText) {
40         return 0;
41     }
42
43     public CompletionTask createTask(int queryType, JTextComponent JavaDoc component) {
44         if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE) {
45             return new AsyncCompletionTask(new Query(component.getCaret().getDot()), component);
46         }
47         return null;
48     }
49     
50     static final class Query extends AsyncCompletionQuery {
51         
52         private JTextComponent JavaDoc component;
53         
54         private int creationCaretOffset;
55         private int queryCaretOffset;
56         
57         private int queryAnchorOffset;
58         
59         private String JavaDoc filterPrefix;
60         
61         Query(int caretOffset) {
62             this.creationCaretOffset = caretOffset;
63         }
64         
65         protected void preQueryUpdate(JTextComponent JavaDoc component) {
66 // int caretOffset = component.getCaretPosition();
67
// Document doc = component.getDocument();
68
// if (caretOffset >= creationCaretOffset) {
69
// try {
70
// if (isJavaIdentifierPart(doc.getText(creationCaretOffset, caretOffset - creationCaretOffset)))
71
// return;
72
// } catch (BadLocationException e) {
73
// }
74
// }
75
// Completion.get().hideCompletion();
76
}
77         
78         protected void query(CompletionResultSet resultSet, Document JavaDoc doc, int caretOffset) {
79 // Retouche
80
// if (JavaMetamodel.getManager().isScanInProgress()) {
81
// resultSet.setWaitText(NbBundle.getMessage(WSCompletionProvider.class, "scanning-in-progress")); //NOI18N
82
// }
83
// WSCompletionQuery query = new WSCompletionQuery(true);
84
// WSCompletionQuery.DefaultResult res = (WSCompletionQuery.DefaultResult)query.query(component, caretOffset, Utilities.getSyntaxSupport(component));
85
// if (res != null) {
86
// queryCaretOffset = caretOffset;
87
// //queryAnchorOffset = res.getSubstituteOffset();
88
// resultSet.setTitle(res.getTitle());
89
// // resultSet.setAnchorOffset(queryAnchorOffset);
90
// resultSet.addAllItems(res.getData());
91
// // queryResult = res;
92
// }
93
resultSet.finish();
94         }
95         
96         protected void prepareQuery(JTextComponent JavaDoc component) {
97             this.component = component;
98         }
99         
100 // private boolean isJavaIdentifierPart(String text) {
101
// for (int i = 0; i < text.length(); i++) {
102
// if (!(Character.isJavaIdentifierPart(text.charAt(i))) ) {
103
// return false;
104
// }
105
// }
106
// return true;
107
// }
108

109         // TODO: filtering
110
}
111 }
112
Popular Tags