Mercurial > hg > release > thermostat-0.15
changeset 239:7711b0e95139
Merge
author | Roman Kennke <rkennke@redhat.com> |
---|---|
date | Mon, 16 Apr 2012 23:21:57 +0200 |
parents | 72f7c3d2a0c6 (current diff) e69fb1a3dbd9 (diff) |
children | 2dca3a8b0c0d c1dbd9616820 |
files | client/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java client/src/test/java/com/redhat/thermostat/client/ui/MainWindowTest.java |
diffstat | 7 files changed, 161 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/README Mon Apr 16 23:16:07 2012 +0200 +++ b/README Mon Apr 16 23:21:57 2012 +0200 @@ -18,7 +18,7 @@ RUNNING THERMOSTAT: 1. To start the agent and the db: - bin/thermostat-service --start + bin/thermostat service --start 2. To start the client: bin/thermostat-client-gui
--- a/client/src/main/java/com/redhat/thermostat/client/MainView.java Mon Apr 16 23:16:07 2012 +0200 +++ b/client/src/main/java/com/redhat/thermostat/client/MainView.java Mon Apr 16 23:21:57 2012 +0200 @@ -36,16 +36,20 @@ package com.redhat.thermostat.client; +import java.awt.Component; + import com.redhat.thermostat.common.ActionListener; - +import com.redhat.thermostat.common.dao.Ref; public interface MainView { enum Action { HOST_VM_TREE_FILTER, + HOST_VM_SELECTION_CHANGED, SHOW_AGENT_CONFIG, SHOW_CLIENT_CONFIG, SWITCH_HISTORY_MODE, + SHOW_ABOUT_DIALOG, SHUTDOWN, } @@ -53,8 +57,16 @@ void updateTree(String eq, HostsVMsLoader any); + void setWindowTitle(String title); + void showMainWindow(); + void hideMainWindow(); + String getHostVmTreeFilter(); + Ref getSelectedHostOrVm(); + + void setSubView(Component view); + }
--- a/client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java Mon Apr 16 23:16:07 2012 +0200 +++ b/client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java Mon Apr 16 23:21:57 2012 +0200 @@ -40,11 +40,15 @@ import java.util.concurrent.TimeUnit; import com.redhat.thermostat.client.config.ClientPreferences; +import com.redhat.thermostat.client.ui.AboutDialog; import com.redhat.thermostat.client.ui.AgentConfigurationController; import com.redhat.thermostat.client.ui.AgentConfigurationModel; import com.redhat.thermostat.client.ui.AgentConfigurationView; import com.redhat.thermostat.client.ui.ClientConfigurationController; 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.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.Timer; @@ -52,6 +56,7 @@ import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.HostInfoDAO; import com.redhat.thermostat.common.dao.HostRef; +import com.redhat.thermostat.common.dao.Ref; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -66,9 +71,14 @@ private final HostInfoDAO hostsDAO; private final VmInfoDAO vmsDAO; + private ApplicationInfo appInfo; + + private UiFacadeFactory facadeFactory; + private boolean showHistory; - public MainWindowControllerImpl(MainView view) { + public MainWindowControllerImpl(UiFacadeFactory facadeFactory, MainView view) { + this.facadeFactory = facadeFactory; ApplicationContext ctx = ApplicationContext.getInstance(); DAOFactory daoFactory = ctx.getDAOFactory(); @@ -76,6 +86,8 @@ vmsDAO = daoFactory.getVmInfoDAO(); initView(view); + appInfo = new ApplicationInfo(); + view.setWindowTitle(appInfo.getName()); initializeTimer(); start(); } @@ -141,6 +153,9 @@ public void actionPerformed(ActionEvent<MainView.Action> evt) { MainView.Action action = evt.getActionId(); switch (action) { + case HOST_VM_SELECTION_CHANGED: + updateView(); + break; case HOST_VM_TREE_FILTER: String filter = view.getHostVmTreeFilter(); setHostVmTreeFilter(filter); @@ -154,11 +169,15 @@ case SWITCH_HISTORY_MODE: switchHistoryMode(); break; + case SHOW_ABOUT_DIALOG: + showAboutDialog(); + break; case SHUTDOWN: + view.hideMainWindow(); stop(); break; default: - assert false; + throw new IllegalStateException("unhandled action"); } } }); @@ -169,6 +188,13 @@ view.showMainWindow(); } + private void showAboutDialog() { + AboutDialog aboutDialog = new AboutDialog(appInfo); + aboutDialog.setModal(true); + aboutDialog.pack(); + aboutDialog.setVisible(true); + } + private void showAgentConfiguration() { AgentConfigurationSource agentPrefs = new AgentConfigurationSource(); AgentConfigurationModel model = new AgentConfigurationModel(agentPrefs); @@ -188,4 +214,21 @@ showHistory = !showHistory; doUpdateTreeAsync(); } + + private void updateView() { + // this is quite an ugly method. there must be a cleaner way to do this + Ref ref = view.getSelectedHostOrVm(); + if (ref == null) { + view.setSubView(new SummaryPanel(facadeFactory.getSummaryPanel())); + } else if (ref instanceof HostRef) { + HostRef hostRef = (HostRef) ref; + view.setSubView(new HostPanel(facadeFactory.getHostPanel(hostRef))); + } else if (ref instanceof VmRef) { + VmRef vmRef = (VmRef) ref; + view.setSubView(new VmPanel(facadeFactory.getVmPanel(vmRef))); + } else { + throw new IllegalArgumentException("unknown type of ref"); + } + } + }
--- a/client/src/main/java/com/redhat/thermostat/client/UiFacadeFactoryImpl.java Mon Apr 16 23:16:07 2012 +0200 +++ b/client/src/main/java/com/redhat/thermostat/client/UiFacadeFactoryImpl.java Mon Apr 16 23:21:57 2012 +0200 @@ -44,8 +44,8 @@ @Override public MainWindowController getMainWindow() { - MainView mainView = new MainWindow(this); - return new MainWindowControllerImpl(mainView); + MainView mainView = new MainWindow(); + return new MainWindowControllerImpl(this, mainView); } @Override
--- a/client/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java Mon Apr 16 23:16:07 2012 +0200 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java Mon Apr 16 23:21:57 2012 +0200 @@ -83,15 +83,12 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; -import com.redhat.thermostat.client.ApplicationInfo; import com.redhat.thermostat.client.HostsVMsLoader; import com.redhat.thermostat.client.MainView; -import com.redhat.thermostat.client.UiFacadeFactory; import com.redhat.thermostat.client.locale.LocaleResources; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ActionNotifier; @@ -218,8 +215,6 @@ private static final long serialVersionUID = 5608972421496808177L; - private final UiFacadeFactory facadeFactory; - private JPanel contentArea = null; private JTextField searchField = null; @@ -227,28 +222,22 @@ private final ShutdownClient shutdownAction; - private ApplicationInfo appInfo; - private ActionNotifier<Action> actionNotifier = new ActionNotifier<>(this); private final DefaultMutableTreeNode publishedRoot = new DefaultMutableTreeNode(localize(LocaleResources.MAIN_WINDOW_TREE_ROOT_NAME)); private final DefaultTreeModel publishedTreeModel = new DefaultTreeModel(publishedRoot); - public MainWindow(UiFacadeFactory facadeFactory) { + public MainWindow() { super(); - appInfo = new ApplicationInfo(); - setTitle(appInfo.getName()); - - this.facadeFactory = facadeFactory; shutdownAction = new ShutdownClient(); searchField = new JTextField(); searchField.setName("hostVMTreeFilter"); - TreeModel model = publishedTreeModel; - agentVmTree = new JTree(model); - model.addTreeModelListener(new KeepRootExpandedListener(agentVmTree)); + agentVmTree = new JTree(publishedTreeModel); + agentVmTree.setName("agentVmTree"); + publishedTreeModel.addTreeModelListener(new KeepRootExpandedListener(agentVmTree)); agentVmTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); agentVmTree.setCellRenderer(new AgentVmTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(agentVmTree); @@ -259,7 +248,7 @@ this.setPreferredSize(new Dimension(800, 600)); - agentVmTree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) model.getRoot()).getPath())); + agentVmTree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) publishedTreeModel.getRoot()).getPath())); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(shutdownAction); @@ -300,6 +289,7 @@ mainMenuBar.add(editMenu); JMenuItem configureAgentMenuItem = new JMenuItem(localize(LocaleResources.MENU_EDIT_CONFIGURE_AGENT)); + configureAgentMenuItem.setName("showAgentConfig"); configureAgentMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -338,10 +328,7 @@ helpAboutMenu.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { - AboutDialog aboutDialog = new AboutDialog(appInfo); - aboutDialog.setModal(true); - aboutDialog.pack(); - aboutDialog.setVisible(true); + fireViewAction(Action.SHOW_ABOUT_DIALOG); } }); helpMenu.add(helpAboutMenu); @@ -398,20 +385,7 @@ @Override public void valueChanged(TreeSelectionEvent e) { if (e.isAddedPath()) { - contentArea.removeAll(); - TreePath path = e.getPath(); - if (path.getPathCount() == 1) {/* root */ - contentArea.add(new SummaryPanel(facadeFactory.getSummaryPanel())); - } else if (path.getPathCount() == 2) { /* agent */ - HostRef hostRef = (HostRef) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject(); - HostPanel panel = new HostPanel(facadeFactory.getHostPanel(hostRef)); - contentArea.add(panel); - } else { /* vm */ - VmRef vmRef = (VmRef) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject(); - VmPanel panel = new VmPanel(facadeFactory.getVmPanel(vmRef)); - contentArea.add(panel); - } - contentArea.revalidate(); + fireViewAction(Action.HOST_VM_SELECTION_CHANGED); } } }); @@ -567,6 +541,11 @@ } @Override + public void setWindowTitle(String title) { + setTitle(title); + } + + @Override public void showMainWindow() { try { new EdtHelper().callAndWait(new Runnable() { @@ -585,6 +564,32 @@ } @Override + public void hideMainWindow() { + setVisible(false); + dispose(); + } + + @Override + public void setSubView(Component view) { + contentArea.removeAll(); + Component toAdd = view; + contentArea.add(toAdd); + contentArea.revalidate(); + } + + /** + * Returns null to indicate no Ref is selected + */ + @Override + public Ref getSelectedHostOrVm() { + TreePath path = agentVmTree.getSelectionPath(); + if (path.getPathCount() == 1) { + return null; + } + return (Ref) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject(); + } + + @Override public String getHostVmTreeFilter() { try { return new EdtHelper().callAndWait(new Callable<String>() {
--- a/client/src/test/java/com/redhat/thermostat/client/MainWindowControllerImplTest.java Mon Apr 16 23:16:07 2012 +0200 +++ b/client/src/test/java/com/redhat/thermostat/client/MainWindowControllerImplTest.java Mon Apr 16 23:21:57 2012 +0200 @@ -88,12 +88,19 @@ when(timerFactory.createTimer()).thenReturn(mainWindowTimer); ApplicationContext.getInstance().setTimerFactory(timerFactory); + SummaryPanelFacade summaryPanelFacade = mock(SummaryPanelFacade.class); + when(summaryPanelFacade.getTotalMonitoredHosts()).thenReturn(new ChangeableText("totalConnectedAgents")); + when(summaryPanelFacade.getTotalMonitoredVms()).thenReturn(new ChangeableText("connectedVms")); + + UiFacadeFactory uiFacadeFactory = mock(UiFacadeFactory.class); + when(uiFacadeFactory.getSummaryPanel()).thenReturn(summaryPanelFacade); + setupDAOs(); view = mock(MainView.class); ArgumentCaptor<ActionListener> grabListener = ArgumentCaptor.forClass(ActionListener.class); doNothing().when(view).addActionListener(grabListener.capture()); - controller = new MainWindowControllerImpl(view); + controller = new MainWindowControllerImpl(uiFacadeFactory, view); l = grabListener.getValue(); } @@ -159,7 +166,7 @@ expectedHosts.add(new HostRef("456", "fluffhost2")); when(mockHostsDAO.getAliveHosts()).thenReturn(expectedHosts); - + controller.doUpdateTreeAsync(); ArgumentCaptor<HostsVMsLoader> arg = ArgumentCaptor.forClass(HostsVMsLoader.class);
--- a/client/src/test/java/com/redhat/thermostat/client/ui/MainWindowTest.java Mon Apr 16 23:16:07 2012 +0200 +++ b/client/src/test/java/com/redhat/thermostat/client/ui/MainWindowTest.java Mon Apr 16 23:21:57 2012 +0200 @@ -40,7 +40,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import net.java.openjdk.cacio.ctc.junit.CacioFESTRunner; import org.fest.swing.annotation.GUITest; @@ -50,6 +49,7 @@ import org.fest.swing.fixture.FrameFixture; import org.fest.swing.fixture.JMenuItemFixture; import org.fest.swing.fixture.JTextComponentFixture; +import org.fest.swing.fixture.JTreeFixture; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -57,10 +57,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import com.redhat.thermostat.client.ChangeableText; import com.redhat.thermostat.client.MainView; -import com.redhat.thermostat.client.SummaryPanelFacade; -import com.redhat.thermostat.client.UiFacadeFactory; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; @@ -80,18 +77,11 @@ @Before public void setUp() { - SummaryPanelFacade summaryPanelFacade = mock(SummaryPanelFacade.class); - when(summaryPanelFacade.getTotalMonitoredHosts()).thenReturn(new ChangeableText("totalConnectedAgents")); - when(summaryPanelFacade.getTotalMonitoredVms()).thenReturn(new ChangeableText("connectedVms")); - - final UiFacadeFactory uiFacadeFactory = mock(UiFacadeFactory.class); - when(uiFacadeFactory.getSummaryPanel()).thenReturn(summaryPanelFacade); - GuiActionRunner.execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { - window = new MainWindow(uiFacadeFactory); + window = new MainWindow(); l = mock(ActionListener.class); window.addActionListener(l); } @@ -110,6 +100,16 @@ @Category(GUITest.class) @Test + public void testHostVmSelectionChangedSupport() { + frameFixture.show(); + JTreeFixture hostVMTree = frameFixture.tree("agentVmTree"); + hostVMTree.selectRows(0); + + verify(l).actionPerformed(new ActionEvent<MainView.Action>(window, MainView.Action.HOST_VM_SELECTION_CHANGED)); + } + + @Category(GUITest.class) + @Test public void testHostVMTreeFilterPropertySupport() { frameFixture.show(); JTextComponentFixture hostVMTreeFilterField = frameFixture.textBox("hostVMTreeFilter"); @@ -138,6 +138,25 @@ @Category(GUITest.class) @Test + public void verifyHideMainWindowHidesWindow() { + GuiActionRunner.execute(new GuiTask() { + @Override + protected void executeInEDT() throws Throwable { + window.showMainWindow(); + } + }); + frameFixture.requireVisible(); + GuiActionRunner.execute(new GuiTask() { + @Override + protected void executeInEDT() throws Throwable { + window.hideMainWindow(); + } + }); + frameFixture.requireNotVisible(); + } + + @Category(GUITest.class) + @Test public void verifyThatClientPreferencesMenuItemTriggersEvent() { frameFixture.show(); JMenuItemFixture menuItem = frameFixture.menuItem("showClientConfig"); @@ -146,9 +165,21 @@ frameFixture.requireNotVisible(); verify(l).actionPerformed(new ActionEvent<MainView.Action>(window, MainView.Action.SHOW_CLIENT_CONFIG)); + } + @Category(GUITest.class) + @Test + public void verifyThatAgentPreferencesMenuItemTriggersEvent() { + frameFixture.show(); + JMenuItemFixture menuItem = frameFixture.menuItem("showAgentConfig"); + menuItem.click(); + frameFixture.close(); + frameFixture.requireNotVisible(); + + verify(l).actionPerformed(new ActionEvent<MainView.Action>(window, MainView.Action.SHOW_AGENT_CONFIG)); } + @Category(GUITest.class) @Test public void verifyThatHistorySwitchTriggersEvent() { @@ -171,5 +202,14 @@ assertEquals("test", actual); } + @Category(GUITest.class) + @Test + public void testGetSelectedHostOrVm() { + frameFixture.show(); + JTreeFixture hostVMTree = frameFixture.tree("agentVmTree"); + hostVMTree.selectRow(0); + + assertEquals(null, window.getSelectedHostOrVm()); + } }