changeset 1734:16960ccfe1a0

Remove visual glitches in the profiler sessions list Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-August/015253.html
author Omair Majid <omajid@redhat.com>
date Tue, 18 Aug 2015 11:23:58 -0400
parents ac22225863ac
children eeff1ae6fcc1
files vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileView.java vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileView.java
diffstat 3 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileView.java	Mon Aug 17 11:54:56 2015 -0400
+++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileView.java	Tue Aug 18 11:23:58 2015 -0400
@@ -183,13 +183,22 @@
         profileList.setCellRenderer(new ProfileItemRenderer());
         profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         profileList.addListSelectionListener(new ListSelectionListener() {
+
+            private Profile oldValue = null;
+
             @Override
             public void valueChanged(ListSelectionEvent e) {
                 if (e.getValueIsAdjusting()) {
                     return;
                 }
 
-                fireProfileAction(ProfileAction.PROFILE_SELECTED);
+                Profile newValue = profileList.getModel().getElementAt(e.getFirstIndex());
+
+                if (oldValue == null || !oldValue.equals(newValue)) {
+                    oldValue = newValue;
+                    fireProfileAction(ProfileAction.PROFILE_SELECTED);
+                }
+
             }
         });
         ThermostatScrollPane profileListPane = new ThermostatScrollPane(profileList);
@@ -285,11 +294,23 @@
     }
 
     @Override
-    public void setAvailableProfilingRuns(List<Profile> data) {
-        listModel.clear();
-        for (Profile item : data) {
-            listModel.addElement(item);
-        }
+    public void setAvailableProfilingRuns(final List<Profile> data) {
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                Profile selectedValue = profileList.getSelectedValue();
+
+                DefaultListModel<Profile> newListModel = new DefaultListModel<>();
+                for (Profile item : data) {
+                    newListModel.addElement(item);
+                }
+
+                profileList.setModel(newListModel);
+                if (selectedValue != null) {
+                    profileList.setSelectedValue(selectedValue, /* shouldScroll = */ true);
+                }
+            }
+        });
     }
 
     @Override
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java	Mon Aug 17 11:54:56 2015 -0400
+++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java	Tue Aug 18 11:23:58 2015 -0400
@@ -39,6 +39,8 @@
 import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
@@ -268,6 +270,8 @@
             profiles.add(profile);
         }
 
+        Collections.sort(profiles, new ByTimeStamp());
+
         view.setAvailableProfilingRuns(profiles);
     }
 
@@ -289,4 +293,10 @@
         return translator.localize(LocaleResources.PROFILER_TAB_NAME);
     }
 
+    static class ByTimeStamp implements Comparator<Profile> {
+        @Override
+        public int compare(Profile o1, Profile o2) {
+            return Long.compare(o1.timeStamp, o2.timeStamp);
+        }
+    }
 }
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileView.java	Mon Aug 17 11:54:56 2015 -0400
+++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileView.java	Tue Aug 18 11:23:58 2015 -0400
@@ -37,6 +37,7 @@
 package com.redhat.thermostat.vm.profiler.client.swing.internal;
 
 import java.util.List;
+import java.util.Objects;
 
 import com.redhat.thermostat.client.core.views.BasicView;
 import com.redhat.thermostat.client.core.views.UIComponent;
@@ -52,6 +53,19 @@
             this.name = name;
             this.timeStamp = timeStamp;
         }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            }
+            if (obj.getClass() != Profile.class) {
+                return false;
+            }
+            Profile other = (Profile) obj;
+            return Objects.equals(this.name, other.name)
+                    && Objects.equals(this.timeStamp, other.timeStamp);
+        }
     }
 
     enum ProfileAction {