In the Google Login panel, bubble the active user to the top of the list.
Change-Id: Id0272b3bb04287675b9ad182609d484562428047
diff --git a/login/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java b/login/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java
index 6536283..a98ce85 100644
--- a/login/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java
+++ b/login/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java
@@ -59,6 +59,7 @@
private JButton signOutButton;
private JButton addAccountButton;
private boolean valueChanged = false;
+ private boolean ignoreSelection = false;
public GoogleLoginUsersPanel() {
super(new BorderLayout());
@@ -150,7 +151,7 @@
// Active user
boolean inPlayUrl = usersListCellRenderer.inPlayConsoleUrl(mouseEvent.getPoint(), index);
boolean inCloudUrl = usersListCellRenderer.inCloudConsoleUrl(mouseEvent.getPoint(), index);
- if(inPlayUrl || inCloudUrl){
+ if (inPlayUrl || inCloudUrl) {
list.setCursor(new Cursor(Cursor.HAND_CURSOR));
} else {
list.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
@@ -223,6 +224,9 @@
//This method is required by ListSelectionListener.
@Override
public void valueChanged(ListSelectionEvent e) {
+ if(ignoreSelection) {
+ return;
+ }
valueChanged = true;
if (e.getValueIsAdjusting() == false) {
if (list.getSelectedIndex() == -1) {
@@ -235,6 +239,19 @@
if(!selectedUser.isActiveUser()) {
GoogleLogin.getInstance().setActiveUser(selectedUser.getUserEmail());
}
+
+ // Change order of elements in the list so that the
+ // active user becomes the first element in the list
+ ignoreSelection = true;
+ try {
+ listModel.remove(list.getSelectedIndex());
+ listModel.add(0, selectedUser);
+
+ // Re-select the active user
+ list.setSelectedIndex(0);
+ } finally {
+ ignoreSelection = false;
+ }
}
}
}
@@ -258,6 +275,12 @@
if(listModel.getSize() == 0) {
// Add no user panel
listModel.addElement(NoUsersListItem.INSTANCE);
+ } else if ((activeUserIndex != 0) && (activeUserIndex < listModel.getSize())) {
+ // Change order of elements in the list so that the
+ // active user becomes the first element in the list
+ UsersListItem activeUser = (UsersListItem)listModel.remove(activeUserIndex);
+ listModel.add(0, activeUser);
+ activeUserIndex = 0;
}
return activeUserIndex;