+ void CompletionResultSet.setWaitText(String waitText)
was added
+ to allow customization of the text in the label displayed
+ if the completion query results are not computed in certain timeout.
+
+ CharSequence CompletionItem.getInsertPrefix()
was added.
+
+ CompletionTask.refresh(CompletionResultSet resultSet) now allows
+ null
parameter.
+
+ void AsyncCompletionQuery.preQueryUpdate(JTextComponent component)
+ was added to reflect that in AsyncCompletionTask.
+
+ * Generally the returned text does not need to contain all the information
+ * that gets inserted when the item is selected.
+ *
+ * For example in java completion the field name should be returned for fields
+ * or a method name for methods (but not parameters)
+ * or a non-FQN name for classes.
+ *
+ * @return non-null character sequence containing the insert prefix.
+ *
+ * Returning an empty string will effectively disable the TAB completion
+ * as the longest common prefix will be empty.
+ *
+ * @since 1.4
+ */
+ CharSequence getInsertPrefix();
}
Index: editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java
===================================================================
RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java,v
--- editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java 21 Jun 2005 15:37:29 -0000 1.3
+++ editor/completion/src/org/netbeans/spi/editor/completion/CompletionResultSet.java 8 Nov 2005 15:44:55 -0000
@@ -202,6 +202,25 @@
public int getSortType() {
return impl.getSortType();
}
+
+ /**
+ * Set the explicit value displayed in a label when the completion results
+ * do not get computed during a certain timeout (e.g. 250ms).
+ *
+ * If not set explicitly the completion infrastructure will use
+ * the default text.
+ *
+ * @param waitText description of what the query copmutation
+ * is currently (doing or waiting for).
+ *
+ * After previous explicit setting null
can be passed
+ * to restore using of the default text.
+ *
+ * @since 1.5
+ */
+ public void setWaitText(String waitText) {
+ impl.setWaitText(waitText);
+ }
private static final class SpiAccessor extends CompletionSpiPackageAccessor {
Index: editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java
===================================================================
RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java,v
--- editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java 15 Sep 2005 09:30:17 -0000 1.4
+++ editor/completion/src/org/netbeans/spi/editor/completion/CompletionTask.java 8 Nov 2005 15:44:55 -0000
@@ -52,8 +52,14 @@
*
* This method can be called multiple times on a single task instance.
*
+ * Typically it is called AFTER the query()
was invoked
+ * but it may also be invoked BEFORE the query()
in case
+ * the user types even before the query()
+ * was called by the infrastructure. In such
+ * case the resultSet
parameter will be null
.
+ *
* It is guaranteed that this method will not be invoked in case
- * the document of the component would change since the last invocation
+ * the document instance set in the component would change since the last invocation
* of either the query()
or refresh()
.
*
*
@@ -63,6 +69,12 @@
*
* @param resultSet non-null result set to which the results
* of the refreshing must be added.
+ *
+ * Null result set may be passed in case the query()
+ * was not invoked yet and user has typed a character. In this case
+ * the provider may hide the completion
+ * by using Completion.get().hideAll()
+ * if the typed character is inappropriate e.g. ";" for java completion.
*/
public void refresh(CompletionResultSet resultSet);
Index: editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java
===================================================================
RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java,v
--- editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java 21 Jun 2005 15:37:29 -0000 1.3
+++ editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionQuery.java 8 Nov 2005 15:44:55 -0000
@@ -34,6 +34,22 @@
public abstract class AsyncCompletionQuery {
private AsyncCompletionTask task;
+
+ /**
+ * Called in response to CompletionTask.refresh(null)
.
+ *
+ * The method gets invoked once the the user types a character
+ * but the CompletionTask.query()
was not yet invoked.
+ *
+ * The method may want to inspect the typed character before the caret
+ * position and decide whether the completion should be hidden
+ * if the typed character is inappropriate e.g. ";" for java completion.
+ *
+ * @since 1.3
+ */
+ protected void preQueryUpdate(JTextComponent component) {
+ // Always done in AWT thread - by default do nothing
+ }
/**
* Perform the query and add results to the given result set.
Index: editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java
===================================================================
RCS file: /cvs/editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java,v
--- editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java 21 Jun 2005 15:37:29 -0000 1.3
+++ editor/completion/src/org/netbeans/spi/editor/completion/support/AsyncCompletionTask.java 8 Nov 2005 15:44:55 -0000
@@ -51,6 +51,9 @@
/** Whether this task is cancelled. */
private boolean cancelled;
+
+ /** Whether query was already invoked on this task. */
+ private boolean queryInvoked;
/**
* Construct asynchronous task for the given component.
@@ -89,6 +92,7 @@
} else {
doc = null;
}
+ queryInvoked = true;
synchronized (this) {
performQuery(resultSet);
@@ -103,11 +107,15 @@
* The results should be fired into the newly provided completion listener.
*/
public void refresh(CompletionResultSet resultSet) {
- assert (resultSet != null);
assert (SwingUtilities.isEventDispatchThread());
assert !cancelled : "refresh() called on canceled task"; // NOI18N
- refreshResultSet = resultSet;
- refreshImpl();
+ if (queryInvoked) {
+ assert (resultSet != null);
+ refreshResultSet = resultSet;
+ refreshImpl();
+ } else {
+ query.preQueryUpdate(component);
+ }
}
/**
Index: java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java
===================================================================
RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java,v
--- java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java 7 Nov 2005 16:05:55 -0000 1.6
+++ java/editor/src/org/netbeans/modules/editor/java/ElementCreatingCompletionProvider.java 8 Nov 2005 15:45:04 -0000
@@ -350,6 +350,10 @@
return 300;
}
+ public CharSequence getInsertPrefix() {
+ return getItemText();
+ }
+
public void create(int offset) {
BaseDocument bdoc = (BaseDocument) document;
Position position = null;
@@ -615,6 +619,11 @@
public int getSortPriority() {
return isImplement ? 0 : 500;
}
+
+ public CharSequence getInsertPrefix() {
+ return getItemText();
+ }
+
}
private static class NbOverrideMethodPaintComponent extends NbJMIPaintComponent.NbMethodPaintComponent {
Index: java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java
===================================================================
RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java,v
--- java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java 4 Nov 2005 21:48:59 -0000 1.12
+++ java/editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java 8 Nov 2005 15:45:04 -0000
@@ -58,7 +58,7 @@
public CompletionTask createTask(int queryType, JTextComponent component) {
if (queryType == COMPLETION_QUERY_TYPE)
- return new AsyncCompletionTask(new Query(), component);
+ return new AsyncCompletionTask(new Query(component.getCaret().getDot()), component);
else if (queryType == DOCUMENTATION_QUERY_TYPE)
return new AsyncCompletionTask(new DocQuery(null), component);
else if (queryType == TOOLTIP_QUERY_TYPE)
@@ -72,11 +72,29 @@
private NbJavaJMICompletionQuery.JavaResult queryResult;
+ private int creationCaretOffset;
private int queryCaretOffset;
private int queryAnchorOffset;
private String filterPrefix;
+
+ Query(int caretOffset) {
+ this.creationCaretOffset = caretOffset;
+ }
+
+ protected void preQueryUpdate(JTextComponent component) {
+ int caretOffset = component.getCaretPosition();
+ Document doc = component.getDocument();
+ if (caretOffset >= creationCaretOffset) {
+ try {
+ if (isJavaIdentifierPart(doc.getText(creationCaretOffset, caretOffset - creationCaretOffset)))
+ return;
+ } catch (BadLocationException e) {
+ }
+ }
+ Completion.get().hideCompletion();
+ }
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
NbJavaJMICompletionQuery query = new NbJavaJMICompletionQuery(true);
Index: java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java
===================================================================
RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java,v
--- java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java 4 Nov 2005 22:15:54 -0000 1.34
+++ java/editor/src/org/netbeans/modules/editor/java/NbJMIResultItem.java 8 Nov 2005 15:45:04 -0000
@@ -176,6 +176,10 @@
public CharSequence getSortText() {
return getItemText();
}
+
+ public CharSequence getInsertPrefix() {
+ return getItemText();
+ }
public CompletionTask createDocumentationTask() {
return new AsyncCompletionTask(new JavaCompletionProvider.DocQuery(this),
Index: html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java
===================================================================
RCS file: /cvs/html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java,v
--- html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java 1 Nov 2005 09:54:04 -0000 1.23
+++ html/editor/lib/src/org/netbeans/editor/ext/html/HTMLCompletionQuery.java 8 Nov 2005 15:45:23 -0000
@@ -457,6 +457,10 @@
return HTMLResultItem.this.getItemText();
}
+ public CharSequence getInsertPrefix() {
+ return getItemText();
+ }
+
public Component getPaintComponent(boolean isSelected) {
//TODO: the paint component should be caches somehow
HTMLCompletionResultItemPaintComponent component = new HTMLCompletionResultItemPaintComponent.StringPaintComponent(getPaintColor());
Index: web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java
===================================================================
RCS file: /cvs/web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java,v
--- web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java 4 Nov 2005 14:51:34 -0000 1.9
+++ web/jspsyntax/src/org/netbeans/modules/web/core/syntax/completion/JspCompletionItem.java 8 Nov 2005 15:45:25 -0000
@@ -76,6 +76,10 @@
return DEFAULT_SORT_PRIORITY;
}
+ public CharSequence getInsertPrefix() {
+ return getItemText();
+ }
+
public Component getPaintComponent(boolean isSelected) {
if (component == null) {
component = new ResultItemPaintComponent.StringPaintComponent();