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

NameTypeOptionalDefaultDescripton
oOwnerBiComponentThis is the component the selection model is handling

Properties

NameTypegetsetDescripton
anchorItemBiComponent/ObjectcheckedcheckedThis item is used when doing multiple selection with the shift key
canDeselectBooleancheckedcheckedWhether the user can deselect items. If this is false you need to select something else to deselect an item
dragSelectionBooleancheckedcheckedDrag selection is used to hold down the mouse to select mutliple items
firstBiComponent/ObjectcheckedReturns the first selectable item
itemsBiComponent[]/Object[]checkedReturns an array containing the items
lastBiComponent/ObjectcheckedReturns the last selectable item
leadItemBiComponent/ObjectcheckedcheckedThis item is used when doing multiple selection. This is the last item selected.
multipleSelectionBooleancheckedcheckedWhether the selection model supports multiple selection
ownerBiComponentcheckedcheckedThis is the owner component that is containing the selectable objects. This should not be set after the selection model has been used
selectedItemsBiComponent[]/Object[]checkedcheckedReturns an array containing the selected items

Methods

NameDescription
deselectAllDeselects all items
getCtrlEndReturns the item to navigate to when the end key and the control key is pressed. This should usually just return the last item.
getCtrlHomeReturns the item to navigate to when the home key and the control key is pressed. This should usually just return the first item.
getDownReturns the item to navigate to when the down arrow key is pressed. This should usually just return the item below the current one.
getEndReturns the item to navigate to when the end key is pressed. This should usually just return the last item.
getHomeReturns the item to navigate to when the home key is pressed. This should usually just return the first item.
getItemHeightReturns the height of the item
getItemLeftReturns the left position of the item
getItemSelectedReturns whether the item is selected or not.
getItemTopReturns the top position of the item
getItemToSelectReturns 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.
getItemWidthReturns the width of the item
getLeftReturns 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.
getNextGets the item coming next after the item
getPageDownReturns the item to navigate to when the page down is pressed.
getPageUpReturns the item to navigate to when the page up key is pressed.
getPreviousGets the item coming before the item
getRightReturns 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.
getUpReturns the item to navigate to when the up arrow key is pressed. This should usually just return the item above the current one.
handleClickThis should be called when the user clicks on an item
handleDblClickThis should be called when the user double clicks on an item
handleKeyDownThis should be called when the user presses down a key on the component
handleMouseDownThis should be called when the user presses down the mouse button on an item
handleMouseOverThis should be called when the user moves the mouse over an item
handleMouseUpThis should be called when the user releases the mouse button on an item
isBeforeReturns whether the first item is before the second item in the component.
isEqualCompares two items and returns true if they are equal.
scrollItemIntoViewScrolls the owner so that the item becomes visible.
selectAllSelects all items
selectItemRangeSelects the items passed as arguments and all the items between them
setItemSelectedSets the item as selected (or deselected) and also updates the selected items collection.
updateItemAnchorStateThis is called when the anchor state of the item has changed. Override this to update the visuals to reflect the anchor state.
updateItemLeadStateThis is called when the lead state of the item has changed. Override this to update the visuals to reflect the lead state.
updateItemSelectionStateThis is called when the selection state of the item has changed. Override this to update the visuals to reflect the selected state.

Events

NameTypeBubblesDescripton
changeBiEventFires when the selected items are changed
leaditemchangeBiEventFires 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item to get the size for

Return Type

Number

getItemLeft

Returns the left position of the item

Syntax

object.getItemLeft ( oItem )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item to get the position for

Return Type

Number

getItemSelected

Returns whether the item is selected or not.

Syntax

object.getItemSelected ( oItem )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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 ( e )

Parameters

NameTypeOptionalDefaultDescripton
eBiKeyboardEventThe event object used for the keyboard event

Return Type

BiComponent/Object

getItemWidth

Returns the width of the item

Syntax

object.getItemWidth ( oItem )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item that was clicked
eBiMouseEvent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item that was double clicked
eBiMouseEvent/ObjectThe 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

NameTypeOptionalDefaultDescripton
eBiKeyboardEvent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemObjectThe item that was pressed
eBiMouseEventThe mousedown event object

Return Type

void

handleMouseOver

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

Syntax

object.handleMouseOver ( oItem,e )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item that the mouse over was triggered on
eBiMouseEvent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemObjectThe item that the mouse up was triggered on
eBiMouseEventThe mouseup event object

Return Type

void

isBefore

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

Syntax

object.isBefore ( oItem1,oItem2 )

Parameters

NameTypeOptionalDefaultDescripton
oItem1BiComponent/ObjectThe item to test if before
oItem2BiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItem1BiComponent/ObjectItem one to compare
oItem2BiComponent/ObjectItem two to compare

Return Type

Boolean

scrollItemIntoView

Scrolls the owner so that the item becomes visible.

Syntax

object.scrollItemIntoView ( oItem )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItem1BiComponent/ObjectThe first item to select
oItem2BiComponent/ObjectThe 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item to select or deselect
bSelectedBooleanWhether 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item to update the anchor state for
bAnchorBooleanWhether 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item to update the selected state for
bLeadBooleanWhether 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

NameTypeOptionalDefaultDescripton
oItemBiComponent/ObjectThe item to update the selected state for
bSelectedBooleanWhether the item is selected

Return Type

void