Packagetwaver
Classpublic class SelectionModel
InheritanceSelectionModel Inheritance flash.events.EventDispatcher

Selection model is a container works for a data box. Selection model responsible for managing the the selection status of all data contains in this connected data box. A data is selected, it will be added into this selection model; the data is unselected, it will be removed from this selection model. All these are done automatically internally, you don't need to do any extra work about it.

With selection model, you can visit all selected data, iterate all selected data, set data to unselected by removing the data from this selection model, etc.

You can set a data selected by setting data's selected property, or adding a data into this selection model. Always recommend to use selection model to set data selected status or check whether a data is selected. The reason is, you can add filter on selection model, so data.setSelected(true) will not guarantee the data will be selected. Using selectionMode.isSelectable(data) to check whether this data is really selected is a better idea.

Selection model will dispatch event to all installed listeners when data box selection is changed. Pressing key of "ctrl+a" will select all data, pressing "ctrl" or "shift" and with mouse click can appending/remove data selection on network canvas.



Public Properties
 PropertyDefined By
  count : int
[read-only] Get total count of this selection model.
SelectionModel
  filterFunction : Function
Get the filter function.
SelectionModel
  firstData : IData
[read-only] Get the first added data of this selection model.
SelectionModel
  lastData : IData
[read-only] Get the last added data from this selection model.
SelectionModel
  selection : ICollection
[read-only] Get all data contains in this selection model as a collection.
SelectionModel
  selectionMode : String
Get current selection mode.
SelectionModel
Public Methods
 MethodDefined By
  
Constructor.
SelectionModel
  
addPropertyChangeListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Add property change listener on this selection model.
SelectionModel
  
addSelectionChangeListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void
Add selection change listener on this selection model.
SelectionModel
  
appendSelection(datas:Object):void
Append more data into this selection model.
SelectionModel
  
Clear all data from this selection model.
SelectionModel
  
contains(data:IData):Boolean
Check whether this selection model contains specified data.
SelectionModel
  
dispatchPropertyChangeEvent(property:String, oldValue:Object, newValue:Object):Boolean
Dispatch a selection change property to all selection change listeners.
SelectionModel
  
isSelectable(data:IData):Boolean
Check whether specified data is selected.
SelectionModel
  
removePropertyChangeListener(listener:Function):void
Remove the specified property change listener from this selection model.
SelectionModel
  
removeSelection(datas:Object):void
Remove specified data from this selection model.
SelectionModel
  
removeSelectionChangeListener(listener:Function):void
Remove the specified listener from this selection model.
SelectionModel
  
selectAll():void
Call this method to select all data contains in the data box.
SelectionModel
  
setSelection(datas:Object):void
Set all specified data to selected status.
SelectionModel
  
toSelection(matchFunction:Function = null):ICollection
Get all selected data by specified filter function and return as a collection.
SelectionModel
Public Constants
 ConstantDefined By
  MULTIPLE_SELECTION : String = multipleSelection
[static] Selection mode indicates this selection model in multiple selection status.
SelectionModel
  NONE_SELECTION : String = noneSelection
[static] Selection mode indicates this selection model in "no data can be selected" status.
SelectionModel
  SINGLE_SELECTION : String = singleSelection
[static] Selection mode indicates this selection model in single selection status.
SelectionModel
Property Detail
countproperty
count:int  [read-only]

Get total count of this selection model. This tells you how many data selected in the connecting data box.


Implementation
    public function get count():int
filterFunctionproperty 
filterFunction:Function

Get the filter function. This filter can be used to determine whether a data can be selected. Use this filter to filter out the data that you never want it to be selected.


Implementation
    public function get filterFunction():Function
    public function set filterFunction(value:Function):void
firstDataproperty 
firstData:IData  [read-only]

Get the first added data of this selection model.


Implementation
    public function get firstData():IData
lastDataproperty 
lastData:IData  [read-only]

Get the last added data from this selection model.


Implementation
    public function get lastData():IData
selectionproperty 
selection:ICollection  [read-only]

Get all data contains in this selection model as a collection.


Implementation
    public function get selection():ICollection
selectionModeproperty 
selectionMode:String

Get current selection mode. Selection mode can be: NONE_SELECTION, SINGLE_SELECTION, MULTIPLE_SELECTION.


Implementation
    public function get selectionMode():String
    public function set selectionMode(value:String):void
Constructor Detail
SelectionModel()Constructor
public function SelectionModel(dataBox:DataBox)

Constructor. Create selection model and connect to this data box.

Parameters
dataBox:DataBox — the data box that this selection model will be connected to.
Method Detail
addPropertyChangeListener()method
public function addPropertyChangeListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void

Add property change listener on this selection model. This listener will be notified when any selection has been changed.

Parameters

listener:Function — the listener to be added
 
priority:int (default = 0) — the priority of the listener.
 
useWeakReference:Boolean (default = false) — whether use weak reference for this listener.

addSelectionChangeListener()method 
public function addSelectionChangeListener(listener:Function, priority:int = 0, useWeakReference:Boolean = false):void

Add selection change listener on this selection model.

Parameters

listener:Function — the listener to be added
 
priority:int (default = 0) — the priority of this listener
 
useWeakReference:Boolean (default = false) — whether use weak reference for this listener.

appendSelection()method 
public function appendSelection(datas:Object):void

Append more data into this selection model. This will make all specified data selected.

Parameters

datas:Object — the data need to be selected.

clearSelection()method 
public function clearSelection():void

Clear all data from this selection model. This will set all selected data to unselected status. Note clear this selection model will not data removed from the connecting data box. This just unselect all contained data.

contains()method 
public function contains(data:IData):Boolean

Check whether this selection model contains specified data.

Parameters

data:IData — the data to be checked.

Returns
Boolean — true if contains the specified data, false otherwise.
dispatchPropertyChangeEvent()method 
public function dispatchPropertyChangeEvent(property:String, oldValue:Object, newValue:Object):Boolean

Dispatch a selection change property to all selection change listeners.

Parameters

property:String — the property name of the change
 
oldValue:Object — the old value before the change
 
newValue:Object — the new value after the change

Returns
Boolean — true if dispatched successfully, false otherwise.
isSelectable()method 
public function isSelectable(data:IData):Boolean

Check whether specified data is selected.

Parameters

data:IData — the data to be checked.

Returns
Boolean — true if this data is selected, false otherwise.
removePropertyChangeListener()method 
public function removePropertyChangeListener(listener:Function):void

Remove the specified property change listener from this selection model.

Parameters

listener:Function — the property change listener to be removed.

removeSelection()method 
public function removeSelection(datas:Object):void

Remove specified data from this selection model. This will set all specified data to unselected status.

Parameters

datas:Object — the data to be unselected.

removeSelectionChangeListener()method 
public function removeSelectionChangeListener(listener:Function):void

Remove the specified listener from this selection model.

Parameters

listener:Function — the listener to be removed.

selectAll()method 
public function selectAll():void

Call this method to select all data contains in the data box.

setSelection()method 
public function setSelection(datas:Object):void

Set all specified data to selected status.

Parameters

datas:Object — all data to be selected.

toSelection()method 
public function toSelection(matchFunction:Function = null):ICollection

Get all selected data by specified filter function and return as a collection.

Parameters

matchFunction:Function (default = null) — the filter that used to filter out data you don't want to be returned in the result.

Returns
ICollection — a collection contains all selected data which match the specified filter function.
Constant Detail
MULTIPLE_SELECTIONConstant
public static const MULTIPLE_SELECTION:String = multipleSelection

Selection mode indicates this selection model in multiple selection status. This is the default mode, any data can be selected in this data box in the same time.

NONE_SELECTIONConstant 
public static const NONE_SELECTION:String = noneSelection

Selection mode indicates this selection model in "no data can be selected" status. In this mode all data contains in the data box can not be selected.

SINGLE_SELECTIONConstant 
public static const SINGLE_SELECTION:String = singleSelection

Selection mode indicates this selection model in single selection status. In this case, only one data can be selected in this data box. Selecting a new data will make the old one unselected.