diff options
| author | Jonathan Bauer | 2015-07-10 13:32:06 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-07-10 13:32:06 +0200 |
| commit | d766c3f3962a865a2f025bdf9f3ff3b7f158ef5b (patch) | |
| tree | 8d5794de6cd1e4f345928f6a796aa26663566312 /dozentenmodul/src/main/java/org | |
| parent | [client] Fix mltk repo entry in pom.xml (diff) | |
| download | tutor-module-d766c3f3962a865a2f025bdf9f3ff3b7f158ef5b.tar.gz tutor-module-d766c3f3962a865a2f025bdf9f3ff3b7f158ef5b.tar.xz tutor-module-d766c3f3962a865a2f025bdf9f3ff3b7f158ef5b.zip | |
[client] fetch idop list in a separate thread
Diffstat (limited to 'dozentenmodul/src/main/java/org')
| -rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java | 101 |
1 files changed, 68 insertions, 33 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 6896835a..7c57b2c9 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 @@ -51,38 +51,30 @@ public class LoginWindow extends LoginWindowLayout { // call the constructor of the superclass super(mainShell); - // entries in the combo - List<Organization> orgs = OrganizationCache.getAll(); - if (orgs == null) { - LOGGER.error("No organizations received from the cache."); - idpCombo.add("No entries"); - } - - // all fine, lets sort it - Collections.sort(orgs, new Comparator<Organization>() { - public int compare(Organization o1, Organization o2) { - return o1.getDisplayName().compareTo(o2.getDisplayName()); - } - }); + // fetch the list of the identity providers as an async Thread + // else the GUI is blocked until this is done. + idpCombo.add("Initialisiere..."); + idpCombo.select(0); + idpCombo.setEnabled(false); + new Thread() { + List<Organization> orgs = null; + public void run() { + try { + Thread.sleep(2000); + orgs = OrganizationCache.getAll(); + } catch (Exception e) { + LoginWindow.LOGGER.error("Error during execution: ", e); + } + // now send the organisations back to the LoginWindow + // through populateIdpCombo() + MainWindow.getDisplay().asyncExec(new Runnable() { + public void run() { + populateIdpCombo(orgs); + } + }); + } + }.start(); - // now check if we had a saved identity provider - String savedOrganizationId = Config.getIdentityProvider(); - // add only organizations which have an ECP URL to the combobox - for (Organization o : orgs) { - if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) - continue; - LOGGER.debug("Adding: " + o.toString()); - idpCombo.add(o.displayName); - idpCombo.setData(o.displayName, o); - if (savedOrganizationId != null && !savedOrganizationId.isEmpty() - && savedOrganizationId.equals(o.getOrganizationId())) - // select the organization we just added, this seems kinda bad - is there a better way? - idpCombo.select(idpCombo.getItemCount() - 1); - //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer - } - // if no organization was saved, none is selected, so select the first one in the combobox - if (idpCombo.getSelectionIndex() == -1) - idpCombo.select(0); // check if we had saved an authentication method String savedAuthMethod = Config.getAuthenticationMethod(); if (savedAuthMethod != null && !savedAuthMethod.isEmpty()) { @@ -94,8 +86,11 @@ public class LoginWindow extends LoginWindowLayout { } else { authButtons[savedLoginType.getId()].setSelection(true); loginType = savedLoginType; - idpText.setVisible(savedLoginType == LOGIN_TYPE.BWIDM); - idpCombo.setVisible(savedLoginType == LOGIN_TYPE.BWIDM); + // enable the IDP combo only if we actually have items in it + if (idpCombo.getItemCount() > 1) { + idpText.setVisible(savedLoginType == LOGIN_TYPE.BWIDM); + idpCombo.setVisible(savedLoginType == LOGIN_TYPE.BWIDM); + } } } else { // default value for LOGIN_TYPE is BWIDM @@ -178,6 +173,46 @@ public class LoginWindow extends LoginWindowLayout { }); } + public void populateIdpCombo(List<Organization> orgs) { + // always clearup the list first + idpCombo.removeAll(); + + // sanity checks on orgs + if (orgs == null) { + LOGGER.error("No organizations received from the cache."); + idpCombo.add("No entries"); + return; + } + + // all fine, lets sort it + Collections.sort(orgs, new Comparator<Organization>() { + public int compare(Organization o1, Organization o2) { + return o1.getDisplayName().compareTo(o2.getDisplayName()); + } + }); + + // now check if we had a saved identity provider + String savedOrganizationId = Config.getIdentityProvider(); + // add only organizations which have an ECP URL to the combobox + for (Organization o : orgs) { + if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) + continue; + LOGGER.debug("Adding: " + o.toString()); + idpCombo.add(o.displayName); + idpCombo.setData(o.displayName, o); + if (savedOrganizationId != null && !savedOrganizationId.isEmpty() + && savedOrganizationId.equals(o.getOrganizationId())) + // select the organization we just added, this seems kinda bad - is there a better way? + idpCombo.select(idpCombo.getItemCount() - 1); + //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer + } + // if no organization was saved, none is selected, so select the first one in the combobox + if (idpCombo.getSelectionIndex() == -1) + idpCombo.select(0); + // finally reenable it + idpCombo.setEnabled(true); + } + /** * Saves various user choices to the config file. * This gets triggered when the login button is activated. |
