BiSelectionModel

This class provides a basic selection model

This treats children as selectable items inside a component. The items can be of any type but if they are not BiComponents you will have to override the following methods and properties: first, last, items, getNext, getPrevious, scrollItemIntoView, getItemLeft, getItemTop, getItemWidth and getItemHeight.

To update the visuals (to show what is selected) override the following methods: updateItemSelectionState, updateItemAnchorState and updateItemLeadState.

This class extends BiEventTarget and therefore all methods and fields available for BiEventTarget are also available for BiSelectionModel .

Constructor

new BiSelectionModel ( oOwner )

Parameters

Name Type Optional Default Descripton
oOwner BiComponent This is the component the selection model is handling

Properties

Name Type get set Descripton
anchorItem BiComponent/Object checked checked This item is used when doing multiple selection with the shift key
canDeselect Boolean checked checked Whether the user can deselect items. If this is false you need to select something else to deselect an item
dragSelection Boolean checked checked Drag selection is used to hold down the mouse to select mutliple items
first BiComponent/Object checked Returns the first selectable item
items BiComponent[]/Object[] checked Returns an array containing the items
last BiComponent/Object checked Returns the last selectable item
leadItem BiComponent/Object checked checked This item is used when doing multiple selection. This is the last item selected.
multipleSelection Boolean checked checked Whether the selection model supports multiple selection
owner BiComponent checked checked This is the owner component that is containing the selectable objects. This should not be set after the selection model has been used
selectedItems BiComponent[]/Object[] checked checked Returns an array containing the selected items

Methods

Name Description
deselectAll Deselects all items
getCtrlEnd Returns the item to navigate to when the end key and the control key is pressed. This should usually just return the last item.
getCtrlHome Returns the item to navigate to when the home key and the control key is pressed. This should usually just return the first item.
getDown Returns the item to navigate to when the down arrow key is pressed. This should usually just return the item below the current one.
getEnd Returns the item to navigate to when the end key is pressed. This should usually just return the last item.
getHome Returns the item to navigate to when the home key is pressed. This should usually just return the first item.
getItemHeight Returns the height of the item
getItemLeft Returns the left position of the item
getItemSelected Returns whether the item is selected or not.
getItemTop Returns the top position of the item
getItemToSelect Returns the next item to select (move to) when using the keyboard. Usually it is enough to override the needed methods among these: getLeft, getRight, getUp, getDown, getHome, getCtrlHome, getEnd, getCtrlEnd, getpageUp and getPageDown.
getItemWidth Returns the width of the item
getLeft Returns the item to navigate to when the left arrow key is pressed. This should usually just return the item to the left of the current one.
getNext Gets the item coming next after the item
getPageDown Returns the item to navigate to when the page down is pressed.
getPageUp Returns the item to navigate to when the page up key is pressed.
getPrevious Gets the item coming before the item
getRight Returns the item to navigate to when the right arrow key is pressed. This should usually just return the item to the right of the current one.
getUp Returns the item to navigate to when the up arrow key is pressed. This should usually just return the item above the current one.
handleClick This should be called when the user clicks on an item
handleDblClick This should be called when the user double clicks on an item
handleKeyDown This should be called when the user presses down a key on the component
handleMouseDown This should be called when the user presses down the mouse button on an item
handleMouseOver This should be called when the user moves the mouse over an item
handleMouseUp This should be called when the user releases the mouse button on an item
isBefore Returns whether the first item is before the second item in the component.
isEqual Compares two items and returns true if they are equal.
scrollItemIntoView Scrolls the owner so that the item becomes visible.
selectAll Selects all items
selectItemRange Selects the items passed as arguments and all the items between them
setItemSelected Sets the item as selected (or deselected) and also updates the selected items collection.
updateItemAnchorState This is called when the anchor state of the item has changed. Override this to update the visuals to reflect the anchor state.
updateItemLeadState This is called when the lead state of the item has changed. Override this to update the visuals to reflect the lead state.
updateItemSelectionState This is called when the selection state of the item has changed. Override this to update the visuals to reflect the selected state.

Events

Name Type Bubbles Descripton
change BiEvent Fires when the selected items are changed
leaditemchange BiEvent Fires when the lead item is changed

Static Methods

None.

Static Fields

None.

Remarks

You need to add event listeners to the owner that calls handleKeyDown, handleMouseDown, handleMouseUp, handleMouseOver, handleClick and handleDblClick.

Method Details

deselectAll

Deselects all items

Syntax

object.deselectAll
 (
 
 )
 

Parameters

No arguments.

Return Type

void

getCtrlEnd

Returns the item to navigate to when the end key and the control key is pressed. This should usually just return the last item.

Syntax

object.getCtrlEnd
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getCtrlHome

Returns the item to navigate to when the home key and the control key is pressed. This should usually just return the first item.

Syntax

object.getCtrlHome
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getDown

Returns the item to navigate to when the down arrow key is pressed. This should usually just return the item below the current one.

Syntax

object.getDown
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getEnd

Returns the item to navigate to when the end key is pressed. This should usually just return the last item.

Syntax

object.getEnd
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getHome

Returns the item to navigate to when the home key is pressed. This should usually just return the first item.

Syntax

object.getHome
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getItemHeight

Returns the height of the item

Syntax

object.getItemHeight
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to get the size for

Return Type

Number

getItemLeft

Returns the left position of the item

Syntax

object.getItemLeft
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to get the position for

Return Type

Number

getItemSelected

Returns whether the item is selected or not.

Syntax

object.getItemSelected
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to check whether it is selected

Return Type

Boolean

getItemTop

Returns the top position of the item

Syntax

object.getItemTop
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to get the position for

Return Type

Number

getItemToSelect

Returns the next item to select (move to) when using the keyboard. Usually it is enough to override the needed methods among these: getLeft, getRight, getUp, getDown, getHome, getCtrlHome, getEnd, getCtrlEnd, getpageUp and getPageDown.

Syntax

object.getItemToSelect
 (
 oKeyboardEvent
 )
 

Parameters

Name Type Optional Default Descripton
oKeyboardEvent BiKeyboardEvent The event object used for the keyboard event

Return Type

BiComponent/Object

getItemWidth

Returns the width of the item

Syntax

object.getItemWidth
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to get the size for

Return Type

Number

getLeft

Returns the item to navigate to when the left arrow key is pressed. This should usually just return the item to the left of the current one.

Syntax

object.getLeft
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getNext

Gets the item coming next after the item

Syntax

object.getNext
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to get the next from

Return Type

BiComponent/Object

getPageDown

Returns the item to navigate to when the page down is pressed.

Syntax

object.getPageDown
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getPageUp

Returns the item to navigate to when the page up key is pressed.

Syntax

object.getPageUp
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getPrevious

Gets the item coming before the item

Syntax

object.getPrevious
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to get the previous from

Return Type

BiComponent/Object

getRight

Returns the item to navigate to when the right arrow key is pressed. This should usually just return the item to the right of the current one.

Syntax

object.getRight
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

getUp

Returns the item to navigate to when the up arrow key is pressed. This should usually just return the item above the current one.

Syntax

object.getUp
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that we want to get the new item relative to

Return Type

BiComponent/Object

handleClick

This should be called when the user clicks on an item

Syntax

object.handleClick
 (
 oItem,e
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that was clicked
e BiMouseEvent/Object The mouse event used in the click event

Return Type

void

handleDblClick

This should be called when the user double clicks on an item

Syntax

object.handleDblClick
 (
 oItem,e
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that was double clicked
e BiMouseEvent/Object The mouse event used in the dblclick event

Return Type

void

handleKeyDown

This should be called when the user presses down a key on the component

Syntax

object.handleKeyDown
 (
 e
 )
 

Parameters

Name Type Optional Default Descripton
e BiKeyboardEvent/Object The keyboard event used in the key down event

Return Type

void

handleMouseDown

This should be called when the user presses down the mouse button on an item

Syntax

object.handleMouseDown
 (
 oItem,e
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that was pressed
e BiMouseEvent/Object The mouse event used in the mouse down event

Return Type

void

handleMouseOver

This should be called when the user moves the mouse over an item

Syntax

object.handleMouseOver
 (
 oItem,e
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that the mouse over was triggered on
e BiMouseEvent/Object The mouse event used in the mouse over event

Return Type

void

handleMouseUp

This should be called when the user releases the mouse button on an item

Syntax

object.handleMouseUp
 (
 oItem,e
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item that the mouse up was triggered on
e BiMouseEvent/Object The mouse event used in the mouse up event

Return Type

void

isBefore

Returns whether the first item is before the second item in the component.

Syntax

object.isBefore
 (
 oItem1,oItem2
 )
 

Parameters

Name Type Optional Default Descripton
oItem1 BiComponent/Object The item to test if before
oItem2 BiComponent/Object The item to test if after

Return Type

Boolean

isEqual

Compares two items and returns true if they are equal.

Syntax

object.isEqual
 (
 oItem1,oItem2
 )
 

Parameters

Name Type Optional Default Descripton
oItem1 BiComponent/Object Item one to compare
oItem2 BiComponent/Object Item two to compare

Return Type

Boolean

scrollItemIntoView

Scrolls the owner so that the item becomes visible.

Syntax

object.scrollItemIntoView
 (
 oItem
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to scroll into view

Return Type

void

selectAll

Selects all items

Syntax

object.selectAll
 (
 
 )
 

Parameters

No arguments.

Return Type

void

selectItemRange

Selects the items passed as arguments and all the items between them

Syntax

object.selectItemRange
 (
 oItem1,oItem2
 )
 

Parameters

Name Type Optional Default Descripton
oItem1 BiComponent/Object The first item to select
oItem2 BiComponent/Object The last item to select

Return Type

void

setItemSelected

Sets the item as selected (or deselected) and also updates the selected items collection.

Syntax

object.setItemSelected
 (
 oItem,bSelected
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to select or deselect
bSelected Boolean Whether to select or deselect

Return Type

void

updateItemAnchorState

This is called when the anchor state of the item has changed. Override this to update the visuals to reflect the anchor state.

Syntax

object.updateItemAnchorState
 (
 oItem,bAnchor
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to update the anchor state for
bAnchor Boolean Whether the item is the anchor item

Return Type

void

updateItemLeadState

This is called when the lead state of the item has changed. Override this to update the visuals to reflect the lead state.

Syntax

object.updateItemLeadState
 (
 oItem,bLead
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to update the selected state for
bLead Boolean Whether the item is the lead item

Return Type

void

updateItemSelectionState

This is called when the selection state of the item has changed. Override this to update the visuals to reflect the selected state.

Syntax

object.updateItemSelectionState
 (
 oItem,bSelected
 )
 

Parameters

Name Type Optional Default Descripton
oItem BiComponent/Object The item to update the selected state for
bSelected Boolean Whether the item is selected

Return Type

void