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/08/07 15:01:13 UTC
[GitHub] [netbeans] ebresie commented on a change in pull request #3074: [NETBEANS-189] Updates for Sql autocomplete
ebresie commented on a change in pull request #3074:
URL: https://github.com/apache/netbeans/pull/3074#discussion_r684642790
##########
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 if DB connection is active
+ if (dbconn != null && dbconn.getJDBCConnection() == null) {
Review comment:
There is two parts to this,
(1) checks to ensure the "dbconn" is set and not null and
(2) check if a DB Connection is selected from the pull down selection list. If it's not available then a warning dialog opens indicating "No database connection is selected. Please select a connection inthe Connection combo box in the editor toolbar." This is the same dialog that use to open previous when attempting any autocomplete without a connection (which prevented any autocompletion). Now it only shows when needed (like when attempting to execute an sql expression)/
Would a clarification of the comment like the below be acceptable?
// check if DB connection is selected
--
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