diff --git a/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/App.java b/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/App.java index 3bd4cb1c..30d1ac84 100644 --- a/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/App.java +++ b/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/App.java @@ -121,6 +121,7 @@ else if (Initializer.getSettingsDirectory() == null) { Platform.runLater(() -> { primaryStage.setWidth(width + 1); }); + // Let the UI thread catch up and redraw try { Thread.sleep(100); } catch (InterruptedException ex) { @@ -130,7 +131,6 @@ else if (Initializer.getSettingsDirectory() == null) { primaryStage.setWidth(width); }); }); - }); primaryStage.show(); diff --git a/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/javafx/AppPaneController.java b/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/javafx/AppPaneController.java index 2c8ec229..1c392f16 100644 --- a/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/javafx/AppPaneController.java +++ b/org.mbari.vars.ui/src/main/java/org/mbari/vars/ui/javafx/AppPaneController.java @@ -499,6 +499,20 @@ public PopOver getOpenPopOver() { return openPopOver; } + private void setUser(String username) { + if (username != null) { + toolBox.getServices() + .getUserService() + .findAllUsers() + .thenAccept(users -> { + Optional opt = users.stream() + .filter(u -> u.getUsername().equals(username)) + .findFirst(); + opt.ifPresent(user -> toolBox.getEventBus().send(new UserChangedEvent(user))); + }); + } + } + public ComboBox getUsersComboBox() { if (usersComboBox == null) { @@ -520,26 +534,30 @@ public ComboBox getUsersComboBox() { ObservableList items = FXCollections.observableList(newItems); usersComboBox.setItems(items); usersComboBox.getSelectionModel().select(user.getUsername()); + setUser(user.getUsername()); }); }); - // When a username is selected send a change event - usersComboBox.getSelectionModel() - .selectedItemProperty() - .addListener((obs, oldv, newv) -> { - if (newv != null) { - toolBox.getServices() - .getUserService() - .findAllUsers() - .thenAccept(users -> { - Optional opt = users.stream() - .filter(u -> u.getUsername().equals(newv)) - .findFirst(); - opt.ifPresent(user -> eventBus.send(new UserChangedEvent(user))); - }); + usersComboBox.showingProperty().addListener((obs, oldv, newv) -> { + if (newv != null && !newv) { + setUser(usersComboBox.getSelectionModel().getSelectedItem()); } }); + usersComboBox.onHiddenProperty().addListener((obs, oldv, newv) -> { + setUser(usersComboBox.getSelectionModel().getSelectedItem()); + }); + + + // When a username is selected send a change event +// usersComboBox.getSelectionModel() +// .selectedItemProperty() +// .addListener((obs, oldv, newv) -> { +// if (newv != null && !usersComboBox.isShowing()) { +// setUser(newv); +// } +// }); + loadUsers(); // Listen for new services event and update users after service is changed. @@ -571,6 +589,7 @@ private void loadUsers() { String defaultUser = System.getProperty("user.name"); if (usernames.contains(defaultUser)) { usersComboBox.getSelectionModel().select(defaultUser); + setUser(defaultUser); } }); });