Hi All,
I am a new proud member to this community. I am working on
a piece of code where i have to loop hierarchical xml asynchronously
using HierarchicalCollectionView.
The same functionality existing for Flat xml data in
GroupingCollection.as -> buildGroups() method. I want to exactly do
the same functionality for hierarchial xml data in asynchronous
manner.
I tried using recursive calls its working but still its not
asynchrouns i looking for alternative and better solutions.
Any suggestions or help is highly appreciated.
Code from buildGroups() method from GroupingCollection.as.
/**
* @private
*
* Start building the groups
*/
private function buildGroups():Boolean
{
if (!prepared)
{
var _openItems:Object = {};
// initialize the variables
initialize();
// remove the items from the source collection if there
are any.
newCollection.removeAll();
if ((source as ICollectionView).length == 0)
return false;
var hierarchicalData:IHierarchicalData = new
HierarchicalData(newCollection);
HierarchicalData(hierarchicalData).childrenField =
childrenField;
hView = new HierarchicalCollectionView(
hierarchicalData, _openItems);
treeCursor = hView.createCursor();
flatView = source as ICollectionView;
flatCursor = flatView.createCursor();
gf = grouping.fields;
fieldCount = gf.length;
if (gf)
{
prepared = true;
if (async)
return false;
}
if (async)
return true;
}
flatCursor.seek(currentPosition);
while(!flatCursor.afterLast && currentPosition !=
CursorBookmark.LAST)
{
currentData = flatCursor.current;
for (var i:int = 0; i < fieldCount ; ++i)
{
var groupingField:String = gf[i].name;
var label:String = getDataLabel(currentData, gf[i]);
if(label != currentGroupLabels[i])
{
if (childrenArray && childrenArray.length)
{
ArrayCollection(currentGroups[fieldCount - 1]
[childrenField]).source = childrenArray;
childrenArray = [];
}
currentGroupLabels.splice(i+1);
currentGroups.splice(i+1);
currentIndices.splice(i+1);
currentGroupLabels[i] = label;
// check for grouping Object Function
if (gf[i].groupingObjectFunction != null)
currentGroups[i] =
gf[i].groupingObjectFunction(label);
else if (grouping.groupingObjectFunction != null)
currentGroups[i] =
grouping.groupingObjectFunction(label);
else
currentGroups[i] = {};
currentGroups[i][childrenField] = new
ArrayCollection();
currentGroups[i][grouping.label] =
currentGroupLabels[i];
itemIndex = currentIndices[i-1];
// create the group
IHierarchicalCollectionView(hView).addChild(currentGroups[i-1],
currentGroups[i]);
currentIndices[i-1] = ++itemIndex;
}
// insert the node as a child of the group
if ( i == fieldCount - 1)
{
itemIndex = currentIndices[i];
if (!childrenArray)
childrenArray = [];
childrenArray.push(currentData);
currentIndices[i] = ++itemIndex;
}
}
try
{
flatCursor.moveNext();
currentPosition = flatCursor.bookmark;
// return in case of async refresh
if (async)
return false;
}
catch (pending:ItemPendingError)
{
cleanUp();
pending.addResponder(new ItemResponder(
function(data:Object, token:Object=null):void
{
makeGroupedCollection();
},
function(info:Object, token:Object=null):void
{
//no-op
}));
}
}
if (currentPosition == CursorBookmark.LAST)
{
if (childrenArray && childrenArray.length)
{
ArrayCollection(currentGroups[fieldCount - 1]
[childrenField]).source = childrenArray;
}
applyFunctionForParentNodes(super.source as
ICollectionView, getSummaries);
if (source && summaries)
{
if (!super.source)
super.source = new ArrayCollection([source]) as
Object;
generateRootSummaries(grouping == null);
}
// dispatch collection change event of kind refresh.
var refreshEvent:CollectionEvent =
new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
refreshEvent.kind = CollectionEventKind.REFRESH;
dispatchEvent(refreshEvent);
cleanUp();
return true;
}
return true;
}
--
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en.