public abstract class AsyncCompletionQuery extends Object
AsyncCompletionQuery.query(CompletionResultSet, Document, int)
abstract method
needs to be implemented to define the asynchronous querying behavior.
AsyncCompletionQuery.canFilter(JTextComponent)
and AsyncCompletionQuery.filter(CompletionResultSet)
.Constructor and Description |
---|
AsyncCompletionQuery() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canFilter(JTextComponent component)
Check whether the query results can successfully be filtered.
|
protected void |
filter(CompletionResultSet resultSet)
Filter the data collected during the last
AsyncCompletionQuery.query(CompletionResultSet, Document, int) invocation. |
boolean |
isTaskCancelled()
Check whether the task corresponding to this query was cancelled.
|
protected void |
prepareQuery(JTextComponent component)
Collect additional information in AWT thread before
AsyncCompletionQuery.query(CompletionResultSet, Document, int)
is called asynchronously. |
protected void |
preQueryUpdate(JTextComponent component)
Called in response to
CompletionTask.refresh(null) . |
protected abstract void |
query(CompletionResultSet resultSet,
Document doc,
int caretOffset)
Perform the query and add results to the given result set.
|
protected void preQueryUpdate(JTextComponent component)
CompletionTask.refresh(null)
.
CompletionTask.query()
was not yet invoked.
protected abstract void query(CompletionResultSet resultSet, Document doc, int caretOffset)
RequestProcessor
thread.resultSet
- result set into which the computed data should be added.
The result set must always be finished
by CompletionResultSet.finish()
.doc
- document of the text component on which the query is being run.
null
if the corresponding component is null.caretOffset
- present caret offset of the text component
on which the query is being run.
-1
if the corresponding component is null.protected boolean canFilter(JTextComponent component)
CompletionTask.refresh(CompletionResultSet)
in AWT thread. The asynchronous query method
AsyncCompletionQuery.query(CompletionResultSet, Document, int)
may still be running when this method is invoked.
The implementation typically gets the text between
caret offset remembered during query and the present caret offset
(can be gathered by component.getCaretPosition()
)
and examines whether the results computed (or being computed) during the query
(they should be collected and rememberred in the query method body)
can be filtered appropriately.
For example in java the user can type e.g. "my" and so all the classes
and fields and methods starting with "my" appropriate for the given context
will be computed during the query.
If the user continues typing e.g. "myMethod" then the result set
computed during the query can be filtered and this method should return true.
However if the user has typed e.g. "my()." then the original result
set is useless and this method should return false.
component
- text component for which this provider was constructed.
It may be null if no text component was provided.false
if the filtering cannot be done or is not supported
at all by this query implementation. The full asynchronous query
will be invoked then.
protected void filter(CompletionResultSet resultSet)
AsyncCompletionQuery.query(CompletionResultSet, Document, int)
invocation.
CompletionTask.refresh(CompletionResultSet)
call.
AsyncCompletionQuery.canFilter(JTextComponent)
returned true
and when there is currently no query in progress
so it is safe to use the results computed during the query.
The implementation typically gets the text between
caret offset remembered during query and the present caret offset
(can be gathered by component.getCaretPosition()
)
and examines whether the results computed during the query
(they should be rememberred in the query method body)
can be filtered appropriately.
For example in java the user can type e.g. "my" and so all the classes
and fields and methods starting with "my" appropriate for the given context
will be computed during the query.
If the user continues typing e.g. "myMethod" then the result set
computed during the query can be filtered and this method should return true.
However if the user has typed e.g. "my()." then the original result
set is useless and this method should return false.
The default implementation does not support filtering
and throws IllegalStateException
.
resultSet
- result set to which the filtering must add
its results. The result set must always be finished
by CompletionResultSet.finish()
.protected void prepareQuery(JTextComponent component)
AsyncCompletionQuery.query(CompletionResultSet, Document, int)
is called asynchronously.component
- text component for which this provider was constructed.
It may be null if no text component was provided.public final boolean isTaskCancelled()