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;
abstract protected void initializeComponents();
- private Log log = null;
-
@Override
protected void setup() {
((SpacingHandler) getLayout()).setSpacing(true);
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
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);
- }
}
\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
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
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
}\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