You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/12/04 17:58:45 UTC

[GitHub] [netbeans] matthiasblaesing commented on a change in pull request #3074: [NETBEANS-189] Updates for Sql autocomplete

matthiasblaesing commented on a change in pull request #3074:
URL: https://github.com/apache/netbeans/pull/3074#discussion_r762449834



##########
File path: ide/db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java
##########
@@ -41,39 +40,61 @@
  * @author Andrei Badea
  */
 public class SQLCompletionProvider implements CompletionProvider {
-
+    @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;
-            }
+
             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) {
+        // XXX: Check if "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;
         }
+        
+        // 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;
+            SQLExecutionBaseAction.notifyNoDatabaseConnection();
         }
-        if (dbconn.getJDBCConnection() == null) {
+
+        // check and notify if DB connection is inactive
+        if (dbconn != null && dbconn.getJDBCConnection() == null) {
             String message = NbBundle.getMessage(SQLCompletionProvider.class, "MSG_NotConnected");
             StatusDisplayer.getDefault().setStatusText(message);
-            return 0;
-        }
+            SQLExecutionBaseAction.notifyNoDatabaseConnection();            

Review comment:
       This (and the change in line 88) causes excessive dialogs to popup. In the case of line 92, you even get two dialogs (one telling you there is no connection and the second querying the user credentials).




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists