IDEMPIERE-92 Chagnes to enable selenium/sahi recording

* Implement unique repeatable component IDs
* Implementa safe validation - add suffix for non-uniques
http://jira.idempiere.com/browse/IDEMPIERE-92
This commit is contained in:
Carlos Ruiz 2012-02-01 21:22:07 -05:00
parent 1c84183b2c
commit 7aceaecff6
9 changed files with 57 additions and 26 deletions

View File

@ -26,6 +26,10 @@ public class AdempiereIdGenerator implements IdGenerator {
private static final String DEFAULT_ZK_COMP_PREFIX = "zk_comp_"; private static final String DEFAULT_ZK_COMP_PREFIX = "zk_comp_";
private static final String DESKTOP_ID_ATTRIBUTE = "org.adempiere.comp.id"; private static final String DESKTOP_ID_ATTRIBUTE = "org.adempiere.comp.id";
/* use this to add a component prefix to identify zk component
* if the prefix starts with unq then it will be used as is - if it doesn't then a sequence suffix will be added to guarantee uniqueness
*/
public static final String ZK_COMPONENT_PREFIX_ATTRIBUTE = "zk_component_prefix"; public static final String ZK_COMPONENT_PREFIX_ATTRIBUTE = "zk_component_prefix";
@Override @Override
@ -43,6 +47,15 @@ public class AdempiereIdGenerator implements IdGenerator {
matcher.appendTail(sb); matcher.appendTail(sb);
prefix = sb.toString(); prefix = sb.toString();
} }
if (prefix.startsWith("unq")) { // prefix already guaranteed unique
if (desktop.getComponentByUuidIfAny(prefix) == null) { // but don't trust and look to avoid dups
return prefix;
} else {
prefix = "not" + prefix; // set notunq as the prefix to let dev know something is wrong
}
}
/* add sequence suffix to guarantee uniqueness */
int i = 0; int i = 0;
try { try {
String number = null; String number = null;

View File

@ -74,7 +74,7 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
ADTabLabel tabLabel = (ADTabLabel) items[i]; ADTabLabel tabLabel = (ADTabLabel) items[i];
Button button = new Button(); Button button = new Button();
button.setDynamicProperty("Title", tabLabel.description); button.setDynamicProperty("Title", tabLabel.description);
button.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "ADButtonTab" + i); button.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unqADButtonTab_" + tabLabel.windowNo + "_" + i);
Text text = new Text(tabLabel.label); Text text = new Text(tabLabel.label);
text.setAttribute("ad_tab_id", tabLabel.AD_Tab_ID); text.setAttribute("ad_tab_id", tabLabel.AD_Tab_ID);
button.appendChild(text); button.appendChild(text);

View File

@ -51,10 +51,10 @@ import org.zkoss.zul.Space;
*/ */
public class CWindowToolbar extends FToolbar implements EventListener public class CWindowToolbar extends FToolbar implements EventListener
{ {
/** /**
* *
*/ */
private static final long serialVersionUID = -8259762910508209764L; private static final long serialVersionUID = -762537218475834634L;
private static final String TOOLBAR_BUTTON_STYLE = "background-color: transparent; display:inline-block; margin-left: 1px; margin-right: 1px; width: 26px; height: 24px;"; private static final String TOOLBAR_BUTTON_STYLE = "background-color: transparent; display:inline-block; margin-left: 1px; margin-right: 1px; width: 26px; height: 24px;";
@ -124,7 +124,13 @@ public class CWindowToolbar extends FToolbar implements EventListener
init(); init();
} }
private void init() public CWindowToolbar(boolean embedded, int windowNo) {
this.embedded = embedded;
setWindowNo(windowNo);
init();
}
private void init()
{ {
LayoutUtils.addSclass("adwindow-toolbar", this); LayoutUtils.addSclass("adwindow-toolbar", this);
@ -203,8 +209,11 @@ public class CWindowToolbar extends FToolbar implements EventListener
private ToolBarButton createButton(String name, String image, String tooltip) private ToolBarButton createButton(String name, String image, String tooltip)
{ {
ToolBarButton btn = new ToolBarButton(""); ToolBarButton btn = new ToolBarButton("");
btn.setName("btn"+name); btn.setName("Btn"+name);
btn.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, btn.getName()); if (windowNo > 0)
btn.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + btn.getName() + "_" + windowNo + (embedded ? "E" : ""));
else
btn.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, btn.getName());
btn.setImage("/images/"+image + (embedded ? "16.png" : "24.png")); btn.setImage("/images/"+image + (embedded ? "16.png" : "24.png"));
btn.setTooltiptext(Msg.getMsg(Env.getCtx(),tooltip)); btn.setTooltiptext(Msg.getMsg(Env.getCtx(),tooltip));
if (embedded) if (embedded)

View File

@ -225,7 +225,7 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt, Renderer
component = createReadonlyCheckbox(value); component = createReadonlyCheckbox(value);
} else if (gridField.getDisplayType() == DisplayType.Button) { } else if (gridField.getDisplayType() == DisplayType.Button) {
GridRowCtx gridRowCtx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex); GridRowCtx gridRowCtx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex);
WButtonEditor editor = new WButtonEditor(gridField); WButtonEditor editor = new WButtonEditor(gridField, rowIndex);
editor.setValue(gridTab.getValue(rowIndex, gridField.getColumnName())); editor.setValue(gridTab.getValue(rowIndex, gridField.getColumnName()));
editor.setReadWrite(gridField.isEditable(gridRowCtx, true)); editor.setReadWrite(gridField.isEditable(gridRowCtx, true));
editor.getComponent().setAttribute("grid.row.index", rowIndex); editor.getComponent().setAttribute("grid.row.index", rowIndex);

View File

@ -74,14 +74,18 @@ public class WButtonEditor extends WEditor
public WButtonEditor(GridField gridField) public WButtonEditor(GridField gridField)
{ {
super(new Button(), gridField); this(gridField, -1);
}
public WButtonEditor(GridField gridField, int rowIndex) {
super(new Button(), gridField, rowIndex);
m_text = gridField.getHeader(); m_text = gridField.getHeader();
AD_Process_ID = gridField.getAD_Process_ID(); AD_Process_ID = gridField.getAD_Process_ID();
gridfield = gridField; gridfield = gridField;
init(); init();
} }
/** /**
* Get AD_Process_ID * Get AD_Process_ID
* @return AD_Process_ID or 0 * @return AD_Process_ID or 0
*/ */

View File

@ -82,12 +82,16 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
protected WEditorPopupMenu popupMenu; protected WEditorPopupMenu popupMenu;
public WEditor(Component comp, GridField gridField) {
this(comp, gridField, -1);
}
/** /**
* *
* @param comp * @param comp
* @param gridField * @param gridField
*/ */
public WEditor(Component comp, GridField gridField) public WEditor(Component comp, GridField gridField, int rowIndex)
{ {
if (comp == null) if (comp == null)
{ {
@ -100,12 +104,13 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
} }
this.setComponent(comp); this.setComponent(comp);
String gridTabName = gridField.getGridTab() != null String gridTabName = gridField.getGridTab() != null ? gridField.getGridTab().getTabNo() + "_" + gridField.getGridTab().getTableName() : "";
? "_" + gridField.getGridTab().getName() : ""; comp.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE,
if (gridField.getGridTab() != null) "unqField_"
{ + gridField.getWindowNo()
comp.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "Field_" + gridField.getColumnName() + gridTabName); + "_" + gridTabName
} + "_" + gridField.getColumnName()
+ (rowIndex >= 0 ? "_" + rowIndex : ""));
this.gridField = gridField; this.gridField = gridField;
this.setMandatory(gridField.isMandatory(false)); this.setMandatory(gridField.isMandatory(false));
this.readOnly = gridField.isReadOnly(); this.readOnly = gridField.isReadOnly();

View File

@ -237,7 +237,7 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
private void initComponents() private void initComponents()
{ {
/** Initalise toolbar */ /** Initalise toolbar */
toolbar = new CWindowToolbar(isEmbedded()); toolbar = new CWindowToolbar(isEmbedded(), getWindowNo());
toolbar.addListener(this); toolbar.addListener(this);
statusBar = new StatusBarPanel(isEmbedded()); statusBar = new StatusBarPanel(isEmbedded());

View File

@ -263,7 +263,7 @@ public class LoginPanel extends Window implements EventListener
txtUserId = new Textbox(); txtUserId = new Textbox();
txtUserId.setId("txtUserId"); txtUserId.setId("txtUserId");
txtUserId.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, txtUserId.getId()); txtUserId.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + txtUserId.getId());
txtUserId.setCols(25); txtUserId.setCols(25);
txtUserId.setMaxlength(40); txtUserId.setMaxlength(40);
txtUserId.setWidth("220px"); txtUserId.setWidth("220px");
@ -272,7 +272,7 @@ public class LoginPanel extends Window implements EventListener
txtPassword = new Textbox(); txtPassword = new Textbox();
txtPassword.setId("txtPassword"); txtPassword.setId("txtPassword");
txtPassword.setType("password"); txtPassword.setType("password");
txtPassword.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, txtPassword.getId()); txtPassword.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + txtPassword.getId());
txtPassword.setCols(25); txtPassword.setCols(25);
// txtPassword.setMaxlength(40); // txtPassword.setMaxlength(40);
@ -282,7 +282,7 @@ public class LoginPanel extends Window implements EventListener
lstLanguage.setAutocomplete(true); lstLanguage.setAutocomplete(true);
lstLanguage.setAutodrop(true); lstLanguage.setAutodrop(true);
lstLanguage.setId("lstLanguage"); lstLanguage.setId("lstLanguage");
lstLanguage.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, lstLanguage.getId()); lstLanguage.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + lstLanguage.getId());
lstLanguage.addEventListener(Events.ON_SELECT, this); lstLanguage.addEventListener(Events.ON_SELECT, this);
lstLanguage.setWidth("220px"); lstLanguage.setWidth("220px");

View File

@ -243,7 +243,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstRole.setAutocomplete(true); lstRole.setAutocomplete(true);
lstRole.setAutodrop(true); lstRole.setAutodrop(true);
lstRole.setId("lstRole"); lstRole.setId("lstRole");
lstRole.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, lstRole.getId()); lstRole.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + lstRole.getId());
lstRole.addEventListener(Events.ON_SELECT, this); lstRole.addEventListener(Events.ON_SELECT, this);
lstRole.setWidth("220px"); lstRole.setWidth("220px");
@ -252,7 +252,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstClient.setAutocomplete(true); lstClient.setAutocomplete(true);
lstClient.setAutodrop(true); lstClient.setAutodrop(true);
lstClient.setId("lstClient"); lstClient.setId("lstClient");
lstClient.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, lstClient.getId()); lstClient.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + lstClient.getId());
lstClient.addEventListener(Events.ON_SELECT, this); lstClient.addEventListener(Events.ON_SELECT, this);
lstClient.setWidth("220px"); lstClient.setWidth("220px");
@ -261,7 +261,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstOrganisation.setAutocomplete(true); lstOrganisation.setAutocomplete(true);
lstOrganisation.setAutodrop(true); lstOrganisation.setAutodrop(true);
lstOrganisation.setId("lstOrganisation"); lstOrganisation.setId("lstOrganisation");
lstOrganisation.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, lstOrganisation.getId()); lstOrganisation.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + lstOrganisation.getId());
lstOrganisation.addEventListener(Events.ON_SELECT, this); lstOrganisation.addEventListener(Events.ON_SELECT, this);
lstOrganisation.setWidth("220px"); lstOrganisation.setWidth("220px");
@ -270,7 +270,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstWarehouse.setAutocomplete(true); lstWarehouse.setAutocomplete(true);
lstWarehouse.setAutodrop(true); lstWarehouse.setAutodrop(true);
lstWarehouse.setId("lstWarehouse"); lstWarehouse.setId("lstWarehouse");
lstWarehouse.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, lstWarehouse.getId()); lstWarehouse.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, "unq" + lstWarehouse.getId());
lstWarehouse.addEventListener(Events.ON_SELECT, this); lstWarehouse.addEventListener(Events.ON_SELECT, this);
lstWarehouse.setWidth("220px"); lstWarehouse.setWidth("220px");