ebresie commented on a change in pull request #2820:
URL: https://github.com/apache/netbeans/pull/2820#discussion_r598342018
##########
File path:
ide/db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java
##########
@@ -41,42 +57,190 @@
* @author Andrei Badea
*/
public class SQLCompletionProvider implements CompletionProvider {
+ private static final String SQL_CONNECTION_HINT_ID = "sql_connection_hint";
+ private String selection;
+ private static JTextComponent component = null;
+ private static DatabaseConnection dbconn = null;
+ @Override
public CompletionTask createTask(int queryType, JTextComponent component) {
- if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE || queryType
== CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
+ if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE ||
+ queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
+
+ /* to support DB related completion tasks (i.e. auto populating
table
+ names or db columns for given schema) check for connection */
DatabaseConnection dbconn = findDBConn(component);
- if (dbconn == null) {
- // XXX perhaps should have an item in the completion instead?
- Completion.get().hideAll();
- SQLExecutionBaseAction.notifyNoDatabaseConnection();
- return null;
+ // No database connection set or active
+ if (SQLCompletionProvider.dbconn == null) {
+ createSuggestions(component,dbconn);
}
+
return new AsyncCompletionTask(new SQLCompletionQuery(dbconn),
component);
}
+
+ // not a completion query type so return nothing
return null;
}
+ /**
+ * getAutoQueryTypes is invoked to check whether a popup with suggestions
+ * should be shown without the user explicitly asking for it.
+ *
+ * If either #getAutoQueryTypes return a non-zero value or the user
+ * explicitly asks for completion, #createTask is invoked with the
+ * requested type. In case of SQL see
+ * org.netbeans.modules.db.sql.editor.completion.SQLCompletionQuery.
+ *
+ * @param component
+ * @param typedText
+ * @return
+ */
public int getAutoQueryTypes(JTextComponent component, String typedText) {
+ /* TODO: Need to check "enable/disable" autocomplete is setting.
+ See NETBEANS-188 */
+
+ // If "." has not been typed then acceptable to start checking for
options.
if (!".".equals(typedText)) { // NOI18N
return 0;
}
+ // check typed text if dot is present at the selected offset
if (!isDotAtOffset(component, component.getSelectionStart() - 1)) {
return 0;
}
+
+// List<Fix> fixes = new ArrayList<>(Collections.emptyList());
+// Document doc = component.getDocument();
+// List<ErrorDescription> warnings = new
ArrayList<>(Collections.emptyList());
+
+ // check if there is a DB connection
DatabaseConnection dbconn = findDBConn(component);
if (dbconn == null) {
String message = NbBundle.getMessage(SQLCompletionProvider.class,
"MSG_NoDatabaseConnection");
StatusDisplayer.getDefault().setStatusText(message);
- return 0;
+ /* TODO: Find How to povide tip to create new connection and/or
+ allow further typing and/or other options.
+
+ Maybe provide a list of available connections.
+
+ return 0; */
+// createSuggestions(component, doc, fixes, warnings, dbconn);
+ createSuggestions(component, dbconn);
Review comment:
My assumption here is that when "dconn" is null, that essentually no
connection is setup (at the top of the SQL Editor) or available. So from this
point I assume there needs to be a way to notify the user of the need to do so.
In this case (and given the possible "make hints" be a separate ticket maybe
this is not the route but) I was adding some hints (like adding drivers, new
connections, and "connect" [which results in the existing dialog warning]).
With this in play, then it allows for some basic sql tokens autocompletion
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists