From f7cfd0c49c08d3641bb88353390c3f12b9c9abb0 Mon Sep 17 00:00:00 2001 From: Hans Van Akelyen Date: Mon, 4 Nov 2024 10:21:48 +0100 Subject: [PATCH] Do not load keywords when no connection, #4387 Add extra checks and listeners Change highligting color for strings --- .../workflow/actions/sql/ActionSqlDialog.java | 11 +++++++++++ .../waitforsql/ActionWaitForSqlDialog.java | 11 +++++++++++ .../databasejoin/DatabaseJoinDialog.java | 12 ++++++++++++ .../dynamicsqlrow/DynamicSqlRowDialog.java | 11 +++++++++++ .../pipeline/transforms/sql/ExecSqlDialog.java | 11 +++++++++++ .../transforms/tableinput/TableInputDialog.java | 16 ++++++++++++---- .../hop/ui/core/widget/ConditionEditor.java | 2 +- .../widget/highlight/GenericCodeHighlight.java | 2 +- .../ui/core/widget/highlight/JavaHighlight.java | 2 +- .../widget/highlight/JavaScriptHighlight.java | 2 +- .../widget/highlight/SQLValuesHighlight.java | 2 +- 11 files changed, 73 insertions(+), 9 deletions(-) diff --git a/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java b/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java index ddd1d1597b8..e708aad499c 100644 --- a/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java +++ b/plugins/actions/sql/src/main/java/org/apache/hop/workflow/actions/sql/ActionSqlDialog.java @@ -148,6 +148,7 @@ public IAction open() { // Connection line DatabaseMeta databaseMeta = workflowMeta.findDatabase(action.getConnection(), variables); wConnection = addConnectionLine(shell, wName, databaseMeta, null); + wConnection.addListener(SWT.Selection, e -> getSqlReservedWords()); // SQL from file? Label wlSqlFromFile = new Label(shell, SWT.RIGHT); @@ -309,6 +310,16 @@ public IAction open() { } private List getSqlReservedWords() { + // Do not search keywords when connection is empty + if (wConnection.getText() == null || wConnection.getText().isEmpty()) { + return new ArrayList<>(); + } + + // If connection is a variable that can't be resolved + if (variables.resolve(wConnection.getText()).startsWith("${")) { + return new ArrayList<>(); + } + DatabaseMeta databaseMeta = wConnection.loadSelectedElement(); if (databaseMeta == null) { diff --git a/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java b/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java index 0247f3e1071..0894d407040 100644 --- a/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java +++ b/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlDialog.java @@ -182,6 +182,7 @@ public IAction open() { // Connection line DatabaseMeta databaseMeta = workflowMeta.findDatabase(action.getConnection(), variables); wConnection = addConnectionLine(shell, wName, databaseMeta, lsMod); + wConnection.addListener(SWT.Selection, e -> getSqlReservedWords()); // Schema name line wlSchemaname = new Label(shell, SWT.RIGHT); @@ -606,6 +607,16 @@ public void mouseUp(MouseEvent e) { } private List getSqlReservedWords() { + // Do not search keywords when connection is empty + if (wConnection.getText() == null || wConnection.getText().isEmpty()) { + return new ArrayList<>(); + } + + // If connection is a variable that can't be resolved + if (variables.resolve(wConnection.getText()).startsWith("${")) { + return new ArrayList<>(); + } + DatabaseMeta databaseMeta = wConnection.loadSelectedElement(); if (databaseMeta == null) { diff --git a/plugins/transforms/databasejoin/src/main/java/org/apache/hop/pipeline/transforms/databasejoin/DatabaseJoinDialog.java b/plugins/transforms/databasejoin/src/main/java/org/apache/hop/pipeline/transforms/databasejoin/DatabaseJoinDialog.java index 9ec8efa7367..fde4804adb1 100644 --- a/plugins/transforms/databasejoin/src/main/java/org/apache/hop/pipeline/transforms/databasejoin/DatabaseJoinDialog.java +++ b/plugins/transforms/databasejoin/src/main/java/org/apache/hop/pipeline/transforms/databasejoin/DatabaseJoinDialog.java @@ -147,6 +147,7 @@ public String open() { // Connection line wConnection = addConnectionLine(shell, wTransformName, input.getConnection(), lsMod); + wConnection.addListener(SWT.Selection, e -> getSqlReservedWords()); // ICache? Label wlCache = new Label(shell, SWT.RIGHT); @@ -424,6 +425,17 @@ public void widgetSelected(SelectionEvent e) { } private List getSqlReservedWords() { + + // Do not search keywords when connection is empty + if (wConnection.getText() == null || wConnection.getText().isEmpty()) { + return new ArrayList<>(); + } + + // If connection is a variable that can't be resolved + if (variables.resolve(wConnection.getText()).startsWith("${")) { + return new ArrayList<>(); + } + DatabaseMeta databaseMeta = pipelineMeta.findDatabase(input.getConnection(), variables); if (databaseMeta == null) { logError("Database connection not found. Proceding without keywords."); diff --git a/plugins/transforms/dynamicsqlrow/src/main/java/org/apache/hop/pipeline/transforms/dynamicsqlrow/DynamicSqlRowDialog.java b/plugins/transforms/dynamicsqlrow/src/main/java/org/apache/hop/pipeline/transforms/dynamicsqlrow/DynamicSqlRowDialog.java index 3b56af62dc7..f5ada1e8546 100644 --- a/plugins/transforms/dynamicsqlrow/src/main/java/org/apache/hop/pipeline/transforms/dynamicsqlrow/DynamicSqlRowDialog.java +++ b/plugins/transforms/dynamicsqlrow/src/main/java/org/apache/hop/pipeline/transforms/dynamicsqlrow/DynamicSqlRowDialog.java @@ -143,6 +143,7 @@ public String open() { wConnection.select(0); } wConnection.addModifyListener(lsMod); + wConnection.addListener(SWT.Selection, e -> getSqlReservedWords()); // SQLFieldName field Label wlSqlFieldName = new Label(shell, SWT.RIGHT); @@ -370,6 +371,16 @@ public void mouseUp(MouseEvent e) { } private List getSqlReservedWords() { + // Do not search keywords when connection is empty + if (wConnection.getText() == null || wConnection.getText().isEmpty()) { + return new ArrayList<>(); + } + + // If connection is a variable that can't be resolved + if (variables.resolve(wConnection.getText()).startsWith("${")) { + return new ArrayList<>(); + } + DatabaseMeta databaseMeta = pipelineMeta.findDatabase(input.getConnection(), variables); if (databaseMeta == null) { logError("Database connection not found. Proceding without keywords."); diff --git a/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java b/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java index c4cb33cb5e9..6cd56759272 100644 --- a/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java +++ b/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSqlDialog.java @@ -178,6 +178,7 @@ public void widgetSelected(SelectionEvent e) { // Connection line wConnection = addConnectionLine(shell, wTransformName, input.getConnection(), lsMod); wConnection.addSelectionListener(lsSelection); + wConnection.addListener(SWT.Selection, e -> getSqlReservedWords()); // Table line... Label wlSql = new Label(shell, SWT.LEFT); @@ -561,6 +562,16 @@ public void widgetSelected(SelectionEvent e) { } private List getSqlReservedWords() { + // Do not search keywords when connection is empty + if (wConnection.getText() == null || wConnection.getText().isEmpty()) { + return new ArrayList<>(); + } + + // If connection is a variable that can't be resolved + if (variables.resolve(wConnection.getText()).startsWith("${")) { + return new ArrayList<>(); + } + DatabaseMeta databaseMeta = pipelineMeta.findDatabase(input.getConnection(), variables); if (databaseMeta == null) { logError("Database connection not found. Proceding without keywords."); diff --git a/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java b/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java index c9507d22b8c..d2d1276b88a 100644 --- a/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java +++ b/plugins/transforms/tableinput/src/main/java/org/apache/hop/pipeline/transforms/tableinput/TableInputDialog.java @@ -106,10 +106,7 @@ public String open() { PropsUi.setLook(shell); setShellImage(shell, input); - ModifyListener lsMod = - e -> { - input.setChanged(); - }; + ModifyListener lsMod = e -> input.setChanged(); changed = input.hasChanged(); FormLayout formLayout = new FormLayout(); @@ -142,6 +139,7 @@ public String open() { wTransformName.setLayoutData(fdTransformName); wConnection = addConnectionLine(shell, wTransformName, input.getConnection(), lsMod); + wConnection.addListener(SWT.Selection, e -> getSqlReservedWords()); // Some buttons wOk = new Button(shell, SWT.PUSH); @@ -357,6 +355,16 @@ public void mouseUp(MouseEvent e) { } private List getSqlReservedWords() { + // Do not search keywords when connection is empty + if (input.getConnection() == null || input.getConnection().isEmpty()) { + return new ArrayList<>(); + } + + // If connection is a variable that can't be resolved + if (variables.resolve(input.getConnection()).startsWith("${")) { + return new ArrayList<>(); + } + DatabaseMeta databaseMeta = pipelineMeta.findDatabase(input.getConnection(), variables); if (databaseMeta == null) { logError("Database connection not found. Proceding without keywords."); diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/ConditionEditor.java b/ui/src/main/java/org/apache/hop/ui/core/widget/ConditionEditor.java index c9c082d8888..f7b3f8e63f3 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/ConditionEditor.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/ConditionEditor.java @@ -193,7 +193,7 @@ public ConditionEditor(Composite composite, int arg1, Condition co, IRowMeta inp white = GuiResource.getInstance().getColorWhite(); black = GuiResource.getInstance().getColorBlack(); red = GuiResource.getInstance().getColorRed(); - green = GuiResource.getInstance().getColorGreen(); + green = GuiResource.getInstance().getColorDarkGreen(); blue = GuiResource.getInstance().getColorBlue(); gray = GuiResource.getInstance().getColorDarkGray(); diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/GenericCodeHighlight.java b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/GenericCodeHighlight.java index 8768d5d812e..231739933ea 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/GenericCodeHighlight.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/GenericCodeHighlight.java @@ -91,7 +91,7 @@ void initializeColors() { new Color[] { guiResource.getColorBlack(), guiResource.getColorRed(), - guiResource.getColorGreen(), + guiResource.getColorDarkGreen(), guiResource.getColorBlue(), guiResource.getColorOrange() }; diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaHighlight.java b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaHighlight.java index fa9a51e6ddb..fef00d13391 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaHighlight.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaHighlight.java @@ -86,7 +86,7 @@ void initializeColors() { new Color[] { GuiResource.getInstance().getColorBlack(), // black GuiResource.getInstance().getColorRed(), // red - GuiResource.getInstance().getColorGreen(), // green + GuiResource.getInstance().getColorDarkGreen(), // green GuiResource.getInstance().getColorBlue(), // blue GuiResource.getInstance().getColorOrange() // orange }; diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaScriptHighlight.java b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaScriptHighlight.java index 5f38fbaee3e..0252ca3a6d5 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaScriptHighlight.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/JavaScriptHighlight.java @@ -94,7 +94,7 @@ void initializeColors() { new Color[] { guiResource.getColorBlack(), guiResource.getColorRed(), - guiResource.getColorGreen(), + guiResource.getColorDarkGreen(), guiResource.getColorBlue(), guiResource.getColorOrange() }; diff --git a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/SQLValuesHighlight.java b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/SQLValuesHighlight.java index 95bcb5cdde0..581be8fc071 100644 --- a/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/SQLValuesHighlight.java +++ b/ui/src/main/java/org/apache/hop/ui/core/widget/highlight/SQLValuesHighlight.java @@ -102,7 +102,7 @@ void initializeColors() { new Color[] { GuiResource.getInstance().getColorBlack(), // black GuiResource.getInstance().getColorRed(), // red - GuiResource.getInstance().getColorGreen(), // green + GuiResource.getInstance().getColorDarkGreen(), // green GuiResource.getInstance().getColorBlue(), // blue GuiResource.getInstance().getColorMagenta() // SQL Functions / Rose };