Skip to content

Commit

Permalink
Have AssociationCollection's behave like an IList
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultz committed Oct 25, 2011
1 parent 3dd5694 commit 5595d98
Showing 1 changed file with 84 additions and 1 deletion.
85 changes: 84 additions & 1 deletion src/mesh/model/associations/AssociationCollection.as
Expand Up @@ -3,12 +3,13 @@ package mesh.model.associations
import mesh.model.Entity;
import mesh.model.store.Query;

import mx.collections.IList;
import mx.collections.ListCollectionView;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
import mx.events.PropertyChangeEvent;

public class AssociationCollection extends Association
public class AssociationCollection extends Association implements IList
{
private var _list:ListCollectionView;
private var _snapshot:Array = [];
Expand All @@ -24,6 +25,38 @@ package mesh.model.associations
_list.addEventListener(CollectionEvent.COLLECTION_CHANGE, handleListCollectionChange);
}

/**
* @inheritDoc
*/
public function addItem(item:Object):void
{
_list.addItem(item);
}

/**
* @inheritDoc
*/
public function addItemAt(item:Object, index:int):void
{
_list.addItemAt(item, index);
}

/**
* @inheritDoc
*/
public function getItemAt(index:int, prefetch:int = 0):Object
{
return _list.getItemAt(index, prefetch);
}

/**
* @inheritDoc
*/
public function getItemIndex(item:Object):int
{
return _list.getItemIndex(item);
}

private function handleListCollectionChange(event:CollectionEvent):void
{
switch (event.kind) {
Expand All @@ -44,6 +77,8 @@ package mesh.model.associations
if (event.kind != CollectionEventKind.UPDATE) {
_snapshot = _list.toArray();
}

dispatchEvent(event);
}

private function handleEntitiesAdded(items:Array):void
Expand Down Expand Up @@ -79,6 +114,54 @@ package mesh.model.associations
}
}

/**
* @inheritDoc
*/
public function itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void
{
_list.itemUpdated(item, property, oldValue, newValue);
}

/**
* @inheritDoc
*/
public function removeAll():void
{
_list.removeAll();
}

/**
* @inheritDoc
*/
public function removeItemAt(index:int):Object
{
return _list.removeItemAt(index);
}

/**
* @inheritDoc
*/
public function setItemAt(item:Object, index:int):Object
{
return _list.setItemAt(item, index);
}

/**
* @inheritDoc
*/
public function toArray():Array
{
return _list.toArray();
}

/**
* @inheritDoc
*/
public function get length():int
{
return _list.length;
}

/**
* @inheritDoc
*/
Expand Down

0 comments on commit 5595d98

Please sign in to comment.