Mercurial > hg > release > thermostat-0.15
changeset 231:9d74f4672d6c
Add initial history mode to GUI clients.
reviewed-by: omajid
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-April/000824.html
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Fri, 13 Apr 2012 19:57:01 +0200 |
parents | 9e23a7bfdbef |
children | 023cdedfdb8c |
files | client/src/main/java/com/redhat/thermostat/client/MainView.java client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java client/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java client/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java client/src/main/resources/com/redhat/thermostat/client/locale/strings.properties client/src/test/java/com/redhat/thermostat/client/MainWindowControllerImplTest.java client/src/test/java/com/redhat/thermostat/client/ui/MainWindowTest.java |
diffstat | 7 files changed, 75 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/main/java/com/redhat/thermostat/client/MainView.java Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/MainView.java Fri Apr 13 19:57:01 2012 +0200 @@ -45,6 +45,7 @@ HOST_VM_TREE_FILTER, SHOW_AGENT_CONFIG, SHOW_CLIENT_CONFIG, + SWITCH_HISTORY_MODE, SHUTDOWN, }
--- a/client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/MainWindowControllerImpl.java Fri Apr 13 19:57:01 2012 +0200 @@ -66,6 +66,8 @@ private final HostInfoDAO hostsDAO; private final VmInfoDAO vmsDAO; + private boolean showHistory; + public MainWindowControllerImpl(MainView view) { ApplicationContext ctx = ApplicationContext.getInstance(); @@ -82,7 +84,11 @@ @Override public Collection<HostRef> getHosts() { - return hostsDAO.getAliveHosts(); + if (showHistory) { + return hostsDAO.getHosts(); + } else { + return hostsDAO.getAliveHosts(); + } } @Override @@ -145,6 +151,9 @@ case SHOW_CLIENT_CONFIG: showConfigureClientPreferences(); break; + case SWITCH_HISTORY_MODE: + switchHistoryMode(); + break; case SHUTDOWN: stop(); break; @@ -174,5 +183,9 @@ ClientConfigurationController controller = new ClientConfigurationController(prefs, view); controller.showDialog(); } - + + private void switchHistoryMode() { + showHistory = !showHistory; + doUpdateTreeAsync(); + } }
--- a/client/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Fri Apr 13 19:57:01 2012 +0200 @@ -58,9 +58,10 @@ MENU_EDIT, MENU_EDIT_CONFIGURE_AGENT, MENU_EDIT_CONFIGURE_CLIENT, + MENU_EDIT_ENABLE_HISTORY_MODE, MENU_HELP, MENU_HELP_ABOUT, - + GARBAGE_COLLECTION, YOUNG_GEN, EDEN_GEN,
--- a/client/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/MainWindow.java Fri Apr 13 19:57:01 2012 +0200 @@ -55,6 +55,7 @@ import java.util.concurrent.ExecutionException; import javax.swing.BorderFactory; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; @@ -314,7 +315,19 @@ } }); editMenu.add(configureClientMenuItem); - + + editMenu.addSeparator(); + JMenuItem historyModeMenuItem = new JCheckBoxMenuItem(localize(LocaleResources.MENU_EDIT_ENABLE_HISTORY_MODE)); + historyModeMenuItem.setName("historyModeSwitch"); + historyModeMenuItem.setSelected(false); + historyModeMenuItem.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fireViewAction(Action.SWITCH_HISTORY_MODE); + } + }); + + editMenu.add(historyModeMenuItem); JMenu helpMenu = new JMenu(localize(LocaleResources.MENU_HELP)); helpMenu.getPopupMenu().setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1)); mainMenuBar.add(helpMenu);
--- a/client/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Fri Apr 13 19:57:01 2012 +0200 @@ -18,6 +18,7 @@ MENU_EDIT = Edit MENU_EDIT_CONFIGURE_AGENT = Configure Agent... MENU_EDIT_CONFIGURE_CLIENT = Client Preferences... +MENU_EDIT_ENABLE_HISTORY_MODE = Enable History Mode MENU_HELP = Help MENU_HELP_ABOUT = About
--- a/client/src/test/java/com/redhat/thermostat/client/MainWindowControllerImplTest.java Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/test/java/com/redhat/thermostat/client/MainWindowControllerImplTest.java Fri Apr 13 19:57:01 2012 +0200 @@ -150,7 +150,7 @@ controller.showMainMainWindow(); verify(view).showMainWindow(); } - + @Test public void verifyUpdateHostsVMsLoadsCorrectHosts() { @@ -171,6 +171,35 @@ } @Test + public void verifyHistoryModeUpdateHostsVMCorrectly() { + + Collection<HostRef> liveHost = new ArrayList<>(); + liveHost.add(new HostRef("123", "fluffhost1")); + liveHost.add(new HostRef("456", "fluffhost2")); + + Collection<HostRef> allHosts = new ArrayList<>(); + allHosts.addAll(liveHost); + allHosts.add(new HostRef("789", "fluffhost3")); + + when(mockHostsDAO.getAliveHosts()).thenReturn(liveHost); + when(mockHostsDAO.getHosts()).thenReturn(allHosts); + + controller.doUpdateTreeAsync(); + + ArgumentCaptor<HostsVMsLoader> arg = ArgumentCaptor.forClass(HostsVMsLoader.class); + verify(view).updateTree(anyString(), arg.capture()); + HostsVMsLoader loader = arg.getValue(); + + Collection<HostRef> actualHosts = loader.getHosts(); + assertEqualCollection(liveHost, actualHosts); + + l.actionPerformed(new ActionEvent<MainView.Action>(view, MainView.Action.SWITCH_HISTORY_MODE)); + + actualHosts = loader.getHosts(); + assertEqualCollection(allHosts, actualHosts); + } + + @Test public void verifyUpdateHostsVMsLoadsCorrectVMs() { Collection<VmRef> expectedVMs = new ArrayList<>();
--- a/client/src/test/java/com/redhat/thermostat/client/ui/MainWindowTest.java Fri Apr 13 13:14:21 2012 -0400 +++ b/client/src/test/java/com/redhat/thermostat/client/ui/MainWindowTest.java Fri Apr 13 19:57:01 2012 +0200 @@ -144,6 +144,18 @@ @Category(GUITest.class) @Test + public void verifyThatHistorySwitchTriggersEvent() { + frameFixture.show(); + JMenuItemFixture menuItem = frameFixture.menuItem("historyModeSwitch"); + menuItem.click(); + frameFixture.close(); + frameFixture.requireNotVisible(); + + verify(l).actionPerformed(new ActionEvent<MainView.Action>(window, MainView.Action.SWITCH_HISTORY_MODE)); + } + + @Category(GUITest.class) + @Test public void testGetHostVMTreeFilter() { frameFixture.show(); JTextComponentFixture hostVMTreeFilterField = frameFixture.textBox("hostVMTreeFilter");