From f6756de3e2e97bf2fbfe1c93ed4a31c8b1c85a21 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 27 Oct 2015 14:33:06 +0100 Subject: [client] Improve focus/idm handling in login window --- .../org/openslx/dozmod/gui/window/LoginWindow.java | 48 +++++++++++++++++----- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'dozentenmodul/src/main/java') 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(); + } + } } /** -- cgit v1.2.3-55-g7522