Packagevegas.models.arrays
Classpublic class PageableArrayModelObject
InheritancePageableArrayModelObject Inheritance CoreModelObject Inheritance CoreModel Inheritance CoreEventDispatcher Inheritance Object

Defines an Array model with a 'page by page' iterator.

View the examples



Public Properties
 PropertyDefined By
 Inheritedchannel : String
[read-only] Indicates the channel of this dispatcher if this instance is global.
CoreEventDispatcher
  count : uint
Determinates the count of items in a page of this model.
PageableArrayModelObject
  currentPage : Number
Indicates the current page selected in the model.
PageableArrayModelObject
 Inheritedid : *
Returns the id of this IModelObject.
CoreModel
  pageCount : Number
[read-only] Indicates the numbers of page with the current model.
PageableArrayModelObject
 Inheritedsecurity : Boolean = true
This property defined if the setCurrentVO method can accept the same vo in argument as the current one.
CoreModelObject
Public Methods
 MethodDefined By
  
PageableArrayModelObject(global:Boolean = true, channel:String = null, id:* = null)
Creates a new PageableArrayModelObject instance.
PageableArrayModelObject
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0.0, useWeakReference:Boolean = false):void
Allows the registration of event listeners on the event target.
CoreEventDispatcher
  
clear():void
[override] Clear the model.
PageableArrayModelObject
 Inherited
Returns and creates a new empty ModelObjectEvent.
CoreModelObject
 Inherited
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
CoreEventDispatcher
  
firstPage():void
Seek the iterator in the first page of this object.
PageableArrayModelObject
 Inherited
Returns the current ValueObject selected in this model.
CoreModelObject
 Inherited
Returns the internal system.events.EventDispatcher reference.
CoreEventDispatcher
 Inherited
Returns the event name use in the setCurrentVO method before is changed.
CoreModelObject
 Inherited
Returns the event name use in the setVO method.
CoreModelObject
 Inherited
Returns the event name use in the clear method.
CoreModelObject
  
Returns the event name use in the notifyInit method.
PageableArrayModelObject
  
Returns the event name use in the notifyUpdate method.
PageableArrayModelObject
  
Returns the ValueObject defined by the id passed in argument register in the model.
PageableArrayModelObject
 Inherited
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
CoreEventDispatcher
  
hasNext():Boolean
Returns true if the list has a next page.
PageableArrayModelObject
  
hasPrevious():Boolean
Returns true if the list has a previous page.
PageableArrayModelObject
  
init(datas:Array, autoClear:Boolean = true, autoRefresh:Boolean = true):void
Fill and initialize the model with an Array of ValueObject.
PageableArrayModelObject
 Inherited
This method is invoked in the constructor of the class to initialize all events.
CoreModelObject
 Inherited
isGlobal():Boolean
Indicates if the dispatcher use a global event flow.
CoreEventDispatcher
 Inherited
isLocked():Boolean
Returns true if the object is locked.
CoreEventDispatcher
  
Returns a PageByPageIterator of this model.
PageableArrayModelObject
  
lastPage():void
Seek the iterator in the last page of this object.
PageableArrayModelObject
 Inherited
lock():void
Locks the object.
CoreEventDispatcher
  
next():*
Show the next page of the model.
PageableArrayModelObject
 Inherited
Notify a ModelObjectEvent before the current ValueObject selected in the model is changed.
CoreModelObject
 Inherited
Notify a ModelObjectEvent when a ValueObject change in the model.
CoreModelObject
 Inherited
Notify a ModelObjectEvent when the model is cleared.
CoreModelObject
  
notifyInit():void
Notify an Event object when the model is initialized.
PageableArrayModelObject
  
notifyUpdate(value:*):*
Notify an Event when a ValueObject is inserted in the model.
PageableArrayModelObject
  
Finds and indicates the page number of the specified value object register in the model.
PageableArrayModelObject
  
Show in the previous page in the list or previous screen.
PageableArrayModelObject
  
refresh():void
Refresh the model.
PageableArrayModelObject
 Inherited
registerEventListener(type:String, listener:*, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Allows the registration of event listeners on the event target (Function or EventListener).
CoreEventDispatcher
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
CoreEventDispatcher
  
reset():void
Resets the key pointer of the iterator.
PageableArrayModelObject
  
run(... arguments):void
[override] Run the model when is initialize.
PageableArrayModelObject
  
setCount(n:uint, noRender:Boolean = false):void
Set the count of items in a page of this model.
PageableArrayModelObject
 Inherited
Sets the current ValueObject selected in this model.
CoreModelObject
 Inherited
Sets the internal EventDispatcher reference.
CoreEventDispatcher
 Inherited
setEventTypeBEFORE_CHANGE(type:String):void
Returns the event name use in the setCurrentVO method before is changed.
CoreModelObject
 Inherited
setEventTypeCHANGE(type:String):void
Returns the event name use in the setVO method.
CoreModelObject
 Inherited
setEventTypeCLEAR(type:String):void
Returns the event name use in the clear method.
CoreModelObject
  
setEventTypeINIT(type:String):void
Sets the event name use in the notifyInit method.
PageableArrayModelObject
  
setEventTypeUPDATE(type:String):void
Sets the event name use in the notifyUpdate method.
PageableArrayModelObject
 Inherited
setGlobal(flag:Boolean = false, channel:String = null):void
Sets if the instance use a global system.events.EventDispatcher to dispatch this events, if the flag value is false the instance use a local EventDispatcher.
CoreEventDispatcher
  
size():uint
Returns the number of ValueObject in this model.
PageableArrayModelObject
 Inherited
supports(value:*):Boolean
Returns true if the IValidator object validate the value.
CoreModelObject
  
toArray():Array
Returns the Array representation of all vos in this model.
PageableArrayModelObject
 Inherited
unlock():void
Unlocks the display.
CoreEventDispatcher
 Inherited
unregisterEventListener(type:String, listener:*, useCapture:Boolean = false):void
Removes a listener (Function or EventListener object) from the EventDispatcher object.
CoreEventDispatcher
 Inherited
validate(value:*):void
Evaluates the specified value and throw a TypeError object if the value is not valid.
CoreModelObject
 Inherited
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
CoreEventDispatcher
Protected Methods
 MethodDefined By
 Inherited
Creates and returns the internal EventDispatcher reference (this method is invoked in the constructor).
CoreEventDispatcher
Property Detail
countproperty
count:uint

Determinates the count of items in a page of this model.


Implementation
    public function get count():uint
    public function set count(value:uint):void
currentPageproperty 
currentPage:Number

Indicates the current page selected in the model.


Implementation
    public function get currentPage():Number
    public function set currentPage(value:Number):void
pageCountproperty 
pageCount:Number  [read-only]

Indicates the numbers of page with the current model.


Implementation
    public function get pageCount():Number
Constructor Detail
PageableArrayModelObject()Constructor
public function PageableArrayModelObject(global:Boolean = true, channel:String = null, id:* = null)

Creates a new PageableArrayModelObject instance.

Parameters
global:Boolean (default = true) — the flag to use a global event flow or a local event flow (default true).
 
channel:String (default = null) — the name of the global event flow if the global argument is true.
 
id:* (default = null) — the id of this model.
Method Detail
clear()method
override public function clear():void

Clear the model.

firstPage()method 
public function firstPage():void

Seek the iterator in the first page of this object.

getEventTypeINIT()method 
public function getEventTypeINIT():String

Returns the event name use in the notifyInit method.

Returns
String — the event name use in the notifyInit method.
getEventTypeUPDATE()method 
public function getEventTypeUPDATE():String

Returns the event name use in the notifyUpdate method.

Returns
String — the event name use in the notifyUpdate method.
getVO()method 
public function getVO(id:*):ValueObject

Returns the ValueObject defined by the id passed in argument register in the model.

Parameters

id:*

Returns
ValueObject — the ValueObject defined by the id passed in argument register in the model.
hasNext()method 
public function hasNext():Boolean

Returns true if the list has a next page.

Returns
Booleantrue if the list has a next page.
hasPrevious()method 
public function hasPrevious():Boolean

Returns true if the list has a previous page.

Returns
Booleantrue if the list has a previous page.
init()method 
public function init(datas:Array, autoClear:Boolean = true, autoRefresh:Boolean = true):void

Fill and initialize the model with an Array of ValueObject.

Parameters

datas:Array — The array of all value objects to insert in the model.
 
autoClear:Boolean (default = true) — (optional) If this argument is true the clear method is invoked when the initialization begin.
 
autoRefresh:Boolean (default = true) — (optional) If this argument is true the model is running when this initialization is finished.

iterator()method 
public function iterator():Iterator

Returns a PageByPageIterator of this model.

Returns
Iterator — a PageByPageIterator of this model.
lastPage()method 
public function lastPage():void

Seek the iterator in the last page of this object.

next()method 
public function next():*

Show the next page of the model.

Returns
*
notifyInit()method 
public function notifyInit():void

Notify an Event object when the model is initialized.

notifyUpdate()method 
public function notifyUpdate(value:*):*

Notify an Event when a ValueObject is inserted in the model. If the model countVO value is > 1 notify an ArrayEvent else if the coutVO value is 1 notify a ModelObjectEvent.

Parameters

value:*

Returns
*
pageOf()method 
public function pageOf(vo:ValueObject):uint

Finds and indicates the page number of the specified value object register in the model. If the passed-in value object is not found 0 is returned.

Parameters

vo:ValueObject

Returns
uint
previous()method 
public function previous():*

Show in the previous page in the list or previous screen.

Returns
*
refresh()method 
public function refresh():void

Refresh the model.

reset()method 
public function reset():void

Resets the key pointer of the iterator.

run()method 
override public function run(... arguments):void

Run the model when is initialize. This method don't work if the model is locked.

Parameters

... arguments

See also

Lockable
setCount()method 
public function setCount(n:uint, noRender:Boolean = false):void

Set the count of items in a page of this model.

Parameters

n:uint — The count value of items in this model. This value must be >=1.
 
noRender:Boolean (default = false) — Indicates if the method call the run method if this argumement is false (default is false).

setEventTypeINIT()method 
public function setEventTypeINIT(type:String):void

Sets the event name use in the notifyInit method.

Parameters

type:String

setEventTypeUPDATE()method 
public function setEventTypeUPDATE(type:String):void

Sets the event name use in the notifyUpdate method.

Parameters

type:String

size()method 
public function size():uint

Returns the number of ValueObject in this model.

Returns
uint — the number of ValueObject in this model.
toArray()method 
public function toArray():Array

Returns the Array representation of all vos in this model.

Returns
Array — the Array representation of all vos in this model.
Examples
Example
     
     import vegas.events.ModelObjectEvent ;
     import vegas.models.arrays.PageableArrayModelObject ;
     import vegas.vo.SimpleValueObject ;
     
     import system.events.ArrayEvent ;
     
     var init:Function = function( e:Event ):void
     {
         trace( "init" ) ;
     }
     
     var update:Function = function( e:Event ):void
     {
         switch( true )
         {
             case e is ArrayEvent :
             {
                 trace( e + " : " + (e as ArrayEvent).array ) ;
                 break ;
             }
             case e is ModelObjectEvent :
             {
                 trace( e + " : " + (e as ModelObjectEvent).getVO() ) ;
                 break ;
             }
             default :
             {
                 trace( e + " : unknow type of event.") ;
             }
         }
     }
     
     var model:PageableArrayModelObject = new PageableArrayModelObject() ;
     
     model.count =  2 ;
     
     model.addEventListener( Event.INIT                 , init   ) ;
     model.addEventListener( ModelObjectEvent.UPDATE_VO , update ) ;
     
     var datas:Array  = [] ;
     var count:uint = 20 ;
     for ( var i:uint = 0 ; i<count ; i++ )
     {
         datas.push( new SimpleValueObject( { id:i } ) ) ;
     }
     
     model.init( datas ) ;
     
     var onKeyDown:Function = function( e:KeyboardEvent ):void
     {
         var code:uint = e.keyCode ;
         switch( code )
         {
             case Keyboard.LEFT :
             {
                 if ( model.hasPrevious() == false )
                 {
                     model.lastPage() ;
                 }
                 else
                 {
                     model.previous() ;
                 }
                 break ;
            }
            case Keyboard.RIGHT :
            {
                if ( model.hasNext() == false )
                {
                    model.firstPage() ;
                }
                else
                {
                    model.next() ;
                }
                break ;
            }
            case Keyboard.SPACE :
            {
                model.setCount( 4 , true ) ; // change the count value but not auto restart the update process of the model.
            }
         }
     }
     
     stage.addEventListener( KeyboardEvent.KEY_DOWN , onKeyDown ) ;
     
     trace( "Press Keyboard.LEFT and Keyboard.RIGHT keys to test this model" ) ;
     trace( "Press Keyboard.SPACE to use a page with 4 items inside (change count of items)." ) ;
     
     model.currentPage = 2 ; // go to the page 2