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 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";
@Override
@ -43,6 +47,15 @@ public class AdempiereIdGenerator implements IdGenerator {
matcher.appendTail(sb);
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;
try {
String number = null;

View File

@ -74,7 +74,7 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
ADTabLabel tabLabel = (ADTabLabel) items[i];
Button button = new Button();
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.setAttribute("ad_tab_id", tabLabel.AD_Tab_ID);
button.appendChild(text);

View File

@ -51,10 +51,10 @@ import org.zkoss.zul.Space;
*/
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;";
@ -124,7 +124,13 @@ public class CWindowToolbar extends FToolbar implements EventListener
init();
}
private void init()
public CWindowToolbar(boolean embedded, int windowNo) {
this.embedded = embedded;
setWindowNo(windowNo);
init();
}
private void init()
{
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)
{
ToolBarButton btn = new ToolBarButton("");
btn.setName("btn"+name);
btn.setAttribute(AdempiereIdGenerator.ZK_COMPONENT_PREFIX_ATTRIBUTE, btn.getName());
btn.setName("Btn"+name);
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.setTooltiptext(Msg.getMsg(Env.getCtx(),tooltip));
if (embedded)

View File

@ -225,7 +225,7 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt, Renderer
component = createReadonlyCheckbox(value);
} else if (gridField.getDisplayType() == DisplayType.Button) {
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.setReadWrite(gridField.isEditable(gridRowCtx, true));
editor.getComponent().setAttribute("grid.row.index", rowIndex);

View File

@ -74,14 +74,18 @@ public class WButtonEditor extends WEditor
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();
AD_Process_ID = gridField.getAD_Process_ID();
gridfield = gridField;
init();
}
}
/**
/**
* Get AD_Process_ID
* @return AD_Process_ID or 0
*/

View File

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

View File

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

View File

@ -263,7 +263,7 @@ public class LoginPanel extends Window implements EventListener
txtUserId = new Textbox();
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.setMaxlength(40);
txtUserId.setWidth("220px");
@ -272,7 +272,7 @@ public class LoginPanel extends Window implements EventListener
txtPassword = new Textbox();
txtPassword.setId("txtPassword");
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.setMaxlength(40);
@ -282,7 +282,7 @@ public class LoginPanel extends Window implements EventListener
lstLanguage.setAutocomplete(true);
lstLanguage.setAutodrop(true);
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.setWidth("220px");

View File

@ -243,7 +243,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstRole.setAutocomplete(true);
lstRole.setAutodrop(true);
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.setWidth("220px");
@ -252,7 +252,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstClient.setAutocomplete(true);
lstClient.setAutodrop(true);
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.setWidth("220px");
@ -261,7 +261,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstOrganisation.setAutocomplete(true);
lstOrganisation.setAutodrop(true);
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.setWidth("220px");
@ -270,7 +270,7 @@ public class RolePanel extends Window implements EventListener, Deferrable
lstWarehouse.setAutocomplete(true);
lstWarehouse.setAutodrop(true);
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.setWidth("220px");