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

View File

@ -52,7 +52,16 @@ public class CubaMenuBarConnector extends MenuBarConnector {
}
@Override
public boolean isUseMoreMenuItem() {
protected boolean isUseMoreMenuItem() {
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")) {
itemHTML.append("<span>---</span><span>---</span>");
} else {
itemHTML.append("<span class=\"")
.append(getStylePrimaryName())
.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.ContextMenuEvent;
import com.google.gwt.event.dom.client.FocusEvent;
import com.vaadin.client.UIDL;
import com.vaadin.client.ui.VTabsheet;
/**
@ -41,4 +42,13 @@ public class CubaTabSheetWidget extends VTabsheet {
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 testModeRequest = false;
protected String webResourceTimestamp = "null";
protected String clientAddress;
@ -305,10 +303,6 @@ public abstract class App {
themeInitialized = false;
}
public boolean isTestModeRequest() {
return testModeRequest;
}
public String getWebResourceTimestamp() {
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.Configuration;
import com.haulmont.cuba.core.global.GlobalConfig;
import com.haulmont.cuba.core.global.MessageTools;
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.CubaSWFObjectIntegration;
import com.vaadin.annotations.PreserveOnRefresh;
@ -41,6 +43,10 @@ public class AppUI extends UI implements ErrorHandler {
protected boolean applicationInitRequired = false;
protected TestIdManager testIdManager = new TestIdManager();
protected boolean testMode = false;
public AppUI() {
log.trace("Creating UI " + this);
if (!App.isBound()) {
@ -66,11 +72,12 @@ public class AppUI extends UI implements ErrorHandler {
});
applicationInitRequired = true;
} else {
app = App.getInstance();
}
testMode = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class).getTestMode();
// do not grab focus
setTabIndex(-1);
@ -156,6 +163,14 @@ public class AppUI extends UI implements ErrorHandler {
}
}
public TestIdManager getTestIdManager() {
return testIdManager;
}
public boolean isTestMode() {
return testMode;
}
@Override
public void error(com.vaadin.server.ErrorEvent event) {
try {

View File

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

View File

@ -64,7 +64,12 @@ public class DefaultApp extends App implements ConnectionListener {
} else {
cleanupBackgroundTasks();
closeAllWindows();
for (AppUI ui : getAppUIs()) {
if (ui.isTestMode()) {
ui.getTestIdManager().reset();
}
UIView window = createLoginWindow(ui);
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.DomainAliasesResolver;
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.ui.CubaCheckBox;
import com.vaadin.data.Property;
@ -138,16 +139,18 @@ public class LoginWindow extends UIView implements Action.Handler {
setBaseStyle("cuba-login");
initUI();
// vaadin7 commented
// if (globalConfig.getTestMode()) {
// WebWindowManager windowManager = app.getWindowManager();
// windowManager.setDebugId(loginField, "loginField");
// windowManager.setDebugId(passwordField, "pwdField");
// windowManager.setDebugId(localesSelect, "localesField");
// if (okButton != null) {
// windowManager.setDebugId(okButton, "loginSubmitButton");
// }
// }
if (ui.isTestMode()) {
TestIdManager testIdManager = ui.getTestIdManager();
loginField.setId(testIdManager.reserveId("loginField"));
passwordField.setId(testIdManager.reserveId("pwdField"));
localesSelect.setId(testIdManager.reserveId("localesField"));
if (okButton != null) {
okButton.setId(testIdManager.reserveId("loginSubmitButton"));
}
}
addActionHandler(this);
}

View File

@ -51,6 +51,7 @@ public class WebWindowManager extends WindowManager {
private static Log log = LogFactory.getLog(WebWindowManager.class);
protected App app;
protected AppUI ui;
protected AppWindow appWindow;
protected final WebConfig webConfig;
@ -62,12 +63,11 @@ public class WebWindowManager extends WindowManager {
protected final Map<Window, Integer> windows = new HashMap<>();
protected final Map<ComponentContainer, WindowBreadCrumbs> fakeTabs = new HashMap<>();
protected Map<String, Integer> debugIds = new HashMap<>();
protected boolean disableSavingScreenHistory;
protected ScreenHistorySupport screenHistorySupport;
public WebWindowManager(final App app, AppWindow appWindow) {
this.ui = app.getAppUI();
this.app = app;
this.appWindow = appWindow;
@ -343,6 +343,12 @@ public class WebWindowManager extends WindowManager {
newTab = tabSheet.getTab(layout);
} else {
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]);
}
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,
boolean forciblyDialog) {
final com.vaadin.ui.Window win = createDialogWindow(window);
win.setId(window.getId());
setDebugId(win, window.getId());
setDebugId(win, "dialog_" + window.getId());
Layout layout = (Layout) WebComponentsHelper.getComposition(window);
@ -554,7 +558,7 @@ public class WebWindowManager extends WindowManager {
}
win.setModal(true);
appWindow.getAppUI().addWindow(win);
ui.addWindow(win);
win.center();
return win;
@ -568,7 +572,7 @@ public class WebWindowManager extends WindowManager {
protected com.vaadin.ui.Window createDialogWindow(Window window) {
com.vaadin.ui.Window vWindow = new com.vaadin.ui.Window(window.getCaption());
vWindow.setErrorHandler(app.getAppUI());
vWindow.setErrorHandler(ui);
return vWindow;
}
@ -676,7 +680,7 @@ public class WebWindowManager extends WindowManager {
case DIALOG: {
final com.vaadin.ui.Window win = (com.vaadin.ui.Window) openMode.getData();
removeCloseListeners(win);
appWindow.getAppUI().removeWindow(win);
ui.removeWindow(win);
fireListeners(window, tabs.size() != 0);
break;
}
@ -804,7 +808,8 @@ public class WebWindowManager extends WindowManager {
public void showMessageDialog(String title, String message, IFrame.MessageType messageType) {
final com.vaadin.ui.Window window = new com.vaadin.ui.Window(title);
window.setId("cuba-message-dialog");
setDebugId(window, "cuba-message-dialog");
setDebugId(window, "cubaMessageDialog");
window.addAction(new ShortcutListener("Esc", ShortcutAction.KeyCode.ESCAPE, null) {
@Override
@ -823,7 +828,7 @@ public class WebWindowManager extends WindowManager {
window.addCloseListener(new com.vaadin.ui.Window.CloseListener() {
@Override
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.setModal(true);
appWindow.getAppUI().addWindow(window);
ui.addWindow(window);
window.center();
window.focus();
}
@ -864,7 +869,7 @@ public class WebWindowManager extends WindowManager {
window.addCloseListener(new com.vaadin.ui.Window.CloseListener() {
@Override
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
public void buttonClick(Button.ClickEvent event) {
action.actionPerform(null);
app.getAppUI().removeWindow(window);
ui.removeWindow(window);
}
});
@ -940,7 +945,7 @@ public class WebWindowManager extends WindowManager {
layout.setExpandRatio(messageLab, 1);
layout.setComponentAlignment(actionsBar, com.vaadin.ui.Alignment.BOTTOM_RIGHT);
appWindow.getAppUI().addWindow(window);
ui.addWindow(window);
window.center();
}
@ -961,29 +966,30 @@ public class WebWindowManager extends WindowManager {
if (target == null)
target = "_blank";
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) {
appWindow.getAppUI().getPage().open(url, target, tryToOpenAsPopup);
ui.getPage().open(url, target, tryToOpenAsPopup);
} else {
appWindow.getAppUI().getPage().open(url, target, false);
ui.getPage().open(url, target, false);
}
}
@Override
protected void initDebugIds(final Window window) {
if (app.isTestModeRequest()) {
if (ui.isTestMode()) {
com.haulmont.cuba.gui.ComponentsHelper.walkComponents(window, new ComponentVisitor() {
@Override
public void visit(com.haulmont.cuba.gui.components.Component component, String name) {
final String id = window.getId() + "." + name;
if (webConfig.getAllowIdSuffix()) {
component.setDebugId(generateDebugId(id));
} else {
if (component.getDebugId() == null) {
final String id;
String fullFrameId = ComponentsHelper.getFullFrameId(window);
if (component.getId() != null) {
component.setDebugId(id);
id = fullFrameId + "_" + component.getId();
} 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) {
if (app.isTestModeRequest()) {
if (webConfig.getAllowIdSuffix()) {
component.setId(generateDebugId(id));
} else {
component.setId(id);
}
if (ui.isTestMode()) {
component.setId(ui.getTestIdManager().getTestId(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.config.WindowConfig;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.WebConfig;
import com.vaadin.shared.ui.MarginInfo;
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) {
super();
if (AppUI.getCurrent().isTestMode()) {
setId(AppUI.getCurrent().getTestIdManager().getTestId("exceptionDialog"));
}
setCaption(caption != null ? caption : messages.getMessage(getClass(), "exceptionDialog.caption"));
setWidth(600, Unit.PIXELS);
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.global.AppBeans;
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.gui.*;
import com.haulmont.cuba.gui.components.*;
@ -620,6 +619,10 @@ public class WebWindow implements Window, Component.Wrapper,
@Override
public void setId(String id) {
this.id = id;
if (AppUI.getCurrent().isTestMode() && StringUtils.isEmpty(debugId)) {
setDebugId(id);
}
}
@Override
@ -630,6 +633,10 @@ public class WebWindow implements Window, Component.Wrapper,
@Override
public void setDebugId(String debugId) {
this.debugId = debugId;
if (debugId != null) {
component.setId(AppUI.getCurrent().getTestIdManager().getTestId("window_" + debugId));
}
}
@Override
@ -1179,12 +1186,10 @@ public class WebWindow implements Window, Component.Wrapper,
public void setId(String id) {
super.setId(id);
Configuration configuration = AppBeans.get(Configuration.NAME);
if (configuration.getConfig(GlobalConfig.class).getTestMode()) {
WebWindowManager windowManager = getWindowManager();
windowManager.setDebugId(selectButton, id + ".selectButton");
windowManager.setDebugId(cancelButton, id + ".cancelButton");
if (debugId != null) {
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
selectButton.setId(testIdManager.getTestId(debugId + "_selectButton"));
cancelButton.setId(testIdManager.getTestId(debugId + "_cancelButton"));
}
}
}

View File

@ -4,10 +4,13 @@
*/
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.IFrame;
import com.haulmont.cuba.web.AppUI;
import com.vaadin.server.Sizeable;
import com.vaadin.ui.Layout;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
import java.util.Arrays;
@ -45,6 +48,17 @@ public class WebAbstractComponent<T extends com.vaadin.ui.Component>
public void setFrame(IFrame frame) {
this.frame = frame;
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

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.Configuration;
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.components.Action;
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.toolkit.VersionedThemeResource;
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
@ -131,4 +146,23 @@ public class WebButton
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.MessageTools;
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.Field;
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.ValueListener;
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.CubaDateFieldWrapper;
import com.haulmont.cuba.web.toolkit.ui.CubaMaskedTextField;
@ -192,6 +194,17 @@ public class WebDateField extends WebAbstractField<CubaDateFieldWrapper> impleme
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) {
boolean isEditable = 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.Datasource;
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.CubaFieldGroup;
import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroupLayout;
@ -80,11 +81,12 @@ public class WebFieldGroup
@Override
public void setDebugId(String id) {
super.setDebugId(id);
final List<FieldConfig> fieldConfs = getFields();
for (final FieldConfig fieldConf : fieldConfs) {
com.vaadin.ui.Field field = component.getField(fieldConf.getId());
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);
}
if (StringUtils.isEmpty(fieldComponent.getId())) {
fieldComponent.setId(fieldConf.getId());
}
assignTypicalAttributes(fieldComponent);
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.global.*;
import com.haulmont.cuba.gui.ComponentsHelper;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.WindowParams;
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.User;
import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.WebWindowManager;
import com.haulmont.cuba.web.app.folders.AppFolderEditWindow;
import com.haulmont.cuba.web.app.folders.FolderEditWindow;
@ -178,7 +180,6 @@ public class WebFilter extends WebAbstractComponent<CubaVerticalActionsLayout> i
select.addValueChangeListener(new SelectListener());
select.setTextInputAllowed(false);
App.getInstance().getWindowManager().setDebugId(select, "genericFilterSelect");
topLayout.addComponent(select);
applyBtn = WebComponentsHelper.createButton("icons/search.png");
@ -189,7 +190,6 @@ public class WebFilter extends WebAbstractComponent<CubaVerticalActionsLayout> i
apply(false);
}
});
App.getInstance().getWindowManager().setDebugId(applyBtn, "genericFilterApplyBtn");
topLayout.addComponent(applyBtn);
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
public CollectionDatasource getDatasource() {
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.Metadata;
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.CaptionMode;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.PickerField;
import com.haulmont.cuba.gui.data.Datasource;
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.toolkit.VersionedThemeResource;
import com.haulmont.cuba.web.toolkit.ui.CubaPickerField;
@ -239,6 +242,29 @@ public class WebPickerField
if (action instanceof StandardAction) {
((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

View File

@ -4,9 +4,11 @@
*/
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.Component;
import com.haulmont.cuba.gui.components.KeyCombination;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.BaseTheme;
@ -144,6 +146,28 @@ public class WebPopupButton
((com.vaadin.ui.Layout) vPopupComponent).addComponent(vButton);
component.markAsDirty();
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;
}
private Action getAction() {
return action;
}
@Override
public void actionPerform(Component component) {
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.ComponentVisitor;
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.IFrame;
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.settings.Settings;
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.toolkit.ui.CubaTabSheet;
import com.vaadin.ui.Layout;
import org.apache.commons.lang.StringUtils;
@ -29,7 +31,7 @@ import java.util.*;
*/
public class WebTabSheet
extends
WebAbstractComponent<com.vaadin.ui.TabSheet>
WebAbstractComponent<CubaTabSheet>
implements
TabSheet, Component.Container {
@ -211,20 +213,43 @@ public class WebTabSheet
}
@Override
public TabSheet.Tab addTab(String name, Component component) {
final Tab tab = new Tab(name, component);
public TabSheet.Tab addTab(String name, Component childComponent) {
final Tab tab = new Tab(name, childComponent);
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();
this.components.put(tabComponent, new ComponentDescriptor(name, component));
this.component.addTab(tabComponent);
this.components.put(tabComponent, new ComponentDescriptor(name, childComponent));
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;
}
@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
public TabSheet.Tab addLazyTab(String name,
Element descriptor,
@ -242,7 +267,7 @@ public class WebTabSheet
tabComponent.setSizeFull();
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);
this.component.addSelectedTabChangeListener(new LazyTabChangeListener(tabContent, descriptor, loader));
@ -258,6 +283,11 @@ public class WebTabSheet
postInitTaskAdded = true;
}
if (getDebugId() != null) {
this.component.setTestId(tabControl,
AppUI.getCurrent().getTestIdManager().getTestId(getDebugId() + "." + name));
}
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.Messages;
import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.AppUI;
import com.vaadin.event.Action;
import com.vaadin.event.ShortcutAction;
import com.vaadin.shared.ui.MarginInfo;
@ -28,6 +29,11 @@ public class LogWindow extends Window {
public LogWindow() {
super(AppBeans.get(Messages.class).getMessage(LogWindow.class, "logWindow.caption"));
if (AppUI.getCurrent().isTestMode()) {
setId(AppUI.getCurrent().getTestIdManager().getTestId("logWindow"));
}
setHeight("80%");
setWidth("80%");
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.DevelopmentException;
import com.haulmont.cuba.gui.NoSuchScreenException;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.config.*;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.web.AppWindow;
@ -54,7 +55,7 @@ public class MenuBuilder {
removeExtraSeparators(menuBar);
}
private void removeExtraSeparators(MenuBar menuBar) {
protected void removeExtraSeparators(MenuBar menuBar) {
for (MenuBar.MenuItem item : new ArrayList<>(menuBar.getItems())) {
removeExtraSeparators(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())
return;
@ -83,33 +84,33 @@ public class MenuBuilder {
} while (!done);
}
private void createMenuBarItem(MenuBar menuBar, MenuItem item) {
protected void createMenuBarItem(MenuBar menuBar, MenuItem item) {
if (item.isPermitted(session)) {
MenuBar.MenuItem menuItem = menuBar.addItem(MenuConfig.getMenuItemCaption(item.getId()), createMenuBarCommand(item));
assignShortcut(menuItem, item);
createSubMenu(menuItem, item, session);
assignDebugIds(menuItem, item);
assignTestId(menuItem, item);
if (isMenuItemEmpty(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()) {
for (MenuItem child : item.getChildren()) {
if (child.getChildren().isEmpty()) {
if (child.isPermitted(session)) {
MenuBar.MenuItem menuItem = (child.isSeparator()) ? vItem.addSeparator() : vItem.addItem(MenuConfig.getMenuItemCaption(child.getId()), createMenuBarCommand(child));
assignShortcut(menuItem, child);
assignDebugIds(menuItem, child);
assignTestId(menuItem, child);
}
} else {
if (child.isPermitted(session)) {
MenuBar.MenuItem menuItem = vItem.addItem(MenuConfig.getMenuItemCaption(child.getId()), null);
assignShortcut(menuItem, child);
createSubMenu(menuItem, child, session);
assignDebugIds(menuItem, child);
assignTestId(menuItem, child);
if (isMenuItemEmpty(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
return null;
@ -143,15 +144,19 @@ public class MenuBuilder {
public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) {
if (command != null) {
command.execute();
} else if (item.getParent() != null) {
throw new DevelopmentException("Invalid screen ID for menu item: " + item.getId(),
"Parent menu ID", item.getParent().getId());
} else {
if (item.getParent() != null) {
throw new DevelopmentException("Invalid screen ID for menu item: " + item.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;
}
@ -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()) {
// vaadin7
// menuBar.setId(menuItem, menuBar.getDebugId() + ":" + conf.getId());
TestIdManager testIdManager = appWindow.getAppUI().getTestIdManager();
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;
import com.haulmont.cuba.gui.TestIdManager;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.web.App;
import com.haulmont.cuba.web.AppUI;
import com.haulmont.cuba.web.AppWindow;
import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
import com.vaadin.shared.ui.label.ContentMode;
@ -58,6 +60,9 @@ public class WindowBreadCrumbs extends HorizontalLayout {
linksLayout.setStyleName("cuba-breadcrumbs");
linksLayout.setSizeUndefined();
TestIdManager testIdManager = AppUI.getCurrent().getTestIdManager();
linksLayout.setId(testIdManager.getTestId("breadCrumbs"));
if (!tabbedMode) {
closeBtn = new Button("", new Button.ClickListener() {
@Override
@ -68,9 +73,7 @@ public class WindowBreadCrumbs extends HorizontalLayout {
});
closeBtn.setIcon(new VersionedThemeResource("icons/close.png"));
closeBtn.setStyleName("cuba-closetab-button");
// vaadin7 Test ids
// AppUI.getInstance().getWindowManager()
// .setDebugId(closeBtn, "closeBtn");
closeBtn.setId(testIdManager.reserveId("closeBtn"));
}
HorizontalLayout enclosingLayout = new HorizontalLayout();

View File

@ -20,6 +20,7 @@ import java.util.Map;
public class CubaMenuBar extends com.vaadin.ui.MenuBar {
protected final Map<MenuItem, String> shortcuts = new HashMap<>();
protected final Map<MenuItem, String> testIds = new HashMap<>();
@Override
protected CubaMenuBarState getState() {
@ -56,6 +57,10 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
shortcuts.remove(item);
}
public void setTestId(MenuItem item, String id) {
testIds.put(item, id);
}
@Override
protected void paintAdditionalItemParams(PaintTarget target, MenuItem item) throws PaintException {
if (shortcuts.containsKey(item)) {
@ -64,5 +69,8 @@ public class CubaMenuBar extends com.vaadin.ui.MenuBar {
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.vaadin.event.Action;
import com.vaadin.server.KeyMapper;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.ui.Component;
import java.util.*;
@ -28,6 +30,8 @@ public class CubaTabSheet extends com.vaadin.ui.TabSheet implements Action.Conta
protected KeyMapper<Action> actionMapper = null;
protected Map<Tab, String> testIds = new HashMap<>();
protected CubaTabSheetServerRpc rpc = new CubaTabSheetServerRpc() {
@Override
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
public void addActionHandler(Action.Handler actionHandler) {
actionHandlers.add(actionHandler);