KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > editor > completion > CompletionResultSet


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.spi.editor.completion;
21
22 import java.util.Collection JavaDoc;
23 import javax.swing.JToolTip JavaDoc;
24 import org.netbeans.modules.editor.completion.CompletionResultSetImpl;
25 import org.netbeans.modules.editor.completion.CompletionSpiPackageAccessor;
26
27 /**
28  * Listener interface for passing the query results.
29  * @see CompletionProvider#createTask
30  *
31  * @author Miloslav Metelka, Dusan Balek
32  * @version 1.01
33  */

34
35 public final class CompletionResultSet {
36
37     static {
38         CompletionSpiPackageAccessor.register(new SpiAccessor());
39     }
40     
41     /**
42      * Sort type returned from {@link #getSortType()}
43      * that prefers priority of the item ({@link CompletionItem#getSortPriority()})
44      * over the text of the item ({@link CompletionItem#getSortText()}).
45      */

46     public static final int PRIORITY_SORT_TYPE = 0;
47     
48     /**
49      * Sort type returned from {@link #getSortType()}
50      * that prefers text of the item ({@link CompletionItem#getSortText()}).
51      * over the priority of the item ({@link CompletionItem#getSortPriority()})
52      */

53     public static final int TEXT_SORT_TYPE = 1;
54
55     private CompletionResultSetImpl impl;
56
57     CompletionResultSet(CompletionResultSetImpl impl) {
58         this.impl = impl;
59         impl.setResultSet(this);
60     }
61
62     /**
63      * Set title that will be assigned to the completion popup window.
64      * <br>
65      * It's only relevant to set the title when providing completion items
66      * for {@link CompletionProvider#COMPLETION_QUERY_TYPE}.
67      * <br>
68      * If there will be multiple completion providers setting this property
69      * for the given mime-type then only the first one
70      * (according to the xml-layer registration order)
71      * will be taken into account.
72      */

73     @Deprecated JavaDoc
74     public void setTitle(String JavaDoc title) {
75         impl.setTitle(title);
76     }
77
78     /**
79      * Set the document offset to which the returned completion items
80      * or documentation or tooltip should be anchored.
81      * <br>
82      * If there will be multiple completion providers setting this property
83      * for the given mime-type then only the first one
84      * (according to the xml-layer registration order)
85      * will be taken into account.
86      */

87     public void setAnchorOffset(int anchorOffset) {
88         impl.setAnchorOffset(anchorOffset);
89     }
90
91     /**
92      * Add the completion item to this result set.
93      * <br>
94      * This method can be called multiple times until
95      * all the items have been added to ths result set.
96      * <br>
97      * After the adding is completed @link #finish()} must be called to confirm
98      * that the result set will no longer be modified.
99      *
100      * @param item non-null completion item.
101      * @return true if adding of the items can continue
102      * or false if there is already too many items
103      * to be practical to display in the listbox so subsequent
104      * adding should preferably be discontinued.
105      */

106     public boolean addItem(CompletionItem item) {
107         return impl.addItem(item);
108     }
109     
110     /**
111      * Add the collection of the completion items to this result set.
112      * <br>
113      * This method can be called multiple times until
114      * all the items have been added to ths result set.
115      * <br>
116      * After the adding is completed @link #finish()} must be called to confirm
117      * that the result set will no longer be modified.
118      *
119      * @param items collection of items to be added.
120      * @return true if adding of the items can continue
121      * or false if there is already too many items
122      * to be practical to display in the listbox so subsequent
123      * adding should preferably be discontinued.
124      */

125     public boolean addAllItems(Collection JavaDoc<? extends CompletionItem> items) {
126         return impl.addAllItems(items);
127     }
128     
129     /**
130      * Indicate that adding of the items to this result set
131      * will likely need a long time so the resulting number of items
132      * and their visual size should be estimated so that
133      * the completion infrastructure can estimate the size
134      * of the popup window and display the items added subsequently
135      * without changing its bound extensively.
136      * <br>
137      * Without calling of this method the completion infrastructure
138      * will wait until {@link #finish()} gets called on this result set
139      * before displaying any of the items added to this result set.
140      *
141      * <p>
142      * By calling of this method the task also confirms
143      * that the items added by {@link #addItem(CompletionItem)} subsequently
144      * are already in the order corresponding to the {@link #getSortType()}.
145      *
146      * @param estimatedItemCount estimated number of the items that will
147      * be added to this result set by {@link #addItem(CompletionItem)}.
148      * If the estimate is significantly lower than the reality then
149      * the vertical scrollbar granularity may be decreased or the vertical
150      * scrollbar can be removed completely once the result set is finished.
151      * If the estimate is significantly higher than the reality then
152      * the vertical scrollbar granularity may be increased
153      * once the result set is finished.
154      * @param estimatedItemWidth estimated maximum visual width of a completion item.
155      */

156     public void estimateItems(int estimatedItemCount, int estimatedItemWidth) {
157         impl.estimateItems(estimatedItemCount, estimatedItemWidth);
158     }
159     
160     /**
161      * Set the documentation to this result set.
162      * <br>
163      * Calling this method is only relevant for tasks
164      * created by {@link CompletionProvider#createTask(int, javax.swing.text.JTextComponent)}
165      * with {@link CompletionProvider#DOCUMENTATION_QUERY_TYPE}
166      * or for {@link CompletionItem#createDocumentationTask()}.
167      */

168     public void setDocumentation(CompletionDocumentation documentation) {
169         impl.setDocumentation(documentation);
170     }
171     
172     /**
173      * Set the tooltip to this result set.
174      * <br>
175      * Calling this method is only relevant for tasks
176      * created by {@link CompletionProvider#createTask(int, javax.swing.text.JTextComponent)}
177      * with {@link CompletionProvider#TOOLTIP_QUERY_TYPE}
178      * or for {@link CompletionItem#createToolTipTask()}.
179      */

180     public void setToolTip(JToolTip JavaDoc toolTip) {
181         impl.setToolTip(toolTip);
182     }
183     
184     /**
185      * Mark that this result set is finished and there will be no more
186      * modifications done to it.
187      */

188     public void finish() {
189         impl.finish();
190     }
191     
192     /**
193      * Check whether this result set is finished.
194      *
195      * @return true if the result set is already finished by previous call
196      * to {@link #finish()}.
197      */

198     public boolean isFinished() {
199         return impl.isFinished();
200     }
201     
202     /**
203      * Get the sort type currently used by the code completion.
204      * <br>
205      * It's one of the {@link #PRIORITY_SORT_TYPE} or {@link #TEXT_SORT_TYPE}.
206      */

207     public int getSortType() {
208         return impl.getSortType();
209     }
210     
211     /**
212      * Set the explicit value displayed in a label when the completion results
213      * do not get computed during a certain timeout (e.g. 250ms).
214      * <br>
215      * If not set explicitly the completion infrastructure will use
216      * the default text.
217      *
218      * @param waitText description of what the query copmutation
219      * is currently (doing or waiting for).
220      * <br>
221      * After previous explicit setting <code>null</code> can be passed
222      * to restore using of the default text.
223      *
224      * @since 1.5
225      */

226     public void setWaitText(String JavaDoc waitText) {
227         impl.setWaitText(waitText);
228     }
229
230     
231     private static final class SpiAccessor extends CompletionSpiPackageAccessor {
232         
233         public CompletionResultSet createCompletionResultSet(CompletionResultSetImpl impl) {
234             return new CompletionResultSet(impl);
235         }
236         
237     }
238 }
239
Popular Tags