Skip to content

Commit c613d97

Browse files
committed
Removed duplicated error handling logic to separate method, avoid relying on global state
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent 2212a16 commit c613d97

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

client/src/com/mirth/connect/client/ui/LoginPanel.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
public class LoginPanel extends javax.swing.JFrame {
3535

36-
private Client client;
3736
private static final String ERROR_MESSAGE = "There was an error connecting to the server at the specified address. Please verify that the server is up and running.";
3837
private static LoginPanel instance = null;
3938

@@ -407,6 +406,7 @@ private void passwordActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST
407406
private void loginButtonActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST:event_loginButtonActionPerformed
408407
{// GEN-HEADEREND:event_loginButtonActionPerformed
409408
errorPane.setVisible(false);
409+
LoginPanel loginPanel = this;
410410

411411
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
412412

@@ -415,7 +415,7 @@ public Void doInBackground() {
415415

416416
try {
417417
String server = serverName.getText();
418-
client = new Client(server, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
418+
Client client = new Client(server, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
419419
PlatformUI.SERVER_URL = server;
420420

421421
// Attempt to login
@@ -440,8 +440,8 @@ public Void doInBackground() {
440440
// If SUCCESS or SUCCESS_GRACE_PERIOD
441441
if (loginStatus != null && loginStatus.isSuccess()) {
442442
if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) {
443-
LoginPanel.getInstance().setVisible(false);
444-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
443+
loginPanel.setVisible(false);
444+
loginPanel.initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
445445
}
446446
} else {
447447
// Assume failure unless overridden by a plugin
@@ -459,8 +459,8 @@ public Void doInBackground() {
459459
if (loginStatus != null && loginStatus.isSuccess()) {
460460
errorOccurred = false;
461461
if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) {
462-
LoginPanel.getInstance().setVisible(false);
463-
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
462+
loginPanel.setVisible(false);
463+
loginPanel.initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
464464
}
465465
}
466466
}
@@ -469,25 +469,16 @@ public Void doInBackground() {
469469

470470
if (errorOccurred) {
471471
if (loginStatus != null) {
472-
errorTextArea.setText(loginStatus.getMessage());
472+
setError(loginStatus.getMessage());
473473
} else {
474-
errorTextArea.setText(ERROR_MESSAGE);
474+
setError(ERROR_MESSAGE);
475475
}
476476
}
477477
} catch (Throwable t) {
478-
errorOccurred = true;
479-
errorTextArea.setText(ERROR_MESSAGE);
478+
setError(ERROR_MESSAGE);
480479
t.printStackTrace();
481480
}
482481

483-
if (errorOccurred) {
484-
errorPane.setVisible(true);
485-
loggingIn.setVisible(false);
486-
loginMain.setVisible(true);
487-
loginProgress.setIndeterminate(false);
488-
password.grabFocus();
489-
}
490-
491482
return null;
492483
}
493484

@@ -514,6 +505,15 @@ public void setStatus(String status) {
514505
this.status.setText("Please wait: " + status);
515506
}
516507

508+
public void setError(String status) {
509+
errorTextArea.setText(status);
510+
errorPane.setVisible(true);
511+
loggingIn.setVisible(false);
512+
loginMain.setVisible(true);
513+
loginProgress.setIndeterminate(false);
514+
password.grabFocus();
515+
}
516+
517517
// Variables declaration - do not modify//GEN-BEGIN:variables
518518
private javax.swing.JButton closeButton;
519519
private javax.swing.JScrollPane errorPane;

0 commit comments

Comments
 (0)