eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SelectionInList':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SelectionInList


Inheritance:

   Object
   |
   +--Model
      |
      +--ValueModel
         |
         +--ValueHolder
            |
            +--SelectionInList
               |
               +--MultiSelectionInList

Package:
stx:libwidg
Category:
Interface-Support-Models
Version:
rev: 1.39 date: 2023/07/15 18:33:04
user: cg
file: SelectionInList.st directory: libwidg
module: stx stc-classLibrary: libwidg

Description:


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

copyright

COPYRIGHT (c) 1994 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.

Class protocol:

instance creation
o  with: aList
return a new instance holding aList

o  with: aList initialSelection: index
return a new instance holding aList and initially selecting
the item at index.


Instance protocol:

accessing-holders
o  listHolder
return the valueHolder which holds the list

o  listHolder: aValueHolder
set the valueHolder which holds the list.
Q: should we forward a change-notification ?

o  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.

o  selectionIndexHolder
return the valueHolder which holds the index

o  selectionIndexHolder: aValueHolder
set the valueHolder which holdes the index.
Q: should we forward a change-notification ?

accessing-values
o  list
return the list - that's the thingy held by the listHolder

o  list: aCollection
set the list - that's the thingy held by the listHolder

o  selection
return the selections value (i.e. the entry in the list - not its index).
If nothing is selected, nil is returned.

o  selection: anObject
set the selection to be anObject.
If anObject is not in the list, the selection is cleared

o  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.

o  selectionIndex: newIndex
set the selectionIndex

change & update
o  update: anAspect with: aParameter from: changedObject
whenever one of my holders value changes,
tell my dependents about this

initialization
o  initialize
initialize; create the valueHolders for the index and the list

obsolete-backward compatibility
o  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) **

o  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) **

o  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) **

o  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
o  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
o  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
o  hasSelection
return true, if there is a selection

o  numberOfSelections
return the number of selected entries

o  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)


Examples:


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


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:44:37 GMT