Enhancement suggestion: doFlexClickDataProviderItemByPropertyValue

36 views
Skip to first unread message

geomuck

unread,
Apr 22, 2010, 5:18:20 PM4/22/10
to Selenium-Flex API - Development
Hi group!

Today I had to modify the code suggestion I made back in December
(http://groups.google.com/group/sfapi-dev/browse_thread/thread/
9b3a01aa81c4786c#) to work with ListBases, in addition to DataGrids. I
don't think that the version I suggested back then was ever
incorporated into the code base, so I'd like to suggest that this
version be added (to ClickCommands.as) instead, since it adds that
additional ListBase support. Please let me know what you think!

Thanks,

George

/**
* Finds a row within a DataGrid or List, based on a given
property's value, and selects
* that row by setting the selectedItem value on the DataGrid/List,
then firing ListEvent.ITEM_FOCUS_IN,
* ListEvent.CHANGE, and ListEvent.ITEM_CLICK events. For example,
given this data in
* a dataProvider on component with ID 'compId':
*
* |idx|name| zip |
* | 1 |fred|80303|
* | 2 |judy|80026|
*
* this call would select the second row:
doFlexClickDataProviderItemByPropertyValue('compId', 'idx,2')
*
* You can also optionally specify a column index that will be
selected: doFlexClickDataGridItemByPropertyValue('compId', 'idx,2,1')
* In this case, cell "judy" would be the target of the events. If
unspecified, column
* index defaults to 0.
*
* @param id The ID of the Flex object
* @param value Takes the form
"searchFieldName,searchFieldValue[,columnIndex]"
* @return String 'true' if the selection succeeds, or an error
message if the call fails or the property is not found.
*/
public function
doFlexClickDataProviderItemByPropertyValue(id:String,
value:String):String
{
var args:Array = value.split(",");
var searchFieldName:String = args[0];
var searchFieldValue:String = args[1];
var colIdx:Number = 0;
if(args[2])
{
colIdx = args[2];
}

var widget:Object = appTreeParser.getWidgetById(id);
if(!(widget is DataGrid) && !(widget is AdvancedDataGrid) && !
(widget is ListBase))
{
return ErrorMessages.getError(ErrorMessages.ERROR_TYPE_MISMATCH,
[id, "DataGrid or AdvancedDataGrid or ListBase"]);
}

var provider:Object = widget.dataProvider;
if(provider == null)
{
return ErrorMessages.getError(ErrorMessages.ERROR_NO_PROPERTY,
[id, "dataProvider"]);
}

if(provider.length > 0)
{
// Expand all of the nodes in the dataProvider's parent, if
possible,
// to ensure that we can walk the entire tree.
if ("expandAll" in widget)
{
widget.expandAll();
}
var viewCursor:IViewCursor = provider.createCursor();
viewCursor.seek(CursorBookmark.FIRST);
var rowIdx:Number = 0;
do
{
var current:Object = viewCursor.current;
if (current[searchFieldName] == searchFieldValue)
{
widget.selectedItem = current;
var itemRenderer:IListItemRenderer = null;
if ("itemRenderer" in widget)
{
itemRenderer = widget.itemToItemRenderer(widget.selectedItem);
}
var retval:Boolean = widget.dispatchEvent(new
ListEvent(ListEvent.ITEM_FOCUS_IN, false, false, colIdx, rowIdx, null,
itemRenderer));
retval = retval && widget.dispatchEvent(new
ListEvent(ListEvent.CHANGE, false, false, colIdx, rowIdx, null,
itemRenderer));
return retval && widget.dispatchEvent(new
ListEvent(ListEvent.ITEM_CLICK, false, false, colIdx, rowIdx, null,
itemRenderer));
}
rowIdx++;
}
while (viewCursor.moveNext());
return ErrorMessages.getError(ErrorMessages.ERROR_MESSAGE,
["Unable to find property " + searchFieldName + "=" + searchFieldValue
+ " in dataProvider for " + id]);
}
else
{
return ErrorMessages.getError(ErrorMessages.ERROR_MESSAGE,
["dataProvider for " + id + " has length of zero."]);
}
}
Reply all
Reply to author
Forward
0 new messages