New test Id mechanism for web #PL-2809

This commit is contained in:
Yuriy Artamonov 2013-12-20 15:26:50 +00:00
parent b4d6ddfb89
commit c83a2af126
27 changed files with 424 additions and 104 deletions

View File

@ -60,7 +60,7 @@ def webToolkitLegacyModule = project(':cuba-web6-toolkit')
def webModuleThemes = project(':cuba-web-themes') def webModuleThemes = project(':cuba-web-themes')
def webLegacyModuleThemes = project(':cuba-web6-themes') def webLegacyModuleThemes = project(':cuba-web6-themes')
def vaadinVersion = '7.1.8.cuba.8' def vaadinVersion = '7.1.8.cuba.9'
def vaadinLegacyVersion = '6.6.1.140' def vaadinLegacyVersion = '6.6.1.140'
def springVersion = '3.1.3.RELEASE' def springVersion = '3.1.3.RELEASE'

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2008-2013 Haulmont. All rights reserved.
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
*/
package com.haulmont.cuba.gui;
import java.util.HashMap;
import java.util.Map;
/**
* @author artamonov
* @version $Id$
*/
public class TestIdManager {
protected Map<String, Integer> ids = new HashMap<>();
public String getTestId(String baseId) {
String id = normalize(baseId);
Integer number = ids.get(id);
if (number == null) {
number = 0;
} else {
number++;
}
ids.put(id, number);
// prevent conflicts
while (ids.containsKey(id + number)) {
number++;
}
if (number > 0) {
id = id + number;
}
return id;
}
public String reserveId(String id) {
if (!ids.containsKey(id)) {
ids.put(id, 0);
}
return id;
}
public String normalize(String id) {
if (id != null) {
return id.replaceAll("[^\\p{L}\\p{Nd}]", "_");
}
return id;
}
public void reset() {
ids.clear();
}
}

View File

@ -321,7 +321,6 @@ public abstract class WindowManager {
if (template != null) { if (template != null) {
//noinspection unchecked //noinspection unchecked
window = createWindow(windowInfo, params, LayoutLoaderConfig.getWindowLoaders()); window = createWindow(windowInfo, params, LayoutLoaderConfig.getWindowLoaders());
window.setId(windowInfo.getId());
String caption = loadCaption(window, params); String caption = loadCaption(window, params);
String description = loadDescription(window, params); String description = loadDescription(window, params);
if (openType == OpenType.NEW_TAB) { if (openType == OpenType.NEW_TAB) {
@ -489,7 +488,7 @@ public abstract class WindowManager {
throw new IllegalStateException("Invalid WindowInfo: " + windowInfo); throw new IllegalStateException("Invalid WindowInfo: " + windowInfo);
} }
} }
window.setId(windowInfo.getId());
((Window.Lookup) window).setLookupHandler(handler); ((Window.Lookup) window).setLookupHandler(handler);
final String caption = loadCaption(window, params); final String caption = loadCaption(window, params);

View File

@ -52,7 +52,16 @@ public class CubaMenuBarConnector extends MenuBarConnector {
} }
@Override @Override
public boolean isUseMoreMenuItem() { protected boolean isUseMoreMenuItem() {
return !getState().vertical; return !getState().vertical;
} }
@Override
protected String getItemId(UIDL uidl) {
if (uidl.hasAttribute("testId")) {
return uidl.getStringAttribute("testId");
}
return null;
}
} }

View File

@ -31,7 +31,6 @@ public class CubaMenuBarWidget extends VMenuBar implements BlurHandler {
if (item.hasAttribute("separator")) { if (item.hasAttribute("separator")) {
itemHTML.append("<span>---</span><span>---</span>"); itemHTML.append("<span>---</span><span>---</span>");
} else { } else {
itemHTML.append("<span class=\"") itemHTML.append("<span class=\"")
.append(getStylePrimaryName()) .append(getStylePrimaryName())
.append("-menuitem-caption\">"); .append("-menuitem-caption\">");

View File

@ -8,6 +8,7 @@ package com.haulmont.cuba.web.toolkit.ui.client.tabsheet;
import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.ContextMenuEvent; import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.dom.client.FocusEvent; import com.google.gwt.event.dom.client.FocusEvent;
import com.vaadin.client.UIDL;
import com.vaadin.client.ui.VTabsheet; import com.vaadin.client.ui.VTabsheet;
/** /**
@ -41,4 +42,13 @@ public class CubaTabSheetWidget extends VTabsheet {
removeStyleDependentName("focus"); removeStyleDependentName("focus");
} }
@Override
protected void updateAdditionalProperties(UIDL tabUidl, Tab tab) {
super.updateAdditionalProperties(tabUidl, tab);
if (tabUidl.hasAttribute("testId")) {
tab.getElement().setId(tabUidl.getStringAttribute("testId"));
}
}
} }

View File

@ -68,8 +68,6 @@ public abstract class App {
protected boolean themeInitialized = false; protected boolean themeInitialized = false;
protected boolean testModeRequest = false;
protected String webResourceTimestamp = "null"; protected String webResourceTimestamp = "null";
protected String clientAddress; protected String clientAddress;
@ -305,10 +303,6 @@ public abstract class App {
themeInitialized = false; themeInitialized = false;
} }
public boolean isTestModeRequest() {
return testModeRequest;
}
public String getWebResourceTimestamp() { public String getWebResourceTimestamp() {
return webResourceTimestamp; return webResourceTimestamp;
} }

View File

@ -7,8 +7,10 @@ package com.haulmont.cuba.web;
import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration; import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.GlobalConfig;
import com.haulmont.cuba.core.global.MessageTools; import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.web.sys.LinkHandler; import com.haulmont.cuba.web.sys.LinkHandler;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.web.toolkit.ui.CubaJQueryIntegration; import com.haulmont.cuba.web.toolkit.ui.CubaJQueryIntegration;
import com.haulmont.cuba.web.toolkit.ui.CubaSWFObjectIntegration; import com.haulmont.cuba.web.toolkit.ui.CubaSWFObjectIntegration;
import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.annotations.PreserveOnRefresh;
@ -41,6 +43,10 @@ public class AppUI extends UI implements ErrorHandler {
protected boolean applicationInitRequired = false; protected boolean applicationInitRequired = false;
protected TestIdManager testIdManager = new TestIdManager();
protected boolean testMode = false;
public AppUI() { public AppUI() {
log.trace("Creating UI " + this); log.trace("Creating UI " + this);
if (!App.isBound()) { if (!App.isBound()) {
@ -66,11 +72,12 @@ public class AppUI extends UI implements ErrorHandler {
}); });
applicationInitRequired = true; applicationInitRequired = true;
} else { } else {
app = App.getInstance(); app = App.getInstance();
} }
testMode = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class).getTestMode();
// do not grab focus // do not grab focus
setTabIndex(-1); setTabIndex(-1);
@ -156,6 +163,14 @@ public class AppUI extends UI implements ErrorHandler {
} }
} }
public TestIdManager getTestIdManager() {
return testIdManager;
}
public boolean isTestMode() {
return testMode;
}
@Override @Override
public void error(com.vaadin.server.ErrorEvent event) { public void error(com.vaadin.server.ErrorEvent event) {
try { try {

View File

@ -216,7 +216,7 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH
clientManager.extend(rootLayout); clientManager.extend(rootLayout);
workerTimer = new CubaTimer(); workerTimer = new CubaTimer();
workerTimer.setId("backgroundWorkerTimer"); workerTimer.setId(ui.getTestIdManager().reserveId("backgroundWorkerTimer"));
rootLayout.addComponent(workerTimer); rootLayout.addComponent(workerTimer);
workerTimer.setRepeating(true); workerTimer.setRepeating(true);
@ -499,6 +499,7 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH
if (AppWindow.Mode.TABBED.equals(getMode())) { if (AppWindow.Mode.TABBED.equals(getMode())) {
if (tabSheet == null) { if (tabSheet == null) {
tabSheet = new AppWindow.AppTabSheet(); tabSheet = new AppWindow.AppTabSheet();
tabSheet.setId(ui.getTestIdManager().reserveId("appTabSheet"));
tabSheet.setSizeFull(); tabSheet.setSizeFull();
mainLayout.addComponent(tabSheet); mainLayout.addComponent(tabSheet);
mainLayout.setExpandRatio(tabSheet, 1); mainLayout.setExpandRatio(tabSheet, 1);
@ -622,9 +623,8 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH
menuBar.setWidth("100%"); menuBar.setWidth("100%");
menuBar.setMoreMenuItem(null); // force usage more item menu menuBar.setMoreMenuItem(null); // force usage more item menu
if (globalConfig.getTestMode()) { if (ui.isTestMode()) {
// vaadin7 test mode menuBar.setId(ui.getTestIdManager().reserveId("appMenu"));
// AppUI.getInstance().getWindowManager().setDebugId(menuBar, "appMenu");
} }
MenuBuilder menuBuilder = new MenuBuilder(this, connection.getSession(), menuBar); MenuBuilder menuBuilder = new MenuBuilder(this, connection.getSession(), menuBar);
@ -780,8 +780,8 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH
logoutBtn.addStyleName("nocaption"); logoutBtn.addStyleName("nocaption");
logoutBtn.setIcon(new VersionedThemeResource("app/images/exit.png")); logoutBtn.setIcon(new VersionedThemeResource("app/images/exit.png"));
// vaadin7 Debug ids disabled logoutBtn.setId(ui.getTestIdManager().reserveId("logoutBtn"));
// AppUI.getInstance().getWindowManager().setDebugId(logoutBtn, "logoutBtn");
return logoutBtn; return logoutBtn;
} }

View File

@ -64,7 +64,12 @@ public class DefaultApp extends App implements ConnectionListener {
} else { } else {
cleanupBackgroundTasks(); cleanupBackgroundTasks();
closeAllWindows(); closeAllWindows();
for (AppUI ui : getAppUIs()) { for (AppUI ui : getAppUIs()) {
if (ui.isTestMode()) {
ui.getTestIdManager().reset();
}
UIView window = createLoginWindow(ui); UIView window = createLoginWindow(ui);
ui.showView(window); ui.showView(window);
} }

View File

@ -12,6 +12,7 @@ import com.haulmont.cuba.web.auth.ActiveDirectoryConnection;
import com.haulmont.cuba.web.auth.ActiveDirectoryHelper; import com.haulmont.cuba.web.auth.ActiveDirectoryHelper;
import com.haulmont.cuba.web.auth.DomainAliasesResolver; import com.haulmont.cuba.web.auth.DomainAliasesResolver;
import com.haulmont.cuba.web.sys.Browser; import com.haulmont.cuba.web.sys.Browser;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource; import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.haulmont.cuba.web.toolkit.ui.CubaCheckBox; import com.haulmont.cuba.web.toolkit.ui.CubaCheckBox;
import com.vaadin.data.Property; import com.vaadin.data.Property;
@ -138,16 +139,18 @@ public class LoginWindow extends UIView implements Action.Handler {
setBaseStyle("cuba-login"); setBaseStyle("cuba-login");
initUI(); initUI();
// vaadin7 commented
// if (globalConfig.getTestMode()) { if (ui.isTestMode()) {
// WebWindowManager windowManager = app.getWindowManager(); TestIdManager testIdManager = ui.getTestIdManager();
// windowManager.setDebugId(loginField, "loginField");
// windowManager.setDebugId(passwordField, "pwdField"); loginField.setId(testIdManager.reserveId("loginField"));
// windowManager.setDebugId(localesSelect, "localesField"); passwordField.setId(testIdManager.reserveId("pwdField"));
// if (okButton != null) { localesSelect.setId(testIdManager.reserveId("localesField"));
// windowManager.setDebugId(okButton, "loginSubmitButton");
// } if (okButton != null) {
// } okButton.setId(testIdManager.reserveId("loginSubmitButton"));
}
}
addActionHandler(this); addActionHandler(this);
} }

View File

@ -51,6 +51,7 @@ public class WebWindowManager extends WindowManager {
private static Log log = LogFactory.getLog(WebWindowManager.class); private static Log log = LogFactory.getLog(WebWindowManager.class);
protected App app; protected App app;
protected AppUI ui;
protected AppWindow appWindow; protected AppWindow appWindow;
protected final WebConfig webConfig; protected final WebConfig webConfig;
@ -62,12 +63,11 @@ public class WebWindowManager extends WindowManager {
protected final Map<Window, Integer> windows = new HashMap<>(); protected final Map<Window, Integer> windows = new HashMap<>();
protected final Map<ComponentContainer, WindowBreadCrumbs> fakeTabs = new HashMap<>(); protected final Map<ComponentContainer, WindowBreadCrumbs> fakeTabs = new HashMap<>();
protected Map<String, Integer> debugIds = new HashMap<>();
protected boolean disableSavingScreenHistory; protected boolean disableSavingScreenHistory;
protected ScreenHistorySupport screenHistorySupport; protected ScreenHistorySupport screenHistorySupport;
public WebWindowManager(final App app, AppWindow appWindow) { public WebWindowManager(final App app, AppWindow appWindow) {
this.ui = app.getAppUI();
this.app = app; this.app = app;
this.appWindow = appWindow; this.appWindow = appWindow;
@ -343,6 +343,12 @@ public class WebWindowManager extends WindowManager {
newTab = tabSheet.getTab(layout); newTab = tabSheet.getTab(layout);
} else { } else {
newTab = tabSheet.addTab(layout); newTab = tabSheet.addTab(layout);
if (ui.isTestMode() && tabSheet instanceof CubaTabSheet) {
CubaTabSheet mainTabsheet = (CubaTabSheet) tabSheet;
mainTabsheet.setTestId(newTab, ui.getTestIdManager().getTestId("tab_" + window.getId()));
}
tabs.put(layout, (WindowBreadCrumbs) components[0]); tabs.put(layout, (WindowBreadCrumbs) components[0]);
} }
newTab.setCaption(formatTabCaption(caption, description)); newTab.setCaption(formatTabCaption(caption, description));
@ -485,10 +491,8 @@ public class WebWindowManager extends WindowManager {
protected Component showWindowDialog(final Window window, final String caption, final String description, protected Component showWindowDialog(final Window window, final String caption, final String description,
boolean forciblyDialog) { boolean forciblyDialog) {
final com.vaadin.ui.Window win = createDialogWindow(window); final com.vaadin.ui.Window win = createDialogWindow(window);
win.setId(window.getId()); setDebugId(win, "dialog_" + window.getId());
setDebugId(win, window.getId());
Layout layout = (Layout) WebComponentsHelper.getComposition(window); Layout layout = (Layout) WebComponentsHelper.getComposition(window);
@ -554,7 +558,7 @@ public class WebWindowManager extends WindowManager {
} }
win.setModal(true); win.setModal(true);
appWindow.getAppUI().addWindow(win); ui.addWindow(win);
win.center(); win.center();
return win; return win;
@ -568,7 +572,7 @@ public class WebWindowManager extends WindowManager {
protected com.vaadin.ui.Window createDialogWindow(Window window) { protected com.vaadin.ui.Window createDialogWindow(Window window) {
com.vaadin.ui.Window vWindow = new com.vaadin.ui.Window(window.getCaption()); com.vaadin.ui.Window vWindow = new com.vaadin.ui.Window(window.getCaption());
vWindow.setErrorHandler(app.getAppUI()); vWindow.setErrorHandler(ui);
return vWindow; return vWindow;
} }
@ -676,7 +680,7 @@ public class WebWindowManager extends WindowManager {
case DIALOG: { case DIALOG: {
final com.vaadin.ui.Window win = (com.vaadin.ui.Window) openMode.getData(); final com.vaadin.ui.Window win = (com.vaadin.ui.Window) openMode.getData();
removeCloseListeners(win); removeCloseListeners(win);
appWindow.getAppUI().removeWindow(win); ui.removeWindow(win);
fireListeners(window, tabs.size() != 0); fireListeners(window, tabs.size() != 0);
break; break;
} }
@ -804,7 +808,8 @@ public class WebWindowManager extends WindowManager {
public void showMessageDialog(String title, String message, IFrame.MessageType messageType) { public void showMessageDialog(String title, String message, IFrame.MessageType messageType) {
final com.vaadin.ui.Window window = new com.vaadin.ui.Window(title); final com.vaadin.ui.Window window = new com.vaadin.ui.Window(title);
window.setId("cuba-message-dialog"); window.setId("cuba-message-dialog");
setDebugId(window, "cuba-message-dialog");
setDebugId(window, "cubaMessageDialog");
window.addAction(new ShortcutListener("Esc", ShortcutAction.KeyCode.ESCAPE, null) { window.addAction(new ShortcutListener("Esc", ShortcutAction.KeyCode.ESCAPE, null) {
@Override @Override
@ -823,7 +828,7 @@ public class WebWindowManager extends WindowManager {
window.addCloseListener(new com.vaadin.ui.Window.CloseListener() { window.addCloseListener(new com.vaadin.ui.Window.CloseListener() {
@Override @Override
public void windowClose(com.vaadin.ui.Window.CloseEvent e) { public void windowClose(com.vaadin.ui.Window.CloseEvent e) {
appWindow.getAppUI().removeWindow(window); ui.removeWindow(window);
} }
}); });
@ -849,7 +854,7 @@ public class WebWindowManager extends WindowManager {
window.setResizable(false); window.setResizable(false);
window.setModal(true); window.setModal(true);
appWindow.getAppUI().addWindow(window); ui.addWindow(window);
window.center(); window.center();
window.focus(); window.focus();
} }
@ -864,7 +869,7 @@ public class WebWindowManager extends WindowManager {
window.addCloseListener(new com.vaadin.ui.Window.CloseListener() { window.addCloseListener(new com.vaadin.ui.Window.CloseListener() {
@Override @Override
public void windowClose(com.vaadin.ui.Window.CloseEvent e) { public void windowClose(com.vaadin.ui.Window.CloseEvent e) {
app.getAppUI().removeWindow(window); ui.removeWindow(window);
} }
}); });
@ -902,7 +907,7 @@ public class WebWindowManager extends WindowManager {
@Override @Override
public void buttonClick(Button.ClickEvent event) { public void buttonClick(Button.ClickEvent event) {
action.actionPerform(null); action.actionPerform(null);
app.getAppUI().removeWindow(window); ui.removeWindow(window);
} }
}); });
@ -940,7 +945,7 @@ public class WebWindowManager extends WindowManager {
layout.setExpandRatio(messageLab, 1); layout.setExpandRatio(messageLab, 1);
layout.setComponentAlignment(actionsBar, com.vaadin.ui.Alignment.BOTTOM_RIGHT); layout.setComponentAlignment(actionsBar, com.vaadin.ui.Alignment.BOTTOM_RIGHT);
appWindow.getAppUI().addWindow(window); ui.addWindow(window);
window.center(); window.center();
} }
@ -961,29 +966,30 @@ public class WebWindowManager extends WindowManager {
if (target == null) if (target == null)
target = "_blank"; target = "_blank";
if (width != null && height != null && border != null) { if (width != null && height != null && border != null) {
appWindow.getAppUI().getPage().open(url, target, width, height, BorderStyle.valueOf(border)); ui.getPage().open(url, target, width, height, BorderStyle.valueOf(border));
} else if (tryToOpenAsPopup != null) { } else if (tryToOpenAsPopup != null) {
appWindow.getAppUI().getPage().open(url, target, tryToOpenAsPopup); ui.getPage().open(url, target, tryToOpenAsPopup);
} else { } else {
appWindow.getAppUI().getPage().open(url, target, false); ui.getPage().open(url, target, false);
} }
} }
@Override @Override
protected void initDebugIds(final Window window) { protected void initDebugIds(final Window window) {
if (app.isTestModeRequest()) { if (ui.isTestMode()) {
com.haulmont.cuba.gui.ComponentsHelper.walkComponents(window, new ComponentVisitor() { com.haulmont.cuba.gui.ComponentsHelper.walkComponents(window, new ComponentVisitor() {
@Override @Override
public void visit(com.haulmont.cuba.gui.components.Component component, String name) { public void visit(com.haulmont.cuba.gui.components.Component component, String name) {
final String id = window.getId() + "." + name; if (component.getDebugId() == null) {
if (webConfig.getAllowIdSuffix()) { final String id;
component.setDebugId(generateDebugId(id)); String fullFrameId = ComponentsHelper.getFullFrameId(window);
} else {
if (component.getId() != null) { if (component.getId() != null) {
component.setDebugId(id); id = fullFrameId + "_" + component.getId();
} else { } else {
component.setDebugId(generateDebugId(id)); id = fullFrameId + "_" + name;
} }
component.setDebugId(ui.getTestIdManager().getTestId(id));
} }
} }
}); });
@ -1037,21 +1043,8 @@ public class WebWindowManager extends WindowManager {
} }
public void setDebugId(Component component, String id) { public void setDebugId(Component component, String id) {
if (app.isTestModeRequest()) { if (ui.isTestMode()) {
if (webConfig.getAllowIdSuffix()) { component.setId(ui.getTestIdManager().getTestId(id));
component.setId(generateDebugId(id));
} else {
component.setId(id);
} }
} }
} }
protected String generateDebugId(String id) {
Integer count = debugIds.get(id);
if (count == null) {
count = 0;
}
debugIds.put(id, ++count);
return id + "." + count;
}
}

View File

@ -9,6 +9,7 @@ import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.gui.GuiDevelopmentException; import com.haulmont.cuba.gui.GuiDevelopmentException;
import com.haulmont.cuba.gui.config.WindowConfig; import com.haulmont.cuba.gui.config.WindowConfig;
import com.haulmont.cuba.security.entity.User; import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.WebConfig; import com.haulmont.cuba.web.WebConfig;
import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.shared.ui.label.ContentMode;
@ -56,7 +57,10 @@ public class ExceptionDialog extends Window {
} }
public ExceptionDialog(Throwable throwable, @Nullable String caption, @Nullable String message) { public ExceptionDialog(Throwable throwable, @Nullable String caption, @Nullable String message) {
super(); if (AppUI.getCurrent().isTestMode()) {
setId(AppUI.getCurrent().getTestIdManager().getTestId("exceptionDialog"));
}
setCaption(caption != null ? caption : messages.getMessage(getClass(), "exceptionDialog.caption")); setCaption(caption != null ? caption : messages.getMessage(getClass(), "exceptionDialog.caption"));
setWidth(600, Unit.PIXELS); setWidth(600, Unit.PIXELS);
center(); center();

View File

@ -10,7 +10,6 @@ import com.haulmont.cuba.client.ClientConfig;
import com.haulmont.cuba.core.entity.Entity; import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration; import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.GlobalConfig;
import com.haulmont.cuba.core.global.Messages; import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.*; import com.haulmont.cuba.gui.*;
import com.haulmont.cuba.gui.components.*; import com.haulmont.cuba.gui.components.*;
@ -620,6 +619,10 @@ public class WebWindow implements Window, Component.Wrapper,
@Override @Override
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
if (AppUI.getCurrent().isTestMode() && StringUtils.isEmpty(debugId)) {
setDebugId(id);
}
} }
@Override @Override
@ -630,6 +633,10 @@ public class WebWindow implements Window, Component.Wrapper,
@Override @Override
public void setDebugId(String debugId) { public void setDebugId(String debugId) {
this.debugId = debugId; this.debugId = debugId;
if (debugId != null) {
component.setId(AppUI.getCurrent().getTestIdManager().getTestId("window_" + debugId));
}
} }
@Override @Override
@ -1179,12 +1186,10 @@ public class WebWindow implements Window, Component.Wrapper,
public void setId(String id) { public void setId(String id) {
super.setId(id); super.setId(id);
Configuration configuration = AppBeans.get(Configuration.NAME); if (debugId != null) {
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
if (configuration.getConfig(GlobalConfig.class).getTestMode()) { selectButton.setId(testIdManager.getTestId(debugId + "_selectButton"));
WebWindowManager windowManager = getWindowManager(); cancelButton.setId(testIdManager.getTestId(debugId + "_cancelButton"));
windowManager.setDebugId(selectButton, id + ".selectButton");
windowManager.setDebugId(cancelButton, id + ".cancelButton");
} }
} }
} }

View File

@ -4,10 +4,13 @@
*/ */
package com.haulmont.cuba.web.gui.components; package com.haulmont.cuba.web.gui.components;
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.IFrame; import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.web.AppUI;
import com.vaadin.server.Sizeable; import com.vaadin.server.Sizeable;
import com.vaadin.ui.Layout; import com.vaadin.ui.Layout;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element; import org.dom4j.Element;
import java.util.Arrays; import java.util.Arrays;
@ -45,6 +48,17 @@ public class WebAbstractComponent<T extends com.vaadin.ui.Component>
public void setFrame(IFrame frame) { public void setFrame(IFrame frame) {
this.frame = frame; this.frame = frame;
frame.registerComponent(this); frame.registerComponent(this);
assignAutoDebugId(frame);
}
protected void assignAutoDebugId(IFrame frame) {
if (frame.getId() == null)
return;
if (AppUI.getCurrent().isTestMode() && StringUtils.isEmpty(getDebugId()) && StringUtils.isNotEmpty(id)) {
setDebugId(AppUI.getCurrent().getTestIdManager().getTestId(ComponentsHelper.getFullFrameId(frame) + "." + id));
}
} }
@Override @Override

View File

@ -6,8 +6,11 @@ package com.haulmont.cuba.web.gui.components;
import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration; import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.components.Action; import com.haulmont.cuba.gui.components.Action;
import com.haulmont.cuba.gui.components.Button; import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.WebConfig; import com.haulmont.cuba.web.WebConfig;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource; import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.vaadin.ui.NativeButton; import com.vaadin.ui.NativeButton;
@ -106,6 +109,18 @@ public class WebButton
} }
} }
); );
AppUI ui = AppUI.getCurrent();
if (ui.isTestMode() && StringUtils.isEmpty(getDebugId()) && frame != null) {
String id = getId();
if (StringUtils.isEmpty(id))
id = action.getId();
if (StringUtils.isNotEmpty(id)) {
setDebugId(ui.getTestIdManager().getTestId(ComponentsHelper.getFullFrameId(frame) + "." + id));
}
}
} }
@Override @Override
@ -131,4 +146,23 @@ public class WebButton
component.removeStyleName(ICON_STYLE); component.removeStyleName(ICON_STYLE);
} }
} }
@Override
protected void assignAutoDebugId(IFrame frame) {
if (frame.getId() == null)
return;
AppUI ui = AppUI.getCurrent();
if (ui.isTestMode() && StringUtils.isEmpty(getDebugId())) {
String id = getId();
if (StringUtils.isEmpty(id) && action != null)
id = action.getId();
if (StringUtils.isNotEmpty(id)) {
setDebugId(ui.getTestIdManager().getTestId(ComponentsHelper.getFullFrameId(frame) + "." + id));
}
}
}
} }

View File

@ -12,6 +12,7 @@ import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MessageTools; import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.UserSessionSource; import com.haulmont.cuba.core.global.UserSessionSource;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.components.DateField; import com.haulmont.cuba.gui.components.DateField;
import com.haulmont.cuba.gui.components.Field; import com.haulmont.cuba.gui.components.Field;
import com.haulmont.cuba.gui.components.RequiredValueMissingException; import com.haulmont.cuba.gui.components.RequiredValueMissingException;
@ -20,6 +21,7 @@ import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.ValueChangingListener; import com.haulmont.cuba.gui.data.ValueChangingListener;
import com.haulmont.cuba.gui.data.ValueListener; import com.haulmont.cuba.gui.data.ValueListener;
import com.haulmont.cuba.gui.data.impl.DsListenerAdapter; import com.haulmont.cuba.gui.data.impl.DsListenerAdapter;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.toolkit.ui.CubaDateField; import com.haulmont.cuba.web.toolkit.ui.CubaDateField;
import com.haulmont.cuba.web.toolkit.ui.CubaDateFieldWrapper; import com.haulmont.cuba.web.toolkit.ui.CubaDateFieldWrapper;
import com.haulmont.cuba.web.toolkit.ui.CubaMaskedTextField; import com.haulmont.cuba.web.toolkit.ui.CubaMaskedTextField;
@ -192,6 +194,17 @@ public class WebDateField extends WebAbstractField<CubaDateFieldWrapper> impleme
updateInstance(); updateInstance();
} }
@Override
public void setDebugId(String id) {
super.setDebugId(id);
if (getDebugId() != null) {
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
timeField.setDebugId(testIdManager.getTestId(id + "_time"));
dateField.setId(testIdManager.getTestId(id + "_date"));
}
}
protected void setValueFromDs(Object value) { protected void setValueFromDs(Object value) {
boolean isEditable = editable; boolean isEditable = editable;
if (!editable) { if (!editable) {

View File

@ -15,6 +15,7 @@ import com.haulmont.cuba.gui.components.Field;
import com.haulmont.cuba.gui.data.CollectionDatasource; import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.Datasource; import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.DsContext; import com.haulmont.cuba.gui.data.DsContext;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.toolkit.ui.CubaCheckBox; import com.haulmont.cuba.web.toolkit.ui.CubaCheckBox;
import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroup; import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroup;
import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroupLayout; import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroupLayout;
@ -80,11 +81,12 @@ public class WebFieldGroup
@Override @Override
public void setDebugId(String id) { public void setDebugId(String id) {
super.setDebugId(id); super.setDebugId(id);
final List<FieldConfig> fieldConfs = getFields(); final List<FieldConfig> fieldConfs = getFields();
for (final FieldConfig fieldConf : fieldConfs) { for (final FieldConfig fieldConf : fieldConfs) {
com.vaadin.ui.Field field = component.getField(fieldConf.getId()); com.vaadin.ui.Field field = component.getField(fieldConf.getId());
if (field != null) { if (field != null) {
field.setId(id + ":" + fieldConf.getId()); field.setId(AppUI.getCurrent().getTestIdManager().getTestId(id + "_" + fieldConf.getId()));
} }
} }
} }
@ -199,6 +201,10 @@ public class WebFieldGroup
((CubaCheckBox) fieldImpl).setCaptionManagedByLayout(true); ((CubaCheckBox) fieldImpl).setCaptionManagedByLayout(true);
} }
if (StringUtils.isEmpty(fieldComponent.getId())) {
fieldComponent.setId(fieldConf.getId());
}
assignTypicalAttributes(fieldComponent); assignTypicalAttributes(fieldComponent);
MetaPropertyPath propertyPath = fieldDatasource.getMetaClass().getPropertyPath(id); MetaPropertyPath propertyPath = fieldDatasource.getMetaClass().getPropertyPath(id);

View File

@ -19,6 +19,7 @@ import com.haulmont.cuba.core.entity.BaseUuidEntity;
import com.haulmont.cuba.core.entity.Entity; import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.*; import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.gui.ComponentsHelper; import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.WindowManager; import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.WindowParams; import com.haulmont.cuba.gui.WindowParams;
import com.haulmont.cuba.gui.components.*; import com.haulmont.cuba.gui.components.*;
@ -40,6 +41,7 @@ import com.haulmont.cuba.security.entity.FilterEntity;
import com.haulmont.cuba.security.entity.SearchFolder; import com.haulmont.cuba.security.entity.SearchFolder;
import com.haulmont.cuba.security.entity.User; import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.web.App; import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.WebWindowManager; import com.haulmont.cuba.web.WebWindowManager;
import com.haulmont.cuba.web.app.folders.AppFolderEditWindow; import com.haulmont.cuba.web.app.folders.AppFolderEditWindow;
import com.haulmont.cuba.web.app.folders.FolderEditWindow; import com.haulmont.cuba.web.app.folders.FolderEditWindow;
@ -178,7 +180,6 @@ public class WebFilter extends WebAbstractComponent<CubaVerticalActionsLayout> i
select.addValueChangeListener(new SelectListener()); select.addValueChangeListener(new SelectListener());
select.setTextInputAllowed(false); select.setTextInputAllowed(false);
App.getInstance().getWindowManager().setDebugId(select, "genericFilterSelect");
topLayout.addComponent(select); topLayout.addComponent(select);
applyBtn = WebComponentsHelper.createButton("icons/search.png"); applyBtn = WebComponentsHelper.createButton("icons/search.png");
@ -189,7 +190,6 @@ public class WebFilter extends WebAbstractComponent<CubaVerticalActionsLayout> i
apply(false); apply(false);
} }
}); });
App.getInstance().getWindowManager().setDebugId(applyBtn, "genericFilterApplyBtn");
topLayout.addComponent(applyBtn); topLayout.addComponent(applyBtn);
if (globalConfig.getAllowQueryFromSelected()) { if (globalConfig.getAllowQueryFromSelected()) {
@ -1093,6 +1093,36 @@ public class WebFilter extends WebAbstractComponent<CubaVerticalActionsLayout> i
}); });
} }
@Override
public void setDebugId(String id) {
super.setDebugId(id);
String debugId = getDebugId();
if (debugId != null) {
WebWindowManager wm = App.getInstance().getWindowManager();
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
select.setId(testIdManager.getTestId(debugId + "_filterSelect"));
if (applyBtn != null) {
applyBtn.setId(testIdManager.getTestId(debugId + "_applyBtn"));
}
if (maxResultsLayout != null) {
maxResultsField.setId(testIdManager.getTestId(debugId + "_maxResultsField"));
maxResultsCb.setId(testIdManager.getTestId(debugId + "_maxResultsCheckBox"));
}
if (actionsButton != null) {
actionsButton.setDebugId(testIdManager.getTestId(debugId + "_actionsBtn"));
}
if (pinAppliedFilterBtn != null) {
wm.setDebugId(pinAppliedFilterBtn, debugId + "_pinAppliedBtn");
}
}
}
@Override @Override
public CollectionDatasource getDatasource() { public CollectionDatasource getDatasource() {
return datasource; return datasource;

View File

@ -12,11 +12,14 @@ import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MessageTools; import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.Metadata; import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.core.global.MetadataTools; import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.components.Action; import com.haulmont.cuba.gui.components.Action;
import com.haulmont.cuba.gui.components.CaptionMode; import com.haulmont.cuba.gui.components.CaptionMode;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.PickerField; import com.haulmont.cuba.gui.components.PickerField;
import com.haulmont.cuba.gui.data.Datasource; import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.impl.DsListenerAdapter; import com.haulmont.cuba.gui.data.impl.DsListenerAdapter;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.gui.data.ItemWrapper; import com.haulmont.cuba.web.gui.data.ItemWrapper;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource; import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.haulmont.cuba.web.toolkit.ui.CubaPickerField; import com.haulmont.cuba.web.toolkit.ui.CubaPickerField;
@ -239,6 +242,29 @@ public class WebPickerField
if (action instanceof StandardAction) { if (action instanceof StandardAction) {
((StandardAction) action).setEditable(isEditable()); ((StandardAction) action).setEditable(isEditable());
} }
if (StringUtils.isNotEmpty(getDebugId())) {
pButton.setDebugId(AppUI.getCurrent().getTestIdManager().getTestId(getDebugId() + "_" + action.getId()));
}
}
@Override
public void setDebugId(String id) {
super.setDebugId(id);
String debugId = getDebugId();
if (debugId != null) {
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
for (Action action : actions) {
if (action.getOwner() != null && action.getOwner() instanceof WebButton) {
WebButton button = (WebButton) action.getOwner();
if (StringUtils.isEmpty(button.getDebugId())) {
button.setDebugId(testIdManager.getTestId(debugId + "_" + action.getId()));
}
}
}
}
} }
@Override @Override

View File

@ -4,9 +4,11 @@
*/ */
package com.haulmont.cuba.web.gui.components; package com.haulmont.cuba.web.gui.components;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.components.Action; import com.haulmont.cuba.gui.components.Action;
import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.KeyCombination; import com.haulmont.cuba.gui.components.KeyCombination;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource; import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.BaseTheme; import com.vaadin.ui.themes.BaseTheme;
@ -144,6 +146,28 @@ public class WebPopupButton
((com.vaadin.ui.Layout) vPopupComponent).addComponent(vButton); ((com.vaadin.ui.Layout) vPopupComponent).addComponent(vButton);
component.markAsDirty(); component.markAsDirty();
actionOrder.add(action); actionOrder.add(action);
String debugId = getDebugId();
if (debugId != null) {
button.setDebugId(AppUI.getCurrent().getTestIdManager().getTestId(debugId + "_" + action.getId()));
}
}
}
@Override
public void setDebugId(String id) {
super.setDebugId(id);
String debugId = getDebugId();
if (debugId != null) {
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
for (Action action : getActions()) {
WebButton button = (WebButton) action.getOwner();
if (StringUtils.isEmpty(button.getDebugId())) {
button.setDebugId(testIdManager.getTestId(debugId + "_" + action.getId()));
}
}
} }
} }
@ -179,6 +203,10 @@ public class WebPopupButton
this.action = action; this.action = action;
} }
private Action getAction() {
return action;
}
@Override @Override
public void actionPerform(Component component) { public void actionPerform(Component component) {
WebPopupButton.this.component.setPopupVisible(false); WebPopupButton.this.component.setPopupVisible(false);

View File

@ -7,6 +7,7 @@ package com.haulmont.cuba.web.gui.components;
import com.haulmont.cuba.gui.AppConfig; import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.ComponentVisitor; import com.haulmont.cuba.gui.ComponentVisitor;
import com.haulmont.cuba.gui.ComponentsHelper; import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.IFrame; import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.TabSheet; import com.haulmont.cuba.gui.components.TabSheet;
@ -14,6 +15,7 @@ import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.data.impl.DsContextImplementation; import com.haulmont.cuba.gui.data.impl.DsContextImplementation;
import com.haulmont.cuba.gui.settings.Settings; import com.haulmont.cuba.gui.settings.Settings;
import com.haulmont.cuba.gui.xml.layout.ComponentLoader; import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.toolkit.ui.CubaTabSheet; import com.haulmont.cuba.web.toolkit.ui.CubaTabSheet;
import com.vaadin.ui.Layout; import com.vaadin.ui.Layout;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -29,7 +31,7 @@ import java.util.*;
*/ */
public class WebTabSheet public class WebTabSheet
extends extends
WebAbstractComponent<com.vaadin.ui.TabSheet> WebAbstractComponent<CubaTabSheet>
implements implements
TabSheet, Component.Container { TabSheet, Component.Container {
@ -211,20 +213,43 @@ public class WebTabSheet
} }
@Override @Override
public TabSheet.Tab addTab(String name, Component component) { public TabSheet.Tab addTab(String name, Component childComponent) {
final Tab tab = new Tab(name, component); final Tab tab = new Tab(name, childComponent);
this.tabs.put(name, tab); this.tabs.put(name, tab);
final com.vaadin.ui.Component tabComponent = WebComponentsHelper.unwrap(component); final com.vaadin.ui.Component tabComponent = WebComponentsHelper.unwrap(childComponent);
tabComponent.setSizeFull(); tabComponent.setSizeFull();
this.components.put(tabComponent, new ComponentDescriptor(name, component)); this.components.put(tabComponent, new ComponentDescriptor(name, childComponent));
this.component.addTab(tabComponent); com.vaadin.ui.TabSheet.Tab tabControl = this.component.addTab(tabComponent);
if (getDebugId() != null) {
this.component.setTestId(tabControl,
AppUI.getCurrent().getTestIdManager().getTestId(getDebugId() + "." + name));
}
return tab; return tab;
} }
@Override
public void setDebugId(String id) {
super.setDebugId(id);
String debugId = getDebugId();
if (debugId != null) {
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
for (com.vaadin.ui.Component tabComponent : components.keySet()) {
com.vaadin.ui.TabSheet.Tab tab = component.getTab(tabComponent);
ComponentDescriptor componentDescriptor = components.get(tabComponent);
String name = componentDescriptor.name;
component.setTestId(tab, testIdManager.getTestId(debugId + "." + name));
}
}
}
@Override @Override
public TabSheet.Tab addLazyTab(String name, public TabSheet.Tab addLazyTab(String name,
Element descriptor, Element descriptor,
@ -242,7 +267,7 @@ public class WebTabSheet
tabComponent.setSizeFull(); tabComponent.setSizeFull();
this.components.put(tabComponent, new ComponentDescriptor(name, tabContent)); this.components.put(tabComponent, new ComponentDescriptor(name, tabContent));
this.component.addTab(tabComponent); com.vaadin.ui.TabSheet.Tab tabControl = this.component.addTab(tabComponent);
lazyTabs.add(tabComponent); lazyTabs.add(tabComponent);
this.component.addSelectedTabChangeListener(new LazyTabChangeListener(tabContent, descriptor, loader)); this.component.addSelectedTabChangeListener(new LazyTabChangeListener(tabContent, descriptor, loader));
@ -258,6 +283,11 @@ public class WebTabSheet
postInitTaskAdded = true; postInitTaskAdded = true;
} }
if (getDebugId() != null) {
this.component.setTestId(tabControl,
AppUI.getCurrent().getTestIdManager().getTestId(getDebugId() + "." + name));
}
return tab; return tab;
} }

View File

@ -7,6 +7,7 @@ package com.haulmont.cuba.web.log;
import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages; import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.web.App; import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.AppUI;
import com.vaadin.event.Action; import com.vaadin.event.Action;
import com.vaadin.event.ShortcutAction; import com.vaadin.event.ShortcutAction;
import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.MarginInfo;
@ -28,6 +29,11 @@ public class LogWindow extends Window {
public LogWindow() { public LogWindow() {
super(AppBeans.get(Messages.class).getMessage(LogWindow.class, "logWindow.caption")); super(AppBeans.get(Messages.class).getMessage(LogWindow.class, "logWindow.caption"));
if (AppUI.getCurrent().isTestMode()) {
setId(AppUI.getCurrent().getTestIdManager().getTestId("logWindow"));
}
setHeight("80%"); setHeight("80%");
setWidth("80%"); setWidth("80%");
center(); center();

View File

@ -8,6 +8,7 @@ package com.haulmont.cuba.web.sys;
import com.haulmont.cuba.core.global.AppBeans; import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.DevelopmentException; import com.haulmont.cuba.core.global.DevelopmentException;
import com.haulmont.cuba.gui.NoSuchScreenException; import com.haulmont.cuba.gui.NoSuchScreenException;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.config.*; import com.haulmont.cuba.gui.config.*;
import com.haulmont.cuba.security.global.UserSession; import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.web.AppWindow; import com.haulmont.cuba.web.AppWindow;
@ -54,7 +55,7 @@ public class MenuBuilder {
removeExtraSeparators(menuBar); removeExtraSeparators(menuBar);
} }
private void removeExtraSeparators(MenuBar menuBar) { protected void removeExtraSeparators(MenuBar menuBar) {
for (MenuBar.MenuItem item : new ArrayList<>(menuBar.getItems())) { for (MenuBar.MenuItem item : new ArrayList<>(menuBar.getItems())) {
removeExtraSeparators(item); removeExtraSeparators(item);
if (isMenuItemEmpty(item)) if (isMenuItemEmpty(item))
@ -62,7 +63,7 @@ public class MenuBuilder {
} }
} }
private void removeExtraSeparators(MenuBar.MenuItem item) { protected void removeExtraSeparators(MenuBar.MenuItem item) {
if (!item.hasChildren()) if (!item.hasChildren())
return; return;
@ -83,33 +84,33 @@ public class MenuBuilder {
} while (!done); } while (!done);
} }
private void createMenuBarItem(MenuBar menuBar, MenuItem item) { protected void createMenuBarItem(MenuBar menuBar, MenuItem item) {
if (item.isPermitted(session)) { if (item.isPermitted(session)) {
MenuBar.MenuItem menuItem = menuBar.addItem(MenuConfig.getMenuItemCaption(item.getId()), createMenuBarCommand(item)); MenuBar.MenuItem menuItem = menuBar.addItem(MenuConfig.getMenuItemCaption(item.getId()), createMenuBarCommand(item));
assignShortcut(menuItem, item); assignShortcut(menuItem, item);
createSubMenu(menuItem, item, session); createSubMenu(menuItem, item, session);
assignDebugIds(menuItem, item); assignTestId(menuItem, item);
if (isMenuItemEmpty(menuItem)) { if (isMenuItemEmpty(menuItem)) {
menuBar.removeItem(menuItem); menuBar.removeItem(menuItem);
} }
} }
} }
private void createSubMenu(MenuBar.MenuItem vItem, MenuItem item, UserSession session) { protected void createSubMenu(MenuBar.MenuItem vItem, MenuItem item, UserSession session) {
if (item.isPermitted(session) && !item.getChildren().isEmpty()) { if (item.isPermitted(session) && !item.getChildren().isEmpty()) {
for (MenuItem child : item.getChildren()) { for (MenuItem child : item.getChildren()) {
if (child.getChildren().isEmpty()) { if (child.getChildren().isEmpty()) {
if (child.isPermitted(session)) { if (child.isPermitted(session)) {
MenuBar.MenuItem menuItem = (child.isSeparator()) ? vItem.addSeparator() : vItem.addItem(MenuConfig.getMenuItemCaption(child.getId()), createMenuBarCommand(child)); MenuBar.MenuItem menuItem = (child.isSeparator()) ? vItem.addSeparator() : vItem.addItem(MenuConfig.getMenuItemCaption(child.getId()), createMenuBarCommand(child));
assignShortcut(menuItem, child); assignShortcut(menuItem, child);
assignDebugIds(menuItem, child); assignTestId(menuItem, child);
} }
} else { } else {
if (child.isPermitted(session)) { if (child.isPermitted(session)) {
MenuBar.MenuItem menuItem = vItem.addItem(MenuConfig.getMenuItemCaption(child.getId()), null); MenuBar.MenuItem menuItem = vItem.addItem(MenuConfig.getMenuItemCaption(child.getId()), null);
assignShortcut(menuItem, child); assignShortcut(menuItem, child);
createSubMenu(menuItem, child, session); createSubMenu(menuItem, child, session);
assignDebugIds(menuItem, child); assignTestId(menuItem, child);
if (isMenuItemEmpty(menuItem)) { if (isMenuItemEmpty(menuItem)) {
vItem.removeChild(menuItem); vItem.removeChild(menuItem);
} }
@ -119,7 +120,7 @@ public class MenuBuilder {
} }
} }
private MenuBar.Command createMenuBarCommand(final MenuItem item) { protected MenuBar.Command createMenuBarCommand(final MenuItem item) {
if (!item.getChildren().isEmpty()) //check item is menu if (!item.getChildren().isEmpty()) //check item is menu
return null; return null;
@ -143,15 +144,19 @@ public class MenuBuilder {
public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) { public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) {
if (command != null) { if (command != null) {
command.execute(); command.execute();
} else if (item.getParent() != null) { } else {
if (item.getParent() != null) {
throw new DevelopmentException("Invalid screen ID for menu item: " + item.getId(), throw new DevelopmentException("Invalid screen ID for menu item: " + item.getId(),
"Parent menu ID", item.getParent().getId()); "Parent menu ID", item.getParent().getId());
} else {
throw new DevelopmentException("Invalid screen ID for menu item: " + item.getId());
}
} }
} }
}; };
} }
private boolean isMenuItemEmpty(MenuBar.MenuItem menuItem) { protected boolean isMenuItemEmpty(MenuBar.MenuItem menuItem) {
return !menuItem.hasChildren() && menuItem.getCommand() == null; return !menuItem.hasChildren() && menuItem.getCommand() == null;
} }
@ -163,10 +168,14 @@ public class MenuBuilder {
} }
} }
protected void assignDebugIds(MenuBar.MenuItem menuItem, MenuItem conf) { protected void assignTestId(MenuBar.MenuItem menuItem, MenuItem conf) {
if (menuBar.getId() != null && !conf.isSeparator()) { if (menuBar.getId() != null && !conf.isSeparator()) {
// vaadin7 TestIdManager testIdManager = appWindow.getAppUI().getTestIdManager();
// menuBar.setId(menuItem, menuBar.getDebugId() + ":" + conf.getId());
String id = testIdManager.normalize(conf.getId());
testIdManager.reserveId(id);
menuBar.setTestId(menuItem, menuBar.getId() + "_" + id);
} }
} }
} }

View File

@ -4,8 +4,10 @@
*/ */
package com.haulmont.cuba.web.sys; package com.haulmont.cuba.web.sys;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.components.Window; import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.web.App; import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.AppWindow; import com.haulmont.cuba.web.AppWindow;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource; import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.shared.ui.label.ContentMode;
@ -58,6 +60,9 @@ public class WindowBreadCrumbs extends HorizontalLayout {
linksLayout.setStyleName("cuba-breadcrumbs"); linksLayout.setStyleName("cuba-breadcrumbs");
linksLayout.setSizeUndefined(); linksLayout.setSizeUndefined();
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
linksLayout.setId(testIdManager.getTestId("breadCrumbs"));
if (!tabbedMode) { if (!tabbedMode) {
closeBtn = new Button("", new Button.ClickListener() { closeBtn = new Button("", new Button.ClickListener() {
@Override @Override
@ -68,9 +73,7 @@ public class WindowBreadCrumbs extends HorizontalLayout {
}); });
closeBtn.setIcon(new VersionedThemeResource("icons/close.png")); closeBtn.setIcon(new VersionedThemeResource("icons/close.png"));
closeBtn.setStyleName("cuba-closetab-button"); closeBtn.setStyleName("cuba-closetab-button");
// vaadin7 Test ids closeBtn.setId(testIdManager.reserveId("closeBtn"));
// AppUI.getInstance().getWindowManager()
// .setDebugId(closeBtn, "closeBtn");
} }
HorizontalLayout enclosingLayout = new HorizontalLayout(); HorizontalLayout enclosingLayout = new HorizontalLayout();

View File

@ -20,6 +20,7 @@ import java.util.Map;
public class CubaMenuBar extends com.vaadin.ui.MenuBar { public class CubaMenuBar extends com.vaadin.ui.MenuBar {
protected final Map<MenuItem, String> shortcuts = new HashMap<>(); protected final Map<MenuItem, String> shortcuts = new HashMap<>();
protected final Map<MenuItem, String> testIds = new HashMap<>();
@Override @Override
protected CubaMenuBarState getState() { protected CubaMenuBarState getState() {
@ -56,6 +57,10 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
shortcuts.remove(item); shortcuts.remove(item);
} }
public void setTestId(MenuItem item, String id) {
testIds.put(item, id);
}
@Override @Override
protected void paintAdditionalItemParams(PaintTarget target, MenuItem item) throws PaintException { protected void paintAdditionalItemParams(PaintTarget target, MenuItem item) throws PaintException {
if (shortcuts.containsKey(item)) { if (shortcuts.containsKey(item)) {
@ -64,5 +69,8 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
target.addAttribute("shortcut", shortcut); target.addAttribute("shortcut", shortcut);
} }
} }
if (testIds.containsKey(item)) {
target.addAttribute("testId", testIds.get(item));
}
} }
} }

View File

@ -10,6 +10,8 @@ import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetServerRpc;
import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetState; import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetState;
import com.vaadin.event.Action; import com.vaadin.event.Action;
import com.vaadin.server.KeyMapper; import com.vaadin.server.KeyMapper;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.ui.Component; import com.vaadin.ui.Component;
import java.util.*; import java.util.*;
@ -28,6 +30,8 @@ public class CubaTabSheet extends com.vaadin.ui.TabSheet implements Action.Conta
protected KeyMapper<Action> actionMapper = null; protected KeyMapper<Action> actionMapper = null;
protected Map<Tab, String> testIds = new HashMap<>();
protected CubaTabSheetServerRpc rpc = new CubaTabSheetServerRpc() { protected CubaTabSheetServerRpc rpc = new CubaTabSheetServerRpc() {
@Override @Override
public void onTabContextMenu(int tabIndex) { public void onTabContextMenu(int tabIndex) {
@ -143,6 +147,19 @@ public class CubaTabSheet extends com.vaadin.ui.TabSheet implements Action.Conta
} }
} }
public void setTestId(Tab tab, String testId) {
testIds.put(tab, testId);
}
@Override
protected void paintAdditionalTabAttributes(PaintTarget target, Tab tab) throws PaintException {
super.paintAdditionalTabAttributes(target, tab);
if (testIds.containsKey(tab)) {
target.addAttribute("testId", testIds.get(tab));
}
}
@Override @Override
public void addActionHandler(Action.Handler actionHandler) { public void addActionHandler(Action.Handler actionHandler) {
actionHandlers.add(actionHandler); actionHandlers.add(actionHandler);