summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOluwatobi Bashir-Bello <nbashirbello@google.com>2014-08-10 11:30:19 -0400
committerOluwatobi Bashir-Bello <nbashirbello@google.com>2014-08-12 12:01:03 -0400
commit1b01645d2a69905dacf7ec62f7d5743b633688f4 (patch)
tree9421b70171afd7551b378c89d1948cc58647b12e
parent7e3d46f3b677817867642ef650aadfa2f3d8a6fb (diff)
downloadcloud-1b01645d2a69905dacf7ec62f7d5743b633688f4.tar.gz
In the Google Login panel, bubble the active user to the top of the list.
Change-Id: Id0272b3bb04287675b9ad182609d484562428047
-rw-r--r--login/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java25
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;