From 78e55ec0f32e25d0be3bf443529e24b6db80aceb Mon Sep 17 00:00:00 2001 From: Ralf Wisser Date: Wed, 4 Dec 2024 10:56:39 +0100 Subject: [PATCH] prevent OutOfIndex exception --- .../net/sf/jailer/ui/DbConnectionDialog.java | 8 ++++-- .../sf/jailer/ui/databrowser/DataBrowser.java | 27 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/gui/net/sf/jailer/ui/DbConnectionDialog.java b/src/main/gui/net/sf/jailer/ui/DbConnectionDialog.java index 0741d0dd7..9ab776a82 100644 --- a/src/main/gui/net/sf/jailer/ui/DbConnectionDialog.java +++ b/src/main/gui/net/sf/jailer/ui/DbConnectionDialog.java @@ -342,7 +342,7 @@ public void select(ConnectionInfo ci) { } } - public boolean connectSilent(ConnectionInfo ci) { + public boolean connectSilent(ConnectionInfo ci, Runnable[] afterConnectAction) { if (connectionsTable.getModel().getRowCount() > 0) { int cRI = -1; for (int i = 0; i < connectionList.size(); ++i) { @@ -376,7 +376,11 @@ public boolean connectSilent(ConnectionInfo ci) { } onConnect(currentConnection); if (dataModelChanger != null) { - dataModelChanger.afterConnect(currentConnection); + if (afterConnectAction != null) { + afterConnectAction[0] = () -> dataModelChanger.afterConnect(currentConnection); + } else { + dataModelChanger.afterConnect(currentConnection); + } } if (currentConnection.alias != null && !"".equals(currentConnection.alias)) { UISettings.addRecentConnectionAliases(currentConnection.alias); diff --git a/src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java b/src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java index 04c778397..7ffc51afc 100644 --- a/src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java +++ b/src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java @@ -1783,13 +1783,23 @@ public void actionPerformed(ActionEvent e) { private void connect(DataBrowser dataBrowser, Object o) { ConnectionInfo oldCurrentConnectionInfo = currentConnectionInfo; - if (dataBrowser.dbConnectionDialog.connectSilent((ConnectionInfo) o)) { + Runnable[] afterConnectAction = new Runnable[1]; + if (dataBrowser.dbConnectionDialog.connectSilent((ConnectionInfo) o, afterConnectAction)) { try { - if (!dataBrowser.setConnection(dataBrowser.dbConnectionDialog)) { + boolean ok; + BrowserContentPane.suppressReloadStatic = true; + try { + ok = dataBrowser.setConnection(dataBrowser.dbConnectionDialog); + } finally { + BrowserContentPane.suppressReloadStatic = false; + } + if (!ok) { if (oldCurrentConnectionInfo != null) { - dataBrowser.dbConnectionDialog.connectSilent(oldCurrentConnectionInfo); + dataBrowser.dbConnectionDialog.connectSilent(oldCurrentConnectionInfo, null); updateModelNavigation(); } + } else { + afterConnectAction[0].run(); } } catch (Exception ex) { UIUtil.showException(dataBrowser, "Error", ex); @@ -1954,12 +1964,9 @@ public void change(String dataModelSubfolder) { if (new File(sessionFile).exists()) { afterReconnectAction = () -> { try { - BrowserContentPane.suppressReloadStatic = true; desktop.restoreSession(null, DataBrowser.this, sessionFile, true); } catch (Exception e) { LogUtil.warn(e); - } finally { - BrowserContentPane.suppressReloadStatic = false; } }; } @@ -4269,11 +4276,19 @@ private void reconnectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {/ dbConnectionDialog.select(lastConnectionInfo); } if (dbConnectionDialog.connect("Reconnect", true)) { + BrowserContentPane.suppressReloadStatic = true; // TODO try { setConnection(dbConnectionDialog); } catch (Exception e) { UIUtil.showException(this, "Error", e, session); + } finally { + BrowserContentPane.suppressReloadStatic = false; } + UIUtil.invokeLater(() -> { + for (RowBrowser rb : desktop.getRootBrowsers(false)) { + rb.browserContentPane.reloadRows(); + } + }); } } }// GEN-LAST:event_reconnectMenuItemActionPerformed