]> source.dussan.org Git - vaadin-framework.git/commitdiff
Enable showing and hiding log
authorArtur Signell <artur.signell@itmill.com>
Sun, 7 Nov 2010 13:30:06 +0000 (13:30 +0000)
committerArtur Signell <artur.signell@itmill.com>
Sun, 7 Nov 2010 13:30:06 +0000 (13:30 +0000)
svn changeset:15902/svn branch:6.4

tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java
tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java

index aa7da25e7e130adb546dc722877c1195df1a1cfc..3ae303946887702e447a919ef9a83b61dc89482c 100644 (file)
@@ -8,7 +8,6 @@ import java.util.Locale;
 import com.vaadin.terminal.Resource;
 import com.vaadin.terminal.ThemeResource;
 import com.vaadin.terminal.UserError;
-import com.vaadin.tests.util.Log;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.Field;
 import com.vaadin.ui.Layout.SpacingHandler;
@@ -39,8 +38,6 @@ public abstract class AbstractComponentTestCase<T extends AbstractComponent>
 
     abstract protected void initializeComponents();
 
-    private Log log = null;
-
     @Override
     protected void setup() {
         ((SpacingHandler) getLayout()).setSpacing(true);
@@ -197,22 +194,12 @@ public abstract class AbstractComponentTestCase<T extends AbstractComponent>
 
     protected <VALUET> void doCommand(String commandName,
             Command<T, VALUET> command, VALUET value) {
-        doCommand(command, value, null);
-        if (hasLog()) {
-            log(commandName + ": " + value);
-        }
+        doCommand(commandName, command, value, null);
     }
 
     protected <VALUET> void doCommand(String commandName,
             Command<T, VALUET> command, VALUET value, Object data) {
         doCommand(command, value, data);
-        if (hasLog()) {
-            log(commandName + ": " + value);
-        }
-    }
-
-    protected boolean hasLog() {
-        return log != null;
     }
 
     @Override
@@ -220,23 +207,4 @@ public abstract class AbstractComponentTestCase<T extends AbstractComponent>
         return "Generic test case for " + getTestClass().getSimpleName();
     }
 
-    protected void clearLog() {
-        log.clear();
-    }
-
-    protected void enableLog() {
-        if (log == null) {
-            log = new Log(5).setNumberLogRows(true);
-            getLayout().addComponent(log, 1);
-        }
-
-    }
-
-    protected void log(String msg) {
-        if (log == null) {
-            throw new IllegalStateException(
-                    "Use enableLog() before calling log()");
-        }
-        log.log(msg);
-    }
 }
index d3675b0b3f134c1a530262edfe032b781270dba4..dfe1b675a69ea42f797b0fc74d6cfaad2ba73be7 100644 (file)
@@ -10,6 +10,7 @@ import java.util.Set;
 \r
 import com.vaadin.terminal.Resource;\r
 import com.vaadin.terminal.ThemeResource;\r
+import com.vaadin.tests.util.Log;\r
 import com.vaadin.tests.util.LoremIpsum;\r
 import com.vaadin.ui.AbstractComponent;\r
 import com.vaadin.ui.MenuBar;\r
@@ -29,22 +30,28 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent>
     private static final Resource SELECTED_ICON = new ThemeResource(\r
             "../runo/icons/16/ok.png");\r
 \r
+    // Menu related\r
+\r
     private MenuItem mainMenu;\r
 \r
     private MenuBar menu;\r
 \r
+    private MenuItem settingsMenu;\r
+\r
     private T component;\r
 \r
     // Used to determine if a menuItem should be selected and the other\r
     // unselected on click\r
     private Set<MenuItem> parentOfSelectableMenuItem = new HashSet<MenuItem>();\r
-    private MenuItem windowMenu;\r
 \r
     /**\r
      * Maps the category name to a menu item\r
      */\r
     private Map<String, MenuItem> categoryToMenuItem = new HashMap<String, MenuItem>();\r
 \r
+    // Logging\r
+    private Log log;\r
+\r
     protected static final String CATEGORY_STATE = "State";\r
     protected static final String CATEGORY_SIZE = "Size";\r
     protected static final String CATEGORY_SELECTION = "Selection";\r
@@ -57,21 +64,50 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent>
         setTheme("tests-components");\r
 \r
         // Create menu here so it appears before the components\r
-        menu = new MenuBar();\r
-        menu.setDebugId("menu");\r
-        mainMenu = menu.addItem("Component", null);\r
-        windowMenu = menu.addItem("Test", null);\r
-        addComponent(menu);\r
+        addComponent(createMainMenu());\r
 \r
         getLayout().setSizeFull();\r
-        enableLog();\r
+        createLog();\r
         super.setup();\r
 \r
         // Create menu actions and trigger default actions\r
         createActions();\r
 \r
         // Clear initialization log messages\r
-        clearLog();\r
+        log.clear();\r
+    }\r
+\r
+    private MenuBar createMainMenu() {\r
+        menu = new MenuBar();\r
+        menu.setDebugId("menu");\r
+        mainMenu = menu.addItem("Component", null);\r
+        settingsMenu = menu.addItem("Settings", null);\r
+        createSettingsMenu();\r
+\r
+        return menu;\r
+    }\r
+\r
+    private void createSettingsMenu() {\r
+        MenuItem showEventLog = settingsMenu.addItem("Show event log",\r
+                new MenuBar.Command() {\r
+\r
+                    public void menuSelected(MenuItem selectedItem) {\r
+                        boolean selected = !isSelected(selectedItem);\r
+                        setLogVisible(selected);\r
+                        setSelected(selectedItem, selected);\r
+                    }\r
+\r
+                });\r
+        setSelected(showEventLog, true);\r
+    }\r
+\r
+    protected void setLogVisible(boolean visible) {\r
+        log.setVisible(visible);\r
+    }\r
+\r
+    private void createLog() {\r
+        log = new Log(5).setNumberLogRows(true);\r
+        getLayout().addComponent(log, 1);\r
     }\r
 \r
     /**\r
@@ -452,4 +488,21 @@ public abstract class MenuBasedComponentTestCase<T extends AbstractComponent>
         }\r
     }\r
 \r
+    protected void log(String msg) {\r
+        log.log(msg);\r
+    }\r
+\r
+    protected boolean hasLog() {\r
+        return log != null;\r
+    }\r
+\r
+    @Override\r
+    protected <VALUET> void doCommand(String commandName,\r
+            AbstractComponentTestCase.Command<T, VALUET> command, VALUET value,\r
+            Object data) {\r
+        if (hasLog()) {\r
+            log("Command: " + commandName + "(" + value + ")");\r
+        }\r
+        super.doCommand(commandName, command, value, data);\r
+    }\r
 }\r