This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new b4df6a9398 Keep connection details when the connection type changes
(#8424)
b4df6a9398 is described below
commit b4df6a9398fff640a63e4fce7b35e9a538711c14
Author: Frank Skorgen <[email protected]>
AuthorDate: Wed Sep 16 20:39:24 2026 +0200
Keep connection details when the connection type changes (#8424)
* Fix #8357: keep connection details when the connection type changes
* Add a Default port button to the database connection editor, for #8357
* Address review: port only for types that show the field, wire the button
into the widget maps
---
.../hop/ui/core/database/DatabaseMetaEditor.java | 79 +++++++++++++++++++++-
.../database/messages/messages_en_US.properties | 1 +
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git
a/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
b/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
index 2bdcda2614..c3da2ee969 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
@@ -449,6 +449,7 @@ public class DatabaseMetaEditor extends
MetadataEditor<DatabaseMeta> {
guiCompositeWidgets.setWidgetsListener(createWidgetsListener());
addCompositeWidgetsUsernamePassword();
+ addDefaultPortButton();
// manual URL field - only create if not excluded
//
@@ -528,6 +529,41 @@ public class DatabaseMetaEditor extends
MetadataEditor<DatabaseMeta> {
: Optional.empty();
}
+ private void addDefaultPortButton() {
+ Control portControl =
guiCompositeWidgets.getWidgetsMap().get(BaseDatabaseMeta.ELEMENT_ID_PORT);
+ if (portControl == null
+ || portControl.isDisposed()
+ || !(portControl.getLayoutData() instanceof FormData fdPort)
+ || getMetadata().getIDatabase().getDefaultDatabasePort() <= 0) {
+ return;
+ }
+
+ Button wbDefaultPort = new Button(portControl.getParent(), SWT.PUSH);
+ wbDefaultPort.setText(BaseMessages.getString(PKG,
"DatabaseDialog.button.DefaultPort"));
+ PropsUi.setLook(wbDefaultPort);
+ FormData fdDefaultPort = new FormData();
+ fdDefaultPort.right = new FormAttachment(100, 0);
+ fdDefaultPort.top = new FormAttachment(portControl, 0, SWT.CENTER);
+ wbDefaultPort.setLayoutData(fdDefaultPort);
+ fdPort.right = new FormAttachment(wbDefaultPort, -PropsUi.getMargin());
+
+ // The action widget of the port row, so that hiding or collapsing the row
takes it along
+
guiCompositeWidgets.getActionWidgetsMap().put(BaseDatabaseMeta.ELEMENT_ID_PORT,
wbDefaultPort);
+
+ wbDefaultPort.addListener(SWT.Selection, event -> setDefaultPort());
+ }
+
+ private void setDefaultPort() {
+ int defaultPort = getMetadata().getIDatabase().getDefaultDatabasePort();
+ Control portControl =
guiCompositeWidgets.getWidgetsMap().get(BaseDatabaseMeta.ELEMENT_ID_PORT);
+ if (defaultPort <= 0 || portControl == null || portControl.isDisposed()) {
+ return;
+ }
+ if (portControl instanceof TextVar portVar) {
+ portVar.setText(Integer.toString(defaultPort));
+ }
+ }
+
private void addCompositeWidgetsUsernamePassword() {
// Add username and password to the mix so folks can enable/disable those
//
@@ -583,7 +619,12 @@ public class DatabaseMetaEditor extends
MetadataEditor<DatabaseMeta> {
// Get possible information from the metadata map (from previous work)
//
-
databaseMeta.setIDatabase(metaMap.get(databaseMeta.getIDatabase().getClass()));
+ IDatabase enteredDatabase = databaseMeta.getIDatabase();
+ IDatabase savedDatabase = metaMap.get(enteredDatabase.getClass());
+ if (savedDatabase != null) {
+ databaseMeta.setIDatabase(savedDatabase);
+ copyEnteredFields(enteredDatabase, savedDatabase);
+ }
// Remove existing children
//
@@ -602,6 +643,10 @@ public class DatabaseMetaEditor extends
MetadataEditor<DatabaseMeta> {
null);
guiCompositeWidgets.setWidgetsListener(createWidgetsListener());
addCompositeWidgetsUsernamePassword();
+ addDefaultPortButton();
+ if (savedDatabase != null) {
+ copyEnteredPort(enteredDatabase, savedDatabase);
+ }
// Put the data back
//
@@ -612,6 +657,31 @@ public class DatabaseMetaEditor extends
MetadataEditor<DatabaseMeta> {
busyChangingConnectionType.set(false);
}
+ private void copyEnteredFields(IDatabase entered, IDatabase target) {
+ target.setAccessType(entered.getAccessType());
+ target.setHostname(entered.getHostname());
+ target.setDatabaseName(entered.getDatabaseName());
+ target.setUsername(entered.getUsername());
+ target.setPassword(entered.getPassword());
+ target.setServername(entered.getServername());
+ target.setDataTablespace(entered.getDataTablespace());
+ target.setIndexTablespace(entered.getIndexTablespace());
+ }
+
+ // Only a type that shows the port field can take the entered port: the ones
that hide it build
+ // their URL from the default and leave no way to correct a copied value. An
empty port falls
+ // back to the new default rather than to the cached one, which the user may
have cleared.
+ private void copyEnteredPort(IDatabase entered, IDatabase target) {
+ Control portControl =
guiCompositeWidgets.getWidgetsMap().get(BaseDatabaseMeta.ELEMENT_ID_PORT);
+ if (portControl != null && StringUtils.isNotEmpty(entered.getPort())) {
+ target.setPort(entered.getPort());
+ } else if (target.getDefaultDatabasePort() > 0) {
+ target.setPort(Integer.toString(target.getDefaultDatabasePort()));
+ } else {
+ target.setPort("");
+ }
+ }
+
private void addAdvancedTab() {
CTabItem wAdvancedTab = new CTabItem(wTabFolder, SWT.NONE);
@@ -1097,6 +1167,13 @@ public class DatabaseMetaEditor extends
MetadataEditor<DatabaseMeta> {
//
guiCompositeWidgets.enableWidgets(
getMetadata().getIDatabase(),
DatabaseMeta.GUI_PLUGIN_ELEMENT_PARENT_ID, !manualUrl);
+
+ // enableWidgets() covers labels and widgets, not action controls
+ Control defaultPortButton =
+
guiCompositeWidgets.getActionWidgetsMap().get(BaseDatabaseMeta.ELEMENT_ID_PORT);
+ if (defaultPortButton != null && !defaultPortButton.isDisposed()) {
+ defaultPortButton.setEnabled(!manualUrl);
+ }
}
private void test() {
diff --git
a/ui/src/main/resources/org/apache/hop/ui/core/database/messages/messages_en_US.properties
b/ui/src/main/resources/org/apache/hop/ui/core/database/messages/messages_en_US.properties
index 6ae91017b7..9712bf7535 100644
---
a/ui/src/main/resources/org/apache/hop/ui/core/database/messages/messages_en_US.properties
+++
b/ui/src/main/resources/org/apache/hop/ui/core/database/messages/messages_en_US.properties
@@ -16,6 +16,7 @@
#
DatabaseDialog.AdvancedTab.title=Advanced
+DatabaseDialog.button.DefaultPort=Default port
DatabaseDialog.button.DownloadDriver=Download driver
DatabaseDialog.button.Explore=Explore
DatabaseDialog.button.OpenInDatabase=Open in Database