changeset 578:aa0d2cb96bb9

Remember split pane location - Thread Monitor review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-August/003004.html reviewed-by: vanaltj
author Mario Torre <neugens.limasoftware@gmail.com>
date Fri, 31 Aug 2012 17:49:39 +0200
parents d03acb3cf6c6
children 4082ce718f9f
files thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/ThreadView.java thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java
diffstat 4 files changed, 61 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/ThreadView.java	Fri Aug 31 16:29:39 2012 +0200
+++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/ThreadView.java	Fri Aug 31 17:49:39 2012 +0200
@@ -36,6 +36,7 @@
 
 package com.redhat.thermostat.thread.client.common;
 
+import com.redhat.thermostat.client.osgi.service.ApplicationService;
 import com.redhat.thermostat.client.osgi.service.BasicView;
 import com.redhat.thermostat.client.ui.UIComponent;
 import com.redhat.thermostat.common.ActionListener;
@@ -49,6 +50,9 @@
         STOP_LIVE_RECORDING
     };
     
+    protected ApplicationService appService;
+    protected String uniqueId;
+    
     protected final ActionNotifier<ThreadAction> notifier;
     public ThreadView() {
         notifier = new ActionNotifier<>(this);
@@ -72,4 +76,9 @@
     public abstract ThreadTableView createThreadTableView();
     
     public abstract void displayWarning(String warning);
+
+    public void setApplicationService(ApplicationService appService, String uniqueId) {
+        this.appService = appService;
+        this.uniqueId = uniqueId;
+    }
 }
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java	Fri Aug 31 16:29:39 2012 +0200
+++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java	Fri Aug 31 17:49:39 2012 +0200
@@ -70,21 +70,18 @@
     
     private ThreadView view;
     private ThreadCollector collector;
-    private ApplicationService appService;
     
     private Timer timer;
-    private ApplicationCache cache;
     
     private LivingDaemonThreadDifferenceChart model;
         
     public ThreadInformationController(VmRef ref, ApplicationService appService,
                                        ThreadCollectorFactory collectorFactory, 
                                        ThreadViewProvider viewFactory)
-    {        
-        this.appService = appService;
-        cache = appService.getApplicationCache();
-
+    {
         view = viewFactory.createView();
+        view.setApplicationService(appService, ref.getIdString() + "-" + ref.getAgent().getAgentId());
+        
         collector = collectorFactory.getCollector(ref);
         
         initControllers();
--- a/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java	Fri Aug 31 16:29:39 2012 +0200
+++ b/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java	Fri Aug 31 17:49:39 2012 +0200
@@ -57,6 +57,7 @@
 import com.redhat.thermostat.common.TimerFactory;
 import com.redhat.thermostat.common.appctx.ApplicationContext;
 import com.redhat.thermostat.common.appctx.ApplicationContextUtil;
+import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.VmRef;
 import com.redhat.thermostat.thread.client.common.ThreadTableView;
 import com.redhat.thermostat.thread.client.common.ThreadView;
@@ -125,6 +126,9 @@
         when(appService.getApplicationCache()).thenReturn(cache);
         
         VmRef ref = mock(VmRef.class);
+        HostRef agent = mock(HostRef.class);
+        when(ref.getAgent()).thenReturn(agent);
+        when(agent.getAgentId()).thenReturn("0xcafe");
         
         ThreadCollectorFactory collectorFactory = mock(ThreadCollectorFactory.class);
         ThreadCollector collector = mock(ThreadCollector.class);
@@ -142,7 +146,10 @@
         
         VmRef ref = mock(VmRef.class);
         when(ref.getStringID()).thenReturn("42");
-                
+        HostRef agent = mock(HostRef.class);
+        when(ref.getAgent()).thenReturn(agent);
+        when(agent.getAgentId()).thenReturn("0xcafe");
+        
         ThreadCollector collector = mock(ThreadCollector.class);
         when(collector.isHarvesterCollecting()).thenReturn(false).thenReturn(true);
         when(collector.startHarvester()).thenReturn(true);
@@ -154,7 +161,7 @@
         ApplicationCache cache = mock(ApplicationCache.class);
         appService = mock(ApplicationService.class);
         when(appService.getApplicationCache()).thenReturn(cache);
-        
+                
         controller = new ThreadInformationController(ref, appService, collectorFactory, viewFactory);
         
         verify(collector).isHarvesterCollecting();
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java	Fri Aug 31 16:29:39 2012 +0200
+++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java	Fri Aug 31 17:49:39 2012 +0200
@@ -39,13 +39,17 @@
 import java.awt.Component;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JSplitPane;
 import javax.swing.JTabbedPane;
 import javax.swing.SwingUtilities;
 import javax.swing.SwingWorker;
 
+import com.redhat.thermostat.client.osgi.service.ApplicationService;
 import com.redhat.thermostat.client.ui.ComponentVisibleListener;
 import com.redhat.thermostat.client.ui.SwingComponent;
 import com.redhat.thermostat.common.locale.Translate;
@@ -58,6 +62,8 @@
 
 public class SwingThreadView extends ThreadView implements SwingComponent {
     
+    private String DIVIDER_LOCATION_KEY;
+    
     private ThreadMainPanel panel;
     private ThreadAliveDaemonTimelinePanel timelinePanel;
     
@@ -76,10 +82,7 @@
             @Override
             public void componentShown(Component component) {
                 SwingThreadView.this.notify(Action.VISIBLE);
-                
-                // TODO: allow controller to define this value based on last
-                // user setting
-                panel.getSplitPane().setDividerLocation(0.80);
+                restoreDivider();
             }
             
             @Override
@@ -88,6 +91,16 @@
             }
         });
         
+        panel.getSplitPane().addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
+                                                       new PropertyChangeListener()
+        {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                JSplitPane sourceSplitPane = (JSplitPane) evt.getSource();
+                saveDivider(sourceSplitPane.getDividerLocation());
+            }
+        });
+        
         timelinePanel = new ThreadAliveDaemonTimelinePanel();
 
         timelinePanel.setToggleText(t.localize(LocaleResources.START_RECORDING) + ":");
@@ -136,6 +149,12 @@
     }
     
     @Override
+    public void setApplicationService(ApplicationService appService, String uniqueId) {
+        super.setApplicationService(appService, uniqueId);
+        DIVIDER_LOCATION_KEY = "divider." + uniqueId;
+    }
+    
+    @Override
     public void setRecording(final boolean recording, final boolean notify) {
         SwingUtilities.invokeLater(new Runnable() {
             @Override
@@ -202,4 +221,21 @@
             }
         });
     }
+    
+    private void restoreDivider() {
+        int location = (int) ((double) (panel.getSplitPane().getHeight() - panel.getSplitPane().getDividerSize()) * 0.80);
+        if (appService != null) {
+            Object _location = appService.getApplicationCache().getAttribute(DIVIDER_LOCATION_KEY);
+            if (_location != null) {
+                location = (Integer) _location;
+            }
+        }
+        panel.getSplitPane().setDividerLocation(location);
+    }
+    
+    private void saveDivider(int location) {
+        if (appService != null) {
+            appService.getApplicationCache().addAttribute(DIVIDER_LOCATION_KEY, location);
+        }
+    }
 }