diff options
author | Oluwatobi Bashir-Bello <nbashirbello@google.com> | 2014-08-12 16:51:57 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-08-11 18:49:34 +0000 |
commit | 78fa6072fd850274896fc5e8c41493b543910420 (patch) | |
tree | 9421b70171afd7551b378c89d1948cc58647b12e | |
parent | 7e3d46f3b677817867642ef650aadfa2f3d8a6fb (diff) | |
parent | 1b01645d2a69905dacf7ec62f7d5743b633688f4 (diff) | |
download | cloud-78fa6072fd850274896fc5e8c41493b543910420.tar.gz |
Merge "In the Google Login panel, bubble the active user to the top of the list." into idea133
-rw-r--r-- | login/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java | 25 |
1 files changed, 24 insertions, 1 deletions
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 @@ public class GoogleLoginUsersPanel extends JPanel implements ListSelectionListen private JButton signOutButton; private JButton addAccountButton; private boolean valueChanged = false; + private boolean ignoreSelection = false; public GoogleLoginUsersPanel() { super(new BorderLayout()); @@ -150,7 +151,7 @@ public class GoogleLoginUsersPanel extends JPanel implements ListSelectionListen // 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 @@ public class GoogleLoginUsersPanel extends JPanel implements ListSelectionListen //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 @@ public class GoogleLoginUsersPanel extends JPanel implements ListSelectionListen 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 @@ public class GoogleLoginUsersPanel extends JPanel implements ListSelectionListen 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; |