Skip to content

Commit

Permalink
Merge pull request #4387 from xdelox/4386-styled-text-comp
Browse files Browse the repository at this point in the history
Enable Code Highlighting
  • Loading branch information
hansva authored Oct 29, 2024
2 parents f16e087 + 00cd66e commit 44f8fbb
Show file tree
Hide file tree
Showing 20 changed files with 4,484 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,31 @@

package org.apache.hop.workflow.actions.sql;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopDatabaseException;
import org.apache.hop.core.logging.LogChannel;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
import org.apache.hop.ui.core.widget.MetaSelectionLine;
import org.apache.hop.ui.core.widget.SQLStyledTextComp;
import org.apache.hop.ui.core.widget.StyledTextComp;
import org.apache.hop.ui.core.widget.TextComposite;
import org.apache.hop.ui.core.widget.TextVar;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.apache.hop.ui.util.EnvironmentUtils;
import org.apache.hop.ui.workflow.action.ActionDialog;
import org.apache.hop.ui.workflow.dialog.WorkflowDialog;
import org.apache.hop.workflow.WorkflowMeta;
Expand Down Expand Up @@ -67,7 +79,7 @@ public class ActionSqlDialog extends ActionDialog {

private Label wlSql;

private StyledTextComp wSql;
private TextComposite wSql;

private Label wlPosition;

Expand Down Expand Up @@ -266,8 +278,12 @@ public IAction open() {
wlSql.setLayoutData(fdlSql);

wSql =
new StyledTextComp(
action, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
EnvironmentUtils.getInstance().isWeb()
? new StyledTextComp(
action, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)
: new SQLStyledTextComp(
action, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
wSql.addLineStyleListener(getSqlReservedWords());
PropsUi.setLook(wSql, Props.WIDGET_STYLE_FIXED);
FormData fdSql = new FormData();
fdSql.left = new FormAttachment(0, 0);
Expand All @@ -292,6 +308,43 @@ public IAction open() {
return action;
}

private List<String> getSqlReservedWords() {
DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
if (databaseMeta == null) {

return new ArrayList<>();
}
Database db = new Database(loggingObject, variables, databaseMeta);
DatabaseMetaData databaseMetaData = null;
try {
db.connect();
databaseMetaData = db.getDatabaseMetaData();
if (databaseMetaData == null) {
LogChannel.UI.logError("Couldn't get database metadata");
return new ArrayList<>();
}
List<String> sqlKeywords = new ArrayList<>();
try {
final ResultSet functionsResultSet = databaseMetaData.getFunctions(null, null, null);
while (functionsResultSet.next()) {
sqlKeywords.add(functionsResultSet.getString("FUNCTION_NAME"));
}
sqlKeywords.addAll(Arrays.asList(databaseMetaData.getSQLKeywords().split(",")));
} catch (SQLException e) {
LogChannel.UI.logError(
"Couldn't extract keywords from database metadata. Proceding without them.");
}
return sqlKeywords;
} catch (HopDatabaseException e) {
LogChannel.UI.logError(
"Couldn't extract keywords from database metadata. Proceding without them.");
return new ArrayList<>();
} finally {
db.disconnect();
db.close();
}
}

public void setPosition() {
int lineNumber = wSql.getLineNumber();
int columnNumber = wSql.getColumnNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@

package org.apache.hop.workflow.actions.waitforsql;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopDatabaseException;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.logging.LogChannel;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.util.Utils;
Expand All @@ -32,9 +40,12 @@
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
import org.apache.hop.ui.core.widget.MetaSelectionLine;
import org.apache.hop.ui.core.widget.SQLStyledTextComp;
import org.apache.hop.ui.core.widget.StyledTextComp;
import org.apache.hop.ui.core.widget.TextComposite;
import org.apache.hop.ui.core.widget.TextVar;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.apache.hop.ui.util.EnvironmentUtils;
import org.apache.hop.ui.workflow.action.ActionDialog;
import org.apache.hop.ui.workflow.dialog.WorkflowDialog;
import org.apache.hop.workflow.WorkflowMeta;
Expand Down Expand Up @@ -87,7 +98,7 @@ public class ActionWaitForSqlDialog extends ActionDialog {

private Label wlSql;

private StyledTextComp wSql;
private TextComposite wSql;

private Label wlPosition;

Expand Down Expand Up @@ -512,8 +523,16 @@ public void widgetSelected(SelectionEvent e) {
wbSqlTable.addListener(SWT.Selection, e -> getSql());

wSql =
new StyledTextComp(
action, wCustomGroup, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
EnvironmentUtils.getInstance().isWeb()
? new StyledTextComp(
action,
wCustomGroup,
SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)
: new SQLStyledTextComp(
action,
wCustomGroup,
SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
wSql.addLineStyleListener(getSqlReservedWords());
PropsUi.setLook(wSql, Props.WIDGET_STYLE_FIXED);
wSql.addModifyListener(lsMod);
FormData fdSql = new FormData();
Expand Down Expand Up @@ -586,6 +605,43 @@ public void mouseUp(MouseEvent e) {
return action;
}

private List<String> getSqlReservedWords() {
DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
if (databaseMeta == null) {

return new ArrayList<>();
}
Database db = new Database(loggingObject, variables, databaseMeta);
DatabaseMetaData databaseMetaData = null;
try {
db.connect();
databaseMetaData = db.getDatabaseMetaData();
if (databaseMetaData == null) {
LogChannel.UI.logError("Couldn't get database metadata");
return new ArrayList<>();
}
List<String> sqlKeywords = new ArrayList<>();
try {
final ResultSet functionsResultSet = databaseMetaData.getFunctions(null, null, null);
while (functionsResultSet.next()) {
sqlKeywords.add(functionsResultSet.getString("FUNCTION_NAME"));
}
sqlKeywords.addAll(Arrays.asList(databaseMetaData.getSQLKeywords().split(",")));
} catch (SQLException e) {
LogChannel.UI.logError(
"Couldn't extract keywords from database metadata. Proceding without them.");
}
return sqlKeywords;
} catch (HopDatabaseException e) {
LogChannel.UI.logError(
"Couldn't extract keywords from database metadata. Proceding without them.");
return new ArrayList<>();
} finally {
db.disconnect();
db.close();
}
}

private void getSql() {
DatabaseMeta databaseMeta = this.workflowMeta.findDatabase(wConnection.getText(), variables);
if (databaseMeta != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@

package org.apache.hop.pipeline.transforms.databasejoin;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopDatabaseException;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.value.ValueMetaFactory;
Expand All @@ -37,9 +43,12 @@
import org.apache.hop.ui.core.dialog.MessageBox;
import org.apache.hop.ui.core.widget.ColumnInfo;
import org.apache.hop.ui.core.widget.MetaSelectionLine;
import org.apache.hop.ui.core.widget.SQLStyledTextComp;
import org.apache.hop.ui.core.widget.StyledTextComp;
import org.apache.hop.ui.core.widget.TableView;
import org.apache.hop.ui.core.widget.TextComposite;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.apache.hop.ui.util.EnvironmentUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
Expand All @@ -64,7 +73,7 @@ public class DatabaseJoinDialog extends BaseTransformDialog {

private MetaSelectionLine<DatabaseMeta> wConnection;

private StyledTextComp wSql;
private TextComposite wSql;

private Text wLimit;

Expand Down Expand Up @@ -193,8 +202,12 @@ public void widgetSelected(SelectionEvent e) {
wlSql.setLayoutData(fdlSql);

wSql =
new StyledTextComp(
variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
EnvironmentUtils.getInstance().isWeb()
? new StyledTextComp(
variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)
: new SQLStyledTextComp(
variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
wSql.addLineStyleListener(getSqlReservedWords());
PropsUi.setLook(wSql, Props.WIDGET_STYLE_FIXED);
wSql.addModifyListener(lsMod);
FormData fdSql = new FormData();
Expand Down Expand Up @@ -410,6 +423,41 @@ public void widgetSelected(SelectionEvent e) {
return transformName;
}

private List<String> getSqlReservedWords() {
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(input.getConnection(), variables);
if (databaseMeta == null) {
logError("Database connection not found. Proceding without keywords.");
return new ArrayList<>();
}
Database db = new Database(loggingObject, variables, databaseMeta);
DatabaseMetaData databaseMetaData = null;
try {
db.connect();
databaseMetaData = db.getDatabaseMetaData();
if (databaseMetaData == null) {
logError("Couldn't get database metadata");
return new ArrayList<>();
}
List<String> sqlKeywords = new ArrayList<>();
try {
final ResultSet functionsResultSet = databaseMetaData.getFunctions(null, null, null);
while (functionsResultSet.next()) {
sqlKeywords.add(functionsResultSet.getString("FUNCTION_NAME"));
}
sqlKeywords.addAll(Arrays.asList(databaseMetaData.getSQLKeywords().split(",")));
} catch (SQLException e) {
logError("Couldn't extract keywords from database metadata. Proceding without them.");
}
return sqlKeywords;
} catch (HopDatabaseException e) {
logError("Couldn't extract keywords from database metadata. Proceding without them.");
return new ArrayList<>();
} finally {
db.disconnect();
db.close();
}
}

private void enableFields() {
wCacheSize.setEnabled(wCache.getSelection());
wlCacheSize.setEnabled(wCache.getSelection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@

package org.apache.hop.pipeline.transforms.dynamicsqlrow;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopDatabaseException;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.util.Utils;
Expand All @@ -31,8 +39,11 @@
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
import org.apache.hop.ui.core.widget.MetaSelectionLine;
import org.apache.hop.ui.core.widget.SQLStyledTextComp;
import org.apache.hop.ui.core.widget.StyledTextComp;
import org.apache.hop.ui.core.widget.TextComposite;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.apache.hop.ui.util.EnvironmentUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusAdapter;
Expand Down Expand Up @@ -61,7 +72,7 @@ public class DynamicSqlRowDialog extends BaseTransformDialog {

private MetaSelectionLine<DatabaseMeta> wConnection;

private StyledTextComp wSql;
private TextComposite wSql;

private Text wLimit;

Expand Down Expand Up @@ -291,8 +302,12 @@ public void widgetSelected(SelectionEvent e) {
wlSql.setLayoutData(fdlSql);

wSql =
new StyledTextComp(
variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
EnvironmentUtils.getInstance().isWeb()
? new StyledTextComp(
variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)
: new SQLStyledTextComp(
variables, shell, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
wSql.addLineStyleListener(getSqlReservedWords());
PropsUi.setLook(wSql, Props.WIDGET_STYLE_FIXED);
FormData fdSql = new FormData();
fdSql.left = new FormAttachment(0, 0);
Expand Down Expand Up @@ -354,6 +369,41 @@ public void mouseUp(MouseEvent e) {
return transformName;
}

private List<String> getSqlReservedWords() {
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(input.getConnection(), variables);
if (databaseMeta == null) {
logError("Database connection not found. Proceding without keywords.");
return new ArrayList<>();
}
Database db = new Database(loggingObject, variables, databaseMeta);
DatabaseMetaData databaseMetaData = null;
try {
db.connect();
databaseMetaData = db.getDatabaseMetaData();
if (databaseMetaData == null) {
logError("Couldn't get database metadata");
return new ArrayList<>();
}
List<String> sqlKeywords = new ArrayList<>();
try {
final ResultSet functionsResultSet = databaseMetaData.getFunctions(null, null, null);
while (functionsResultSet.next()) {
sqlKeywords.add(functionsResultSet.getString("FUNCTION_NAME"));
}
sqlKeywords.addAll(Arrays.asList(databaseMetaData.getSQLKeywords().split(",")));
} catch (SQLException e) {
logError("Couldn't extract keywords from database metadata. Proceding without them.");
}
return sqlKeywords;
} catch (HopDatabaseException e) {
logError("Couldn't extract keywords from database metadata. Proceding without them.");
return new ArrayList<>();
} finally {
db.disconnect();
db.close();
}
}

public void setPosition() {
int lineNumber = wSql.getLineNumber();
int columnNumber = wSql.getColumnNumber();
Expand Down
Loading

0 comments on commit 44f8fbb

Please sign in to comment.