diff options
author | Simon Rettberg | 2015-10-27 14:33:06 +0100 |
---|---|---|
committer | Simon Rettberg | 2015-10-27 14:33:06 +0100 |
commit | f6756de3e2e97bf2fbfe1c93ed4a31c8b1c85a21 (patch) | |
tree | 69656c0c2dd2dbf5a85c8aedb0b40ad041d8c6f2 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | |
parent | [*] Implement max connection information in satellite config (diff) | |
download | tutor-module-f6756de3e2e97bf2fbfe1c93ed4a31c8b1c85a21.tar.gz tutor-module-f6756de3e2e97bf2fbfe1c93ed4a31c8b1c85a21.tar.xz tutor-module-f6756de3e2e97bf2fbfe1c93ed4a31c8b1c85a21.zip |
[client] Improve focus/idm handling in login window
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java index d3229a4c..d525062f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java @@ -37,6 +37,7 @@ import org.openslx.dozmod.authentication.TestAccountAuthenticator; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.helper.TextChangeListener; import org.openslx.dozmod.gui.window.layout.LoginWindowLayout; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftActions; @@ -197,15 +198,31 @@ public class LoginWindow extends LoginWindowLayout { } }); - // finally check if we had a saved username - String savedUsername = Config.getUsername(); - if (savedUsername != null && !savedUsername.isEmpty()) { - usernameField.setText(savedUsername); - saveUsernameCheck.setSelected(true); - passwordField.requestFocus(); - } else { - usernameField.requestFocus(); - } + usernameField.getDocument().addDocumentListener(new TextChangeListener() { + @Override + public void changed() { + if (idpCombo.getSelectedIndex() != -1) + return; + String name = usernameField.getText(); + int at = name.indexOf('@'); + if (at == -1) + return; + final int oldCursorPos = usernameField.getCaretPosition(); + String suffix = name.substring(at + 1); + Organization organization = OrganizationCache.find(suffix); + if (organization == null) + return; + final String nameOnly = name.substring(0, at); + idpCombo.setSelectedItem(organization); + Gui.asyncExec(new Runnable() { + @Override + public void run() { + usernameField.setText(nameOnly); + usernameField.setCaretPosition(Math.min(oldCursorPos, nameOnly.length())); + } + }); + } + }); } /** @@ -268,7 +285,7 @@ public class LoginWindow extends LoginWindowLayout { if (loginType == LoginType.ECP && idpCombo.getSelectedIndex() == -1) { Gui.showMessageBox(this, "Bitte wählen Sie ihre Organisation als 'Identity Provider'.", MessageType.ERROR, LOGGER, null); - idpCombo.requestFocus(); + idpCombo.requestFocusInWindow(); return; } // here we only check for the fields @@ -428,6 +445,17 @@ public class LoginWindow extends LoginWindowLayout { loginTypePanel.setEnabled(enable); loginFormPanel.setEnabled(enable); saveUsernameCheck.setEnabled(enable); + if (enable) { + // Do this here, otherwise the focus might not be set + String savedUsername = Config.getUsername(); + if (savedUsername != null && !savedUsername.isEmpty()) { + usernameField.setText(savedUsername); + saveUsernameCheck.setSelected(true); + passwordField.requestFocusInWindow(); + } else { + usernameField.requestFocusInWindow(); + } + } } /** |