changeset 242:1c37a952b712

Fix VmPanel by splitting it into MVC Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-April/000919.html
author Omair Majid <omajid@redhat.com>
date Wed, 18 Apr 2012 11:54:25 -0400
parents f105046da8c3
children f51208ae449a
files client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java client/src/main/java/com/redhat/thermostat/client/SwingViewFactory.java client/src/main/java/com/redhat/thermostat/client/UiFacadeFactory.java client/src/main/java/com/redhat/thermostat/client/UiFacadeFactoryImpl.java client/src/main/java/com/redhat/thermostat/client/VmPanelFacade.java client/src/main/java/com/redhat/thermostat/client/VmPanelFacadeImpl.java client/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java client/src/main/java/com/redhat/thermostat/client/ui/VmInformationPanel.java client/src/main/java/com/redhat/thermostat/client/ui/VmInformationView.java client/src/main/java/com/redhat/thermostat/client/ui/VmPanel.java
diffstat 10 files changed, 240 insertions(+), 257 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java	Tue Apr 17 15:05:55 2012 -0400
+++ b/client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java	Wed Apr 18 11:54:25 2012 -0400
@@ -48,7 +48,7 @@
 import com.redhat.thermostat.client.ui.ClientConfigurationView;
 import com.redhat.thermostat.client.ui.HostPanel;
 import com.redhat.thermostat.client.ui.SummaryPanel;
-import com.redhat.thermostat.client.ui.VmPanel;
+import com.redhat.thermostat.client.ui.VmInformationController;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.Timer;
@@ -76,7 +76,9 @@
     private UiFacadeFactory facadeFactory;
 
     private boolean showHistory;
-    
+
+    private AsyncUiFacade oldController = null;
+
     public MainWindowControllerImpl(UiFacadeFactory facadeFactory, MainView view) {
         this.facadeFactory = facadeFactory;
 
@@ -209,7 +211,7 @@
         ClientConfigurationController controller = new ClientConfigurationController(prefs, view);
         controller.showDialog();
     }
-    
+
     private void switchHistoryMode() {
         showHistory = !showHistory;
         doUpdateTreeAsync();
@@ -218,6 +220,11 @@
     private void updateView() {
         // this is quite an ugly method. there must be a cleaner way to do this
         Ref ref = view.getSelectedHostOrVm();
+
+        if (oldController != null) {
+            oldController.stop();
+        }
+
         if (ref == null) {
             view.setSubView(new SummaryPanel(facadeFactory.getSummaryPanel()));
         } else if (ref instanceof HostRef) {
@@ -225,7 +232,10 @@
             view.setSubView(new HostPanel(facadeFactory.getHostPanel(hostRef)));
         } else if (ref instanceof VmRef) {
             VmRef vmRef = (VmRef) ref;
-            view.setSubView(new VmPanel(facadeFactory.getVmPanel(vmRef)));
+            VmInformationController vmInformation = facadeFactory.getVmController(vmRef);
+            view.setSubView(vmInformation.getComponent());
+            vmInformation.start();
+            oldController = vmInformation;
         } else {
             throw new IllegalArgumentException("unknown type of ref");
         }
--- a/client/src/main/java/com/redhat/thermostat/client/SwingViewFactory.java	Tue Apr 17 15:05:55 2012 -0400
+++ b/client/src/main/java/com/redhat/thermostat/client/SwingViewFactory.java	Wed Apr 18 11:54:25 2012 -0400
@@ -53,6 +53,8 @@
 import com.redhat.thermostat.client.ui.VmCpuView;
 import com.redhat.thermostat.client.ui.VmGcPanel;
 import com.redhat.thermostat.client.ui.VmGcView;
+import com.redhat.thermostat.client.ui.VmInformationPanel;
+import com.redhat.thermostat.client.ui.VmInformationView;
 import com.redhat.thermostat.client.ui.VmMemoryPanel;
 import com.redhat.thermostat.client.ui.VmMemoryView;
 import com.redhat.thermostat.client.ui.VmOverviewPanel;
@@ -65,6 +67,8 @@
         setViewClass(AgentConfigurationView.class, AgentConfigurationFrame.class);
         setViewClass(ClientConfigurationView.class, ClientConfigurationFrame.class);
 
+        setViewClass(VmInformationView.class, VmInformationPanel.class);
+
         setViewClass(HostCpuView.class, HostCpuPanel.class);
         setViewClass(HostMemoryView.class, HostMemoryPanel.class);
         setViewClass(HostOverviewView.class, HostOverviewPanel.class);
--- a/client/src/main/java/com/redhat/thermostat/client/UiFacadeFactory.java	Tue Apr 17 15:05:55 2012 -0400
+++ b/client/src/main/java/com/redhat/thermostat/client/UiFacadeFactory.java	Wed Apr 18 11:54:25 2012 -0400
@@ -36,6 +36,7 @@
 
 package com.redhat.thermostat.client;
 
+import com.redhat.thermostat.client.ui.VmInformationController;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.VmRef;
 
@@ -47,6 +48,6 @@
 
     public HostPanelFacade getHostPanel(HostRef ref);
 
-    public VmPanelFacade getVmPanel(VmRef ref);
+    public VmInformationController getVmController(VmRef ref);
 
 }
--- a/client/src/main/java/com/redhat/thermostat/client/UiFacadeFactoryImpl.java	Tue Apr 17 15:05:55 2012 -0400
+++ b/client/src/main/java/com/redhat/thermostat/client/UiFacadeFactoryImpl.java	Wed Apr 18 11:54:25 2012 -0400
@@ -37,6 +37,7 @@
 package com.redhat.thermostat.client;
 
 import com.redhat.thermostat.client.ui.MainWindow;
+import com.redhat.thermostat.client.ui.VmInformationController;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.VmRef;
 
@@ -61,8 +62,8 @@
     }
 
     @Override
-    public VmPanelFacade getVmPanel(VmRef ref) {
-        return new VmPanelFacadeImpl(ref);
+    public VmInformationController getVmController(VmRef ref) {
+        return new VmInformationController(ref);
 
     }
 
--- a/client/src/main/java/com/redhat/thermostat/client/VmPanelFacade.java	Tue Apr 17 15:05:55 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * 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;
-
-import com.redhat.thermostat.client.ui.VmClassStatController;
-import com.redhat.thermostat.client.ui.VmCpuController;
-import com.redhat.thermostat.client.ui.VmGcController;
-import com.redhat.thermostat.client.ui.VmMemoryController;
-import com.redhat.thermostat.client.ui.VmOverviewController;
-
-/**
- * Represents information specific to a JVM running on a host somewhere. This is
- * used to populate the UI for a VM's information.
- */
-public interface VmPanelFacade extends AsyncUiFacade {
-
-    public VmOverviewController getOverviewController();
-
-    public VmCpuController getCpuController();
-
-    public VmMemoryController getMemoryController();
-
-    public VmClassStatController getClassesController();
-
-    public VmGcController getGcController();
-
-
-}
--- a/client/src/main/java/com/redhat/thermostat/client/VmPanelFacadeImpl.java	Tue Apr 17 15:05:55 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/*
- * 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;
-
-import com.redhat.thermostat.client.ui.VmClassStatController;
-import com.redhat.thermostat.client.ui.VmCpuController;
-import com.redhat.thermostat.client.ui.VmGcController;
-import com.redhat.thermostat.client.ui.VmMemoryController;
-import com.redhat.thermostat.client.ui.VmOverviewController;
-import com.redhat.thermostat.common.dao.VmRef;
-
-public class VmPanelFacadeImpl implements VmPanelFacade {
-
-    private final VmOverviewController overviewController;
-    private final VmCpuController cpuController;
-    private final VmMemoryController memoryController;
-    private final VmClassStatController classesController;
-    private final VmGcController gcController;
-
-    public VmPanelFacadeImpl(VmRef vmRef) {
-        overviewController = new VmOverviewController(vmRef);
-        cpuController = new VmCpuController(vmRef);
-        memoryController = new VmMemoryController(vmRef);
-        gcController = new VmGcController(vmRef);
-        classesController = new VmClassStatController(vmRef);
-    }
-
-    @Override
-    public void start() {
-        overviewController.start();
-        cpuController.start();
-        memoryController.start();
-        gcController.start();
-        classesController.start();
-
-    }
-
-    @Override
-    public void stop() {
-        overviewController.stop();
-        cpuController.stop();
-        memoryController.stop();
-        gcController.stop();
-        classesController.stop();
-    }
-
-    @Override
-    public VmOverviewController getOverviewController() {
-        return overviewController;
-    }
-
-    @Override
-    public VmCpuController getCpuController() {
-        return cpuController;
-    }
-
-    @Override
-    public VmMemoryController getMemoryController() {
-        return memoryController;
-    }
-
-    @Override
-    public VmGcController getGcController() {
-        return gcController;
-    }
-
-    @Override
-    public VmClassStatController getClassesController() {
-        return classesController;
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java	Wed Apr 18 11:54:25 2012 -0400
@@ -0,0 +1,96 @@
+/*
+ * 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.ui;
+
+import static com.redhat.thermostat.client.locale.Translate.localize;
+
+import java.awt.Component;
+
+import com.redhat.thermostat.client.AsyncUiFacade;
+import com.redhat.thermostat.client.locale.LocaleResources;
+import com.redhat.thermostat.common.appctx.ApplicationContext;
+import com.redhat.thermostat.common.dao.VmRef;
+
+public class VmInformationController implements AsyncUiFacade {
+
+    private final VmInformationView view;
+
+    private final VmOverviewController overviewController;
+    private final VmCpuController cpuController;
+    private final VmMemoryController memoryController;
+    private final VmClassStatController classesController;
+    private final VmGcController gcController;
+
+    public VmInformationController(VmRef vmRef) {
+        overviewController = new VmOverviewController(vmRef);
+        cpuController = new VmCpuController(vmRef);
+        memoryController = new VmMemoryController(vmRef);
+        gcController = new VmGcController(vmRef);
+        classesController = new VmClassStatController(vmRef);
+
+        view = ApplicationContext.getInstance().getViewFactory().getView(VmInformationView.class);
+
+        view.addChildView(localize(LocaleResources.VM_INFO_TAB_OVERVIEW), overviewController.getComponent());
+        view.addChildView(localize(LocaleResources.VM_INFO_TAB_CPU), cpuController.getComponent());
+        view.addChildView(localize(LocaleResources.VM_INFO_TAB_MEMORY), memoryController.getComponent());
+        view.addChildView(localize(LocaleResources.VM_INFO_TAB_GC), gcController.getComponent());
+        view.addChildView(localize(LocaleResources.VM_INFO_TAB_CLASSES), classesController.getComponent());
+    }
+
+    @Override
+    public void start() {
+        overviewController.start();
+        cpuController.start();
+        memoryController.start();
+        gcController.start();
+        classesController.start();
+
+    }
+
+    @Override
+    public void stop() {
+        overviewController.stop();
+        cpuController.stop();
+        memoryController.stop();
+        gcController.stop();
+        classesController.stop();
+    }
+
+    public Component getComponent() {
+        return view.getUiComponent();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmInformationPanel.java	Wed Apr 18 11:54:25 2012 -0400
@@ -0,0 +1,69 @@
+/*
+ * 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.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+
+public class VmInformationPanel extends JPanel implements VmInformationView {
+
+    private final JTabbedPane tabPane = new JTabbedPane();
+
+    private int tabCount = 0;
+
+    public VmInformationPanel() {
+        setLayout(new BorderLayout());
+        tabPane.setName("tabPane");
+        add(tabPane);
+    }
+
+    @Override
+    public void addChildView(String title, Component view) {
+        Component component = view;
+        tabPane.insertTab(title, null, component, null, tabCount);
+        tabCount++;
+    }
+
+    @Override
+    public Component getUiComponent() {
+        return this;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmInformationView.java	Wed Apr 18 11:54:25 2012 -0400
@@ -0,0 +1,52 @@
+/*
+ * 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.ui;
+
+import java.awt.Component;
+
+import com.redhat.thermostat.common.View;
+
+public interface VmInformationView extends View {
+
+    /**
+     * @param view the view. FIXME currently a awt component
+     */
+    void addChildView(String title, Component view);
+
+    Component getUiComponent();
+
+}
--- a/client/src/main/java/com/redhat/thermostat/client/ui/VmPanel.java	Tue Apr 17 15:05:55 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/*
- * 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.ui;
-
-import static com.redhat.thermostat.client.locale.Translate.localize;
-
-import java.awt.BorderLayout;
-
-import javax.swing.JPanel;
-import javax.swing.JTabbedPane;
-
-import com.redhat.thermostat.client.VmPanelFacade;
-import com.redhat.thermostat.client.locale.LocaleResources;
-
-
-public class VmPanel extends JPanel {
-
-    private static final long serialVersionUID = 2816226547554943368L;
-
-    private final VmPanelFacade facade;
-
-    public VmPanel(final VmPanelFacade facade) {
-        this.facade = facade;
-        createUI();
-
-        addHierarchyListener(new AsyncFacadeManager(facade));
-    }
-
-    public void createUI() {
-        setLayout(new BorderLayout());
-
-        JTabbedPane tabPane = new JTabbedPane();
-
-        tabPane.insertTab(localize(LocaleResources.VM_INFO_TAB_OVERVIEW), null, facade.getOverviewController().getComponent(), null, 0);
-        tabPane.insertTab(localize(LocaleResources.VM_INFO_TAB_CPU), null, facade.getCpuController().getComponent(), null, 1);
-        tabPane.insertTab(localize(LocaleResources.VM_INFO_TAB_MEMORY), null, facade.getMemoryController().getComponent(), null, 2);
-        tabPane.insertTab(localize(LocaleResources.VM_INFO_TAB_GC), null, facade.getGcController().getComponent(),
-                          localize(LocaleResources.GARBAGE_COLLECTION), 3);
-        tabPane.insertTab(localize(LocaleResources.VM_INFO_TAB_CLASSES), null, facade.getClassesController().getComponent(), null, 4);
-
-        // TODO additional tabs provided by plugins
-        // tabPane.insertTab(title, icon, component, tip, 3)
-
-        this.add(tabPane);
-    }
-
-
-}