changeset 519:8bf476b9575c

Refactor views (part 3) review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-August/002588.html reviewed-by: omajid
author Mario Torre <neugens.limasoftware@gmail.com>
date Thu, 02 Aug 2012 21:08:46 +0200
parents 82ddaad8c1fd
children c3c8643bf10f
files client/core/src/main/java/com/redhat/thermostat/client/osgi/service/BasicView.java client/core/src/main/java/com/redhat/thermostat/client/osgi/service/VmInformationServiceController.java client/core/src/main/java/com/redhat/thermostat/client/ui/SwingComponent.java client/core/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationPanel.java client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationView.java client/core/src/main/java/com/redhat/thermostat/client/ui/VmOverviewController.java client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsController.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/Activator.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatController.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatService.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatViewProvider.java client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/VmClassStatControllerTest.java
diffstat 15 files changed, 81 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/BasicView.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/BasicView.java	Thu Aug 02 21:08:46 2012 +0200
@@ -36,11 +36,12 @@
 
 package com.redhat.thermostat.client.osgi.service;
 
+import com.redhat.thermostat.client.ui.UIComponent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.ActionNotifier;
 import com.redhat.thermostat.common.View;
 
-public abstract class BasicView implements View {
+public abstract class BasicView implements View, UIComponent {
     public enum Action {
         VISIBLE,
         HIDDEN,
--- a/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/VmInformationServiceController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/VmInformationServiceController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -36,9 +36,9 @@
 
 package com.redhat.thermostat.client.osgi.service;
 
+import com.redhat.thermostat.client.ui.UIComponent;
 
 public interface VmInformationServiceController {
-    BasicView getView();
-
+    UIComponent getView();
     String getLocalizedName();
 }
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/SwingComponent.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/SwingComponent.java	Thu Aug 02 21:08:46 2012 +0200
@@ -2,7 +2,7 @@
 
 import java.awt.Component;
 
-public interface SwingComponent {
+public interface SwingComponent extends UIComponent {
 
     Component getUiComponent();
 }
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -40,7 +40,6 @@
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
-import com.redhat.thermostat.client.osgi.service.BasicView;
 import com.redhat.thermostat.client.osgi.service.BasicView.Action;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
@@ -116,7 +115,7 @@
         timer.stop();
     }
 
-    public BasicView getView() {
-        return view;
+    public UIComponent getView() {
+        return (UIComponent) view;
     }
 }
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -194,8 +194,8 @@
         return localize(LocaleResources.UNKNOWN_GEN);
     }
 
-    public BasicView getView() {
-        return view;
+    public UIComponent getView() {
+        return (UIComponent) view;
     }
 
 }
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationPanel.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationPanel.java	Thu Aug 02 21:08:46 2012 +0200
@@ -42,8 +42,6 @@
 import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
 
-import com.redhat.thermostat.client.osgi.service.BasicView;
-
 public class VmInformationPanel extends VmInformationView implements SwingComponent {
 
     private final JTabbedPane tabPane = new JTabbedPane();
@@ -60,7 +58,7 @@
     }
 
     @Override
-    public void addChildView(String title, BasicView view) {
+    public void addChildView(String title, UIComponent view) {
         if (view instanceof SwingComponent) {
             SwingComponent panel = (SwingComponent)view;
             tabPane.insertTab(title, null, panel.getUiComponent(), null, tabCount);
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationView.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationView.java	Thu Aug 02 21:08:46 2012 +0200
@@ -43,7 +43,7 @@
     /**
      * @param view the view.
      */
-    public abstract void addChildView(String title, BasicView view);
+    public abstract void addChildView(String title, UIComponent view);
 
     public abstract int getNumChildren();
     public abstract boolean selectChildID(int id);
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmOverviewController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmOverviewController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -131,7 +131,7 @@
         timer.stop();
     }
 
-    public BasicView getView() {
-        return view;
+    public UIComponent getView() {
+        return (UIComponent) view;
     }
 }
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -49,6 +49,7 @@
 import com.redhat.thermostat.client.osgi.service.BasicView;
 import com.redhat.thermostat.client.osgi.service.VmInformationServiceController;
 import com.redhat.thermostat.client.osgi.service.BasicView.Action;
+import com.redhat.thermostat.client.ui.UIComponent;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.NotImplementedException;
@@ -182,8 +183,8 @@
     }
 
     @Override
-    public BasicView getView() {
-        return view;
+    public UIComponent getView() {
+        return (UIComponent) view;
     }
 
     @Override
--- a/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -46,6 +46,7 @@
 import com.redhat.thermostat.client.osgi.service.BasicView;
 import com.redhat.thermostat.client.osgi.service.VmInformationServiceController;
 import com.redhat.thermostat.client.osgi.service.BasicView.Action;
+import com.redhat.thermostat.client.ui.UIComponent;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.NotImplementedException;
@@ -218,7 +219,7 @@
     }
 
     @Override
-    public BasicView getView() {
-        return view;
+    public UIComponent getView() {
+        return (UIComponent) view;
     }
 }
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/Activator.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/Activator.java	Thu Aug 02 21:08:46 2012 +0200
@@ -43,7 +43,6 @@
 
 import com.redhat.thermostat.client.osgi.service.ApplicationService;
 import com.redhat.thermostat.client.osgi.service.VmInformationService;
-import com.redhat.thermostat.common.appctx.ApplicationContext;
 
 public class Activator implements BundleActivator {
 
@@ -52,7 +51,6 @@
         ServiceTracker tracker = new ServiceTracker(context, ApplicationService.class.getName(), null) {
             @Override
             public Object addingService(ServiceReference reference) {
-                ApplicationContext.getInstance().getViewFactory().setViewClass(VmClassStatView.class, VmClassStatPanel.class);
                 context.registerService(VmInformationService.class.getName(), new VmClassStatService(), null);
                 return super.addingService(reference);
             }
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatController.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatController.java	Thu Aug 02 21:08:46 2012 +0200
@@ -42,9 +42,9 @@
 
 import com.redhat.thermostat.client.locale.LocaleResources;
 import com.redhat.thermostat.client.locale.Translate;
-import com.redhat.thermostat.client.osgi.service.BasicView;
 import com.redhat.thermostat.client.osgi.service.VmInformationServiceController;
 import com.redhat.thermostat.client.osgi.service.BasicView.Action;
+import com.redhat.thermostat.client.ui.UIComponent;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.NotImplementedException;
@@ -76,7 +76,7 @@
     private final VmClassStatDAO dao;
     private final Timer timer;
 
-    public VmClassStatController(VmRef ref) {
+    public VmClassStatController(VmRef ref, VmClassStatViewProvider viewProvider) {
         this.ref = ref;
         dao = ApplicationContext.getInstance().getDAOFactory().getVmClassStatsDAO();
         timer = ApplicationContext.getInstance().getTimerFactory().createTimer();
@@ -87,7 +87,7 @@
         timer.setDelay(5);
         timer.setInitialDelay(0);
 
-        classesView = ApplicationContext.getInstance().getViewFactory().getView(VmClassStatView.class);
+        classesView = viewProvider.createView();
 
         classesView.addActionListener(new ActionListener<VmClassStatView.Action>() {
             @Override
@@ -120,8 +120,8 @@
     }
 
     @Override
-    public BasicView getView() {
-        return classesView;
+    public UIComponent getView() {
+        return (UIComponent) classesView;
     }
 
 }
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatService.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatService.java	Thu Aug 02 21:08:46 2012 +0200
@@ -46,9 +46,14 @@
 
     private VmFilter filter = new AlwaysMatchFilter();
 
+    private VmClassStatViewProvider viewProvider;
+    public VmClassStatService() {
+        viewProvider = new VmClassStatViewProvider();
+    }
+    
     @Override
     public VmInformationServiceController getInformationServiceController(VmRef ref) {
-        return new VmClassStatController(ref);
+        return new VmClassStatController(ref, viewProvider);
     }
 
     @Override
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatViewProvider.java	Thu Aug 02 21:08:46 2012 +0200
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.vmclassstat;
+
+import com.redhat.thermostat.client.osgi.service.ViewProvider;
+
+public class VmClassStatViewProvider implements ViewProvider {
+
+    @Override
+    public VmClassStatView createView() {
+        return new VmClassStatPanel();
+    }
+}
--- a/client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/VmClassStatControllerTest.java	Thu Aug 02 21:08:03 2012 +0200
+++ b/client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/VmClassStatControllerTest.java	Thu Aug 02 21:08:46 2012 +0200
@@ -91,12 +91,11 @@
         VmClassStatView view = mock(VmClassStatView.class);
         ArgumentCaptor<ActionListener> viewArgumentCaptor = ArgumentCaptor.forClass(ActionListener.class);
         doNothing().when(view).addActionListener(viewArgumentCaptor.capture());
-        ViewFactory viewFactory = mock(ViewFactory.class);
-        when(viewFactory.getView(eq(VmClassStatView.class))).thenReturn(view);
+        
+        VmClassStatViewProvider viewFactory = mock(VmClassStatViewProvider.class);
+        when(viewFactory.createView()).thenReturn(view);
 
-        ApplicationContext.getInstance().setViewFactory(viewFactory);
-
-        VmClassStatController controller = new VmClassStatController(ref);
+        VmClassStatController controller = new VmClassStatController(ref, viewFactory);
 
         ActionListener<VmClassStatView.Action> l = viewArgumentCaptor.getValue();