Packagesystem.models.arrays
Classpublic class PageableArrayModel
InheritancePageableArrayModel Inheritance ChangeModel Inheritance KernelModel Inheritance Object
Implements OrderedIterator, Runnable

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

View the examples



Public Properties
 PropertyDefined By
 InheritedbeforeChanged : Signaler
[read-only] Emits a message before the current object in the model is changed.
ChangeModel
 Inheritedchanged : Signaler
[read-only] Emits a message when the current object in the model is changed.
ChangeModel
 Inheritedcleared : Signaler
[read-only] Emits a message when the current object in the model is cleared.
ChangeModel
  count : uint
Determinates the number of elements in a page of this model.
PageableArrayModel
 Inheritedcurrent : *
Determinates the selected value in this model.
ChangeModel
  currentPage : uint
Indicates the current page selected in the model.
PageableArrayModel
  initialized : Signaler
[read-only] Returns the event name use in the notifyInit method.
PageableArrayModel
  length : uint
[read-only] Indicates the number of elements in the model.
PageableArrayModel
  pageCount : Number
[read-only] Indicates the numbers of page with the current model.
PageableArrayModel
 Inheritedsecurity : Boolean = true
This property defined if the current property can accept the same object in argument as the current one.
ChangeModel
  updated : Signaler
[read-only] Returns the event name use in the notifyUpdate method.
PageableArrayModel
Public Methods
 MethodDefined By
  
PageableArrayModel(count:uint = 1, factory:Array = null)
Creates a new PageableArrayModel instance.
PageableArrayModel
  
clear():void
[override] Clear the model.
PageableArrayModel
  
firstPage():void
Seek the iterator in the first page of this object.
PageableArrayModel
  
getByKey(key:*, primaryKey:String = id):Object
Returns the object defined by the key passed in argument and register in the model.
PageableArrayModel
  
hasNext():Boolean
Returns true if the list has a next page.
PageableArrayModel
  
hasPrevious():Boolean
Returns true if the list has a previous page.
PageableArrayModel
  
init(datas:Array, autoClear:Boolean = true, autoRefresh:Boolean = true):void
Fill and initialize the model with an Array of ValueObject.
PageableArrayModel
 Inherited
isLocked():Boolean
Returns true if the object is locked.
KernelModel
  
key():*
Returns the current key of the internal pointer of the iterator (optional operation).
PageableArrayModel
  
lastPage():void
Seek the iterator in the last page of this object.
PageableArrayModel
 Inherited
lock():void
Locks the object.
KernelModel
  
next():*
Show the next page of the model.
PageableArrayModel
 Inherited
notifyBeforeChange(value:*):void
Notify a signal before the specified value is changed.
ChangeModel
 Inherited
notifyChange(value:*):void
Notify a signal when the model is changed.
ChangeModel
 Inherited
Notify a signal when the model is cleared.
ChangeModel
  
notifyInit():void
Emit a message when the model is initialized.
PageableArrayModel
  
notifyUpdate(value:*):*
Emit a message when the model is updated.
PageableArrayModel
  
pageOf(value:Object):uint
Finds and indicates the page number of the specified value object register in the model.
PageableArrayModel
  
Show in the previous page in the list or previous screen.
PageableArrayModel
  
refresh():void
Refresh the iterator of the model and run it.
PageableArrayModel
  
remove():*
Removes from the underlying model the last element returned by the iterator (optional operation).
PageableArrayModel
  
reset():void
Resets the key pointer of the iterator.
PageableArrayModel
  
run(... arguments):void
Run the model when is initialize.
PageableArrayModel
  
seek(position:*):void
Seek the position of the pointer in the model but don't notify an update signal.
PageableArrayModel
 Inherited
supports(value:*):Boolean
Returns true if the Validator object validate the value.
KernelModel
  
toArray():Array
Returns a new Array representation of all elements in this model.
PageableArrayModel
 Inherited
unlock():void
Unlocks the display.
KernelModel
 Inherited
validate(value:*):void
Evaluates the specified value and throw a TypeError object if the value is not valid.
KernelModel
Property Detail
countproperty
count:uint

Determinates the number of elements in a page of this model.


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

Indicates the current page selected in the model.


Implementation
    public function get currentPage():uint
    public function set currentPage(value:uint):void
initializedproperty 
initialized:Signaler  [read-only]

Returns the event name use in the notifyInit method.


Implementation
    public function get initialized():Signaler
lengthproperty 
length:uint  [read-only]

Indicates the number of elements in the model.


Implementation
    public function get length():uint
pageCountproperty 
pageCount:Number  [read-only]

Indicates the numbers of page with the current model.


Implementation
    public function get pageCount():Number
updatedproperty 
updated:Signaler  [read-only]

Returns the event name use in the notifyUpdate method.


Implementation
    public function get updated():Signaler
Constructor Detail
PageableArrayModel()Constructor
public function PageableArrayModel(count:uint = 1, factory:Array = null)

Creates a new PageableArrayModel instance.

Parameters
count:uint (default = 1) — Indicates the default number of elements by page in the model (default 1).
 
factory:Array (default = null) — the optional internal Array reference to build the model, by default an empty Array is created.
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.

getByKey()method 
public function getByKey(key:*, primaryKey:String = id):Object

Returns the object defined by the key passed in argument and register in the model.

Parameters

key:*
 
primaryKey:String (default = id)

Returns
Object — the object defined by the key passed in argument and 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.

key()method 
public function key():*

Returns the current key of the internal pointer of the iterator (optional operation).

Returns
* — the current key of the internal pointer of the iterator (optional operation).
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

Emit a message when the model is initialized.

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

Emit a message when the model is updated.

Parameters

value:*

Returns
*
pageOf()method 
public function pageOf(value:Object):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

value:Object

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 iterator of the model and run it.

remove()method 
public function remove():*

Removes from the underlying model the last element returned by the iterator (optional operation).

Returns
*

Throws
IllegalOperationError — The PageableArrayModel remove method is unsupported.
reset()method 
public function reset():void

Resets the key pointer of the iterator.

run()method 
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

seek()method 
public function seek(position:*):void

Seek the position of the pointer in the model but don't notify an update signal.

Parameters

position:*

toArray()method 
public function toArray():Array

Returns a new Array representation of all elements in this model.

Returns
Array — a new Array representation of all elements in this model.
Examples
Example
     
     package examples
     {
         import core.dump;
         
         import system.models.arrays.PageableArrayModel;
         
         import flash.display.Sprite;
         import flash.events.KeyboardEvent;
         import flash.ui.Keyboard;
         
         public class PageableArrayModelExample extends Sprite
         {
             public function PageableArrayModelExample()
             {
                 stage.addEventListener( KeyboardEvent.KEY_DOWN , keyDown ) ;
                 
                 model = new PageableArrayModel( 2 ) ;
                 
                 // model.count =  3 ;
                 
                 model.initialized.connect( init ) ; 
                 model.updated.connect( update ) ; 
                 
                 var datas:Array  = [] ;
                 
                 for ( var i:uint = 0 ; i < 20 ; i++ )
                 {
                     datas.push( { id:i } ) ;
                 }
                 
                 model.init( datas , false , false ) ;
                 
                 model.currentPage = 2 ;
             }
             
             protected var model:PageableArrayModel ;
             
             protected function init( model:PageableArrayModel ):void
             {
                 trace( model + " init" ) ;
             }
             
             protected function update( value:* , model:PageableArrayModel ):void
             {
                 trace( model + " update " + model.currentPage + "/" + model.pageCount + " value:" + dump(value) ) ;
             }
             
             protected function keyDown( e:KeyboardEvent ):void
             {
                 var code:uint = e.keyCode ;
                 switch( code )
                 {
                     case Keyboard.LEFT :
                     {
                         if ( model.hasPrevious() )
                         {
                             model.previous() ;
                         }
                         else
                         {
                             model.lastPage() ;
                         }
                         break ;
                     }
                     case Keyboard.RIGHT :
                     {
                         if ( model.hasNext() )
                         {
                             model.next() ;
                         }
                         else
                         {
                             model.firstPage() ;
                         }
                         break ;
                     }
                     case Keyboard.SPACE :
                     {
                         model.lock() ;
                         model.count = 4 ; // change the count value but not update the model.
                         model.unlock() ;
                    }
                 }
             }
         }
     }