From: Artur Signell Date: Sun, 7 Nov 2010 13:30:06 +0000 (+0000) Subject: Enable showing and hiding log X-Git-Tag: 6.7.0.beta1~883^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8955ae4af7eb58b7b184b63c913d9cbd00e65869;p=vaadin-framework.git Enable showing and hiding log svn changeset:15902/svn branch:6.4 --- diff --git a/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java b/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java index aa7da25e7e..3ae3039468 100644 --- a/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java +++ b/tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java @@ -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 abstract protected void initializeComponents(); - private Log log = null; - @Override protected void setup() { ((SpacingHandler) getLayout()).setSpacing(true); @@ -197,22 +194,12 @@ public abstract class AbstractComponentTestCase protected void doCommand(String commandName, Command command, VALUET value) { - doCommand(command, value, null); - if (hasLog()) { - log(commandName + ": " + value); - } + doCommand(commandName, command, value, null); } protected void doCommand(String commandName, Command 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 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); - } } diff --git a/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java b/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java index d3675b0b3f..dfe1b675a6 100644 --- a/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java +++ b/tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java @@ -10,6 +10,7 @@ import java.util.Set; import com.vaadin.terminal.Resource; import com.vaadin.terminal.ThemeResource; +import com.vaadin.tests.util.Log; import com.vaadin.tests.util.LoremIpsum; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.MenuBar; @@ -29,22 +30,28 @@ public abstract class MenuBasedComponentTestCase private static final Resource SELECTED_ICON = new ThemeResource( "../runo/icons/16/ok.png"); + // Menu related + private MenuItem mainMenu; private MenuBar menu; + private MenuItem settingsMenu; + private T component; // Used to determine if a menuItem should be selected and the other // unselected on click private Set parentOfSelectableMenuItem = new HashSet(); - private MenuItem windowMenu; /** * Maps the category name to a menu item */ private Map categoryToMenuItem = new HashMap(); + // Logging + private Log log; + protected static final String CATEGORY_STATE = "State"; protected static final String CATEGORY_SIZE = "Size"; protected static final String CATEGORY_SELECTION = "Selection"; @@ -57,21 +64,50 @@ public abstract class MenuBasedComponentTestCase setTheme("tests-components"); // Create menu here so it appears before the components - menu = new MenuBar(); - menu.setDebugId("menu"); - mainMenu = menu.addItem("Component", null); - windowMenu = menu.addItem("Test", null); - addComponent(menu); + addComponent(createMainMenu()); getLayout().setSizeFull(); - enableLog(); + createLog(); super.setup(); // Create menu actions and trigger default actions createActions(); // Clear initialization log messages - clearLog(); + log.clear(); + } + + private MenuBar createMainMenu() { + menu = new MenuBar(); + menu.setDebugId("menu"); + mainMenu = menu.addItem("Component", null); + settingsMenu = menu.addItem("Settings", null); + createSettingsMenu(); + + return menu; + } + + private void createSettingsMenu() { + MenuItem showEventLog = settingsMenu.addItem("Show event log", + new MenuBar.Command() { + + public void menuSelected(MenuItem selectedItem) { + boolean selected = !isSelected(selectedItem); + setLogVisible(selected); + setSelected(selectedItem, selected); + } + + }); + setSelected(showEventLog, true); + } + + protected void setLogVisible(boolean visible) { + log.setVisible(visible); + } + + private void createLog() { + log = new Log(5).setNumberLogRows(true); + getLayout().addComponent(log, 1); } /** @@ -452,4 +488,21 @@ public abstract class MenuBasedComponentTestCase } } + protected void log(String msg) { + log.log(msg); + } + + protected boolean hasLog() { + return log != null; + } + + @Override + protected void doCommand(String commandName, + AbstractComponentTestCase.Command command, VALUET value, + Object data) { + if (hasLog()) { + log("Command: " + commandName + "(" + value + ")"); + } + super.doCommand(commandName, command, value, data); + } }