MultiSelectionInList.st
author ca
Mon, 01 Apr 1996 20:56:26 +0200
changeset 526 8203430fbadd
parent 360 c057423ecdd0
child 536 fd1b723e69b6
permissions -rw-r--r--
oops - clearing selection was wrong in MultiSelectionInList

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

SelectionInList subclass:#MultiSelectionInList
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Support-Models'
!

!MultiSelectionInList class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    Like a selectionInList, but allows for multiple selected items.
    For use as a model for SelectionInListViews, with multipleSelectOk set to true.
"
! !

!MultiSelectionInList methodsFor:'accessing-values'!

selection
    "return the selections value (i.e. the entry in the list"

    |l|

    l := self list.
    ^ selectionIndexHolder value collect:[:index |
	l at:index
      ]

    "Created: 26.10.1995 / 16:52:27 / cg"
!

selection:anObjectList 
    "set the selection to be anObjectList."

    |l indizes|

    l := self list.
    indizes := OrderedCollection new.
    anObjectList do:[:o |
	|idx|

	idx := l indexOf:o ifAbsent:0.
	idx ~~ 0 ifTrue:[
	    indizes add:idx
	].
    ].
    ^ self selectionIndex:indizes

    "Created: 26.10.1995 / 16:40:24 / cg"
! !

!MultiSelectionInList methodsFor:'initialization'!

initialize
    self listHolder:(nil asValue).      "/ could also use an empty collection here
    self selectionIndexHolder:(Array new asValue).

    "Created: 26.10.1995 / 16:30:22 / cg"
! !

!MultiSelectionInList methodsFor:'private'!

clearSelection
    selectionIndexHolder setValue:(Array new).


! !

!MultiSelectionInList methodsFor:'selections'!

selections
    |selectionIndices|

    selectionIndices := selectionIndexHolder value.
    (selectionIndices isNil 
    or:[selectionIndices isEmpty]) ifFalse:[
	^ selectionIndices collect:[:index | listHolder value at:index]
    ].
    ^ Array new
! !

!MultiSelectionInList class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg/MultiSelectionInList.st,v 1.7 1996-04-01 18:56:26 ca Exp $'
! !