Skip to content

Commit

Permalink
Do not load keywords when no connection, apache#4387
Browse files Browse the repository at this point in the history
Add extra checks and listeners

Change highligting color for strings
  • Loading branch information
hansva committed Nov 4, 2024
1 parent 44f8fbb commit f7cfd0c
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -309,6 +310,16 @@ public IAction open() {
}

private List<String> 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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -606,6 +607,16 @@ public void mouseUp(MouseEvent e) {
}

private List<String> 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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -424,6 +425,17 @@ public void widgetSelected(SelectionEvent e) {
}

private List<String> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -370,6 +371,16 @@ public void mouseUp(MouseEvent e) {
}

private List<String> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -561,6 +562,16 @@ public void widgetSelected(SelectionEvent e) {
}

private List<String> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -357,6 +355,16 @@ public void mouseUp(MouseEvent e) {
}

private List<String> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void initializeColors() {
new Color[] {
guiResource.getColorBlack(),
guiResource.getColorRed(),
guiResource.getColorGreen(),
guiResource.getColorDarkGreen(),
guiResource.getColorBlue(),
guiResource.getColorOrange()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void initializeColors() {
new Color[] {
guiResource.getColorBlack(),
guiResource.getColorRed(),
guiResource.getColorGreen(),
guiResource.getColorDarkGreen(),
guiResource.getColorBlue(),
guiResource.getColorOrange()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit f7cfd0c

Please sign in to comment.