changeset 685:0cb6631d2bca

Remove ViewFactory references in the vmclassstat bundle. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-October/003631.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 09 Oct 2012 17:18:40 +0200
parents c2f3b3b23e0a
children bce48ee46f4e
files client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/Activator.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/SwingVmClassStatViewProvider.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatController.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatPanel.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatService.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatView.java client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatViewProvider.java client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/ActivatorTest.java client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/VmClassStatControllerTest.java
diffstat 9 files changed, 83 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/Activator.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/Activator.java	Tue Oct 09 17:18:40 2012 +0200
@@ -43,7 +43,7 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-import com.redhat.thermostat.client.common.VmInformationService;
+import com.redhat.thermostat.client.core.VmInformationService;
 import com.redhat.thermostat.client.osgi.service.ApplicationService;
 import com.redhat.thermostat.common.MultipleServiceTracker;
 import com.redhat.thermostat.common.MultipleServiceTracker.Action;
@@ -56,6 +56,8 @@
 
     @Override
     public void start(final BundleContext context) throws Exception {
+        VmClassStatViewProvider viewProvider = new SwingVmClassStatViewProvider();
+        context.registerService(VmClassStatViewProvider.class.getName(), viewProvider, null);
 
         Class<?>[] deps = new Class<?>[] {
             ApplicationService.class,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/SwingVmClassStatViewProvider.java	Tue Oct 09 17:18:40 2012 +0200
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+
+public class SwingVmClassStatViewProvider implements VmClassStatViewProvider {
+
+    @Override
+    public VmClassStatView createView() {
+        return new VmClassStatPanel();
+    }
+}
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatController.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatController.java	Tue Oct 09 17:18:40 2012 +0200
@@ -40,9 +40,9 @@
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
-import com.redhat.thermostat.client.common.controllers.VmInformationServiceController;
-import com.redhat.thermostat.client.common.views.UIComponent;
-import com.redhat.thermostat.client.common.views.BasicView.Action;
+import com.redhat.thermostat.client.core.controllers.VmInformationServiceController;
+import com.redhat.thermostat.client.core.views.UIComponent;
+import com.redhat.thermostat.client.core.views.BasicView.Action;
 import com.redhat.thermostat.client.locale.LocaleResources;
 import com.redhat.thermostat.client.locale.Translate;
 import com.redhat.thermostat.common.ActionEvent;
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatPanel.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatPanel.java	Tue Oct 09 17:18:40 2012 +0200
@@ -79,7 +79,7 @@
         // any name works
         dataset.addSeries(new TimeSeries("class-stat"));
 
-        visiblePanel.setHeader(localize(LocaleResources.VM_CLASSES_TITLE));
+        visiblePanel.setHeader(localize(LocaleResources.VM_CLASSES_CHART_LOADED_CLASSES_LABEL));
 
         JFreeChart chart = ChartFactory.createTimeSeriesChart(
                 null,
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatService.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatService.java	Tue Oct 09 17:18:40 2012 +0200
@@ -36,28 +36,27 @@
 
 package com.redhat.thermostat.client.vmclassstat;
 
-import com.redhat.thermostat.client.common.VmFilter;
-import com.redhat.thermostat.client.common.VmInformationService;
-import com.redhat.thermostat.client.common.controllers.VmInformationServiceController;
+import com.redhat.thermostat.client.core.VmFilter;
+import com.redhat.thermostat.client.core.VmInformationService;
+import com.redhat.thermostat.client.core.controllers.VmInformationServiceController;
 import com.redhat.thermostat.client.osgi.service.AlwaysMatchFilter;
 import com.redhat.thermostat.common.dao.VmClassStatDAO;
 import com.redhat.thermostat.common.dao.VmRef;
+import com.redhat.thermostat.common.utils.OSGIUtils;
 
 class VmClassStatService implements VmInformationService {
 
     private VmFilter filter = new AlwaysMatchFilter();
 
-    private VmClassStatViewProvider viewProvider;
-
     private VmClassStatDAO vmClassStatDao;
 
     public VmClassStatService(VmClassStatDAO vmClassStatDao) {
         this.vmClassStatDao = vmClassStatDao;
-        viewProvider = new VmClassStatViewProvider();
     }
     
     @Override
     public VmInformationServiceController getInformationServiceController(VmRef ref) {
+        VmClassStatViewProvider viewProvider = OSGIUtils.getInstance().getService(VmClassStatViewProvider.class);
         return new VmClassStatController(vmClassStatDao, ref, viewProvider);
     }
 
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatView.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatView.java	Tue Oct 09 17:18:40 2012 +0200
@@ -38,8 +38,8 @@
 
 import java.util.List;
 
-import com.redhat.thermostat.client.common.views.BasicView;
-import com.redhat.thermostat.client.common.views.UIComponent;
+import com.redhat.thermostat.client.core.views.BasicView;
+import com.redhat.thermostat.client.core.views.UIComponent;
 import com.redhat.thermostat.common.model.DiscreteTimeData;
 
 public abstract class VmClassStatView extends BasicView implements UIComponent {
--- a/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatViewProvider.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/main/java/com/redhat/thermostat/client/vmclassstat/VmClassStatViewProvider.java	Tue Oct 09 17:18:40 2012 +0200
@@ -36,12 +36,11 @@
 
 package com.redhat.thermostat.client.vmclassstat;
 
-import com.redhat.thermostat.client.common.views.ViewProvider;
+import com.redhat.thermostat.client.core.views.ViewProvider;
 
-public class VmClassStatViewProvider implements ViewProvider {
+
+public interface VmClassStatViewProvider extends ViewProvider {
 
     @Override
-    public VmClassStatView createView() {
-        return new VmClassStatPanel();
-    }
+    public VmClassStatView createView();
 }
--- a/client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/ActivatorTest.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/ActivatorTest.java	Tue Oct 09 17:18:40 2012 +0200
@@ -43,8 +43,8 @@
 
 import org.junit.Test;
 
+import com.redhat.thermostat.client.core.VmInformationService;
 import com.redhat.thermostat.client.osgi.service.ApplicationService;
-import com.redhat.thermostat.client.osgi.service.VmInformationService;
 import com.redhat.thermostat.common.dao.VmClassStatDAO;
 import com.redhat.thermostat.test.StubBundleContext;
 
@@ -58,8 +58,9 @@
 
         activator.start(context);
 
-        assertEquals(0, context.getAllServices().size());
-        assertNotSame(0, context.getServiceListeners().size());
+        // View provider registers unconditionally
+        assertEquals(1, context.getAllServices().size());
+        assertNotSame(1, context.getServiceListeners().size());
 
         activator.stop(context);
 
@@ -84,6 +85,15 @@
         activator.stop(context);
 
         assertEquals(0, context.getServiceListeners().size());
-        assertEquals(2, context.getAllServices().size());
+        assertEquals(3, context.getAllServices().size());
+    }
+
+    @Test
+    public void verifyStartRegistersViewProvider() throws Exception {
+        StubBundleContext ctx = new StubBundleContext();
+        Activator activator = new Activator();
+        activator.start(ctx);
+        assertTrue(ctx.isServiceRegistered(VmClassStatViewProvider.class.getName(), SwingVmClassStatViewProvider.class));
+        assertEquals(1, ctx.getAllServices().size());
     }
 }
--- a/client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/VmClassStatControllerTest.java	Tue Oct 09 17:14:38 2012 +0200
+++ b/client/vmclassstat/src/test/java/com/redhat/thermostat/client/vmclassstat/VmClassStatControllerTest.java	Tue Oct 09 17:18:40 2012 +0200
@@ -60,7 +60,7 @@
 
 public class VmClassStatControllerTest {
 
-    @SuppressWarnings("unchecked") // any(List.class)
+    @SuppressWarnings({ "unchecked", "rawtypes" }) // any(List.class)
     @Test
     public void testChartUpdate() {
 
@@ -85,10 +85,11 @@
         ArgumentCaptor<ActionListener> viewArgumentCaptor = ArgumentCaptor.forClass(ActionListener.class);
         doNothing().when(view).addActionListener(viewArgumentCaptor.capture());
         
-        VmClassStatViewProvider viewFactory = mock(VmClassStatViewProvider.class);
-        when(viewFactory.createView()).thenReturn(view);
+        VmClassStatViewProvider viewProvider = mock(VmClassStatViewProvider.class);
+        when(viewProvider.createView()).thenReturn(view);
 
-        VmClassStatController controller = new VmClassStatController(vmClassStatDAO, ref, viewFactory);
+        @SuppressWarnings("unused")
+        VmClassStatController controller = new VmClassStatController(vmClassStatDAO, ref, viewProvider);
 
         ActionListener<VmClassStatView.Action> l = viewArgumentCaptor.getValue();