|
Class: SelectionInList
Object
|
+--Model
|
+--ValueModel
|
+--ValueHolder
|
+--SelectionInList
|
+--MultiSelectionInList
- Package:
- stx:libwidg
- Category:
- Interface-Support-Models
- Version:
- rev:
1.35
date: 2019/06/28 07:12:15
- user: cg
- file: SelectionInList.st directory: libwidg
- module: stx stc-classLibrary: libwidg
- Author:
- Claus Gittinger
Instances of SelectionInList can be used as model for
a SelectionInListView or a PopUpList.
They keep two values: a list value and a selection value;
both are referred to via valueHolders.
If any of those two changes, the selectionInList notifies its
dependents via a change notification,
using #list or #selectionIndex as update aspect respectively.
A popupList also knows how to deal with a selectionInList model;
this makes it possible to have popupLists be somewhat exchangable
with selectionInListViews.
SelectionInLists only support a single selection within the list;
use MultiSelectionInList, if multiple selections are needed.
[instance variables:]
listHolder <ValueHolder> holds the list
selectionIndexHolder <ValueHolder> holdes the selectionIndex
SelectionInListView
PopUpList
MultiSelectionInList
Model
ValueHolder
instance creation
-
with: aList
-
return a new instance holding aList
-
with: aList initialSelection: index
-
return a new instance holding aList and initially selecting
the item at index.
accessing-holders
-
listHolder
-
return the valueHolder which holds the list
-
listHolder: aValueHolder
-
set the valueHolder which holds the list.
Q: should we forward a change-notification ?
-
selectionHolder
-
return someone holding on the selection itself (not the index).
Since we have no one, create an adapter, to get up-to-date values.
-
selectionIndexHolder
-
return the valueHolder which holds the index
-
selectionIndexHolder: aValueHolder
-
set the valueHolder which holdes the index.
Q: should we forward a change-notification ?
accessing-values
-
list
-
return the list - that's the thingy held by the listHolder
-
list: aCollection
-
set the list - that's the thingy held by the listHolder
-
selection
-
return the selections value (i.e. the entry in the list - not its index).
If nothing is selected, nil is returned.
-
selection: anObject
-
set the selection to be anObject.
If anObject is not in the list, the selection is cleared
-
selectionIndex
-
return the selections index (1..).
That's the thingy held by the indexHolder.
For ST-80 compatibility, 0 is returned if nothing is selected.
-
selectionIndex: newIndex
-
set the selectionIndex
change & update
-
update: something with: aParameter from: changedObject
-
whenever one of my holders value changes,
tell my dependents about this
initialization
-
initialize
-
initialize; create the valueHolders for the index and the list
obsolete-backward compatibility
-
index
-
return the selections index.
This is an OBSOLETE backward compatibility interface
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
index: newIndex
-
set the selections index.
This is an OBSOLETE backward compatibility interface
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
indexHolder
-
return the valueHolder of the selections index.
This is an OBSOLETE backward compatibility interface
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
indexHolder: aValueHolder
-
set the valueHolder of the selections index.
This is an OBSOLETE backward compatibility interface
** This is an obsolete interface - do not use it (it may vanish in future versions) **
printing & storing
-
displayOn: aGCOrStream
-
Compatibility
append a printed desription on some stream (Dolphin, Squeak)
OR:
display the receiver in a graphicsContext at 0@0 (ST80).
This method allows for any object to be displayed in some view
(although the fallBack is to display its printString ...)
private
-
clearSelection
-
clear the selection.
For ST-80 compatibility, a non-selection has an index of 0
although, nil sounds more natural to me ... (sigh)
queries
-
hasSelection
-
return true, if there is a selection
-
numberOfSelections
-
return the number of selected entries
-
zeroIndex
-
return the selections index returned when nothing
is selected. This method is provided to allow applications
to deal transparently with SelectionInList models AND with
MultSelectionInList models, which use different no-selection values.
Although I would prefer nil, ST-80 uses 0 to represent `no-selection'. (sigh)
basic setup using a selectionInList as model of a selectionInListView:
|m v|
m := SelectionInList new.
m list:#('one' 'two' 'three' 'four').
m selectionIndex:2.
v := SelectionInListView on:m.
v open
|
similar, a selectionInList as model of a popUpList:
|m v|
m := SelectionInList new.
m list:#('one' 'two' 'three' 'four').
m selectionIndex:2.
v := PopUpList on:m.
v open
|
using a combination-instance creation method:
|m v|
m := SelectionInList
with:#('one' 'two' 'three' 'four')
initialSelection:2.
v := PopUpList on:m.
v open
|
two different views on the same selectionInList model:
|m v1 v2|
m := SelectionInList new.
m list:#('one' 'two' 'three' 'four').
m selectionIndex:2.
v1 := PopUpList on:m.
v1 open.
v2 := SelectionInListView on:m.
v2 open
|
two views on the same selectionInList:
and a button, which adds an item to the list.
|m v1 v2 b numItems|
numItems := 4.
m := SelectionInList new.
m list:((1 to:numItems) collect:[:i | i printString]).
m selectionIndex:2.
v1 := ScrollableView forView:(SelectionInListView on:m).
v1 open.
v2 := ScrollableView forView:(SelectionInListView on:m).
v2 open.
b := Button label:'add item'.
b action:[numItems := numItems + 1.
m list:((1 to:numItems) collect:[:i | i printString]).
].
b open
|
|