Skip to content

Commit

Permalink
prevent OutOfIndex exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Wisser committed Dec 4, 2024
1 parent 87ce2cb commit 78e55ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/main/gui/net/sf/jailer/ui/DbConnectionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 21 additions & 6 deletions src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
};
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 78e55ec

Please sign in to comment.