|
Class: ComboListView
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--View
|
+--ComboView
|
+--ComboListView
- Package:
- stx:libwidg2
- Category:
- Views-Interactors
- Version:
- rev:
1.71
date: 2022/07/21 10:06:42
- user: cg
- file: ComboListView.st directory: libwidg2
- module: stx stc-classLibrary: libwidg2
A ComboListView combines a label with a drop down list of default inputs;
choosing any from the pulled list sets the string in the label.
The string is not editable: as oposed to a ComboBoxView, which allows free text input,
this only allows choosing from the given list.
This has a similar function as a PopUpList or SelectionInListView, but looks different.
The preferred model is a SelectionInList, but a simple valueHolder may also be used.
If some other model is to be used, the changeMessage and aspectMessage
should be defined as appropriate (or an aspectAdaptor should be used).
If a listHolder is set, that one is assumed to provide the list of
items in the popped menu;
otherwise, if listMessage is nonNil, the model is assumed to also provide the
list as displayed in the pulled menu.
copyrightCOPYRIGHT (c) 1996 by eXept Software AG / 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.
defaults
-
defaultAspectMessage
-
(comment from inherited method)
subclasses which by default do NOT want to be informed about changed
models should redefine this to return nil
-
defaultChangeMessage
-
(comment from inherited method)
subclasses which by default do NOT want to inform the model
should redefine this to return nil
-
defaultFont
-
(comment from inherited method)
for now - should come from the styleSheet
accessing
-
selectCondition: something
-
accessing-behavior
-
useIndex
-
specify, if the selected components value or its index in the
list should be sent to the model. The default is its value.
-
useIndex: aBoolean
-
specify, if the selected component's value or its index in the
list should be sent to the model. The default is its value.
-
values: aCollection
-
specify, which values are to be stuffed into the model or
passed via the actionBlock.
accessing-components
-
label
-
return the label component
accessing-contents
-
contents
-
get the current value - either in the field's model
or directly
-
contents: something
-
set the current value - either in the field's model or directly
-
selection: something
-
set the contents of my field; questionable
event handling
-
buttonPress: button x: x y: y view: aView
-
-
enableStateChanged
-
(comment from inherited method)
the enable state has changed - pass this to my field and pullDownButton
-
handlesButtonPress: button inView: aView
-
-
keyPress: key x: x y: y
-
select by first letter
focus handling
-
showFocus: explicit
-
the button got the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.
-
showNoFocus: explicit
-
the button lost the keyboard focus
(either explicit, via tabbing; or implicit, by pointer movement)
- change any display attributes as req'd.
-
subviewsInFocusOrder
-
none of my subviews should get he focus
-
wantsFocusWithButtonPress
-
we want the focus, in order to do selection via mouse wheel
initialization
-
initialize
-
(comment from inherited method)
what a hack...
-
initializeField
-
delegate mouseWheel events to myself
menu interaction
-
select: anIndex
-
sent from the popped menu, when an item was selected
private
-
getValueFromModel
-
kludge - try #value if aspect is the default and
queries
-
specClass
-
returns my spec class (for UI editor)
non-MVC use;
set the list explicitly:
|top comboList|
top := StandardSystemView new.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList list:#('hello' 'world' 'this' 'is' 'st/x').
top open.
|
a really, really long list (notice scrollup/down buttons at the top/bottom);
|top comboList|
top := StandardSystemView new.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList list:((1 to:100) collect:[:n | n printString]).
top open.
|
with callBack:
|top comboList|
top := StandardSystemView new.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList list:#('hello' 'world' 'this' 'is' 'st/x').
comboList action:[:selected | Transcript showCR:selected].
top open.
|
with separating lines:
|top comboList|
top := StandardSystemView label:'fruit chooser'.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList label:'fruit'.
comboList list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
comboList action:[:selected | Transcript showCR:selected].
top open
|
with values different from the label strings:
|top comboList|
top := StandardSystemView label:'fruit chooser'.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList label:'dummy'.
comboList list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
comboList selection:'apples'.
comboList values:#(10 20 30 40 nil 50).
comboList action:[:what | Transcript show:'you selected: '; showCR:what].
top open
|
sometimes, you may like the index instead of the value:
(notice, that the separating line counts, so you have to take care ...)
|top comboList|
top := StandardSystemView label:'fruit chooser'.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList label:'dummy'.
comboList list:#('apples' 'bananas' 'grape' 'lemon' '-' 'margaritas').
comboList selection:'apples'.
comboList action:[:what | Transcript show:'you selected: '; showCR:what].
comboList useIndex:true.
top open
|
since the list is actually represented by a menuView,
which itself is inheriting from listView, which itself can display
things different from strings, arbitrary lists can be constructed:
(see ListEntry, LabelAndIcon and Text classes)
|top comboList l|
top := StandardSystemView label:'fruit chooser'.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
l := OrderedCollection new.
l add:(Text string:'apples' color:Color red).
l add:(Text string:'bananas' color:Color red).
l add:(Text string:'grape' color:Color red).
l add:(Text string:'lemon' color:Color red).
l add:'='.
l add:(Text string:'margaritas' color:Color green darkened darkened).
l add:(Text string:'pina colada' color:Color green darkened darkened).
l add:'='.
l add:(Text string:'smalltalk' color:Color blue).
l add:(Text string:'c++' color:Color blue).
l add:(Text string:'eiffel' color:Color blue).
l add:(Text string:'java' color:Color blue).
comboList list:l.
comboList values:#(apples bananas grape lemon
nil
'mhmh - so good' 'makes headache'
nil
'great' 'another headache' 'not bad' 'neat').
comboList selection:'apples'.
comboList action:[:what | Transcript show:'you selected: '; showCR:what].
top open
|
with values different from the label strings:
|top comboList|
top := StandardSystemView label:'language chooser'.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList list:( #(
'usa'
'uk'
'france'
'germany'
'italy'
) collect:[:country |
LabelAndIcon
icon:(Image fromFile:'bitmaps/xpmBitmaps/countries/' , country , '.xpm')
string:country
]
).
comboList values:#(us england france germany italy).
comboList action:[:what | Transcript show:'you selected: '; showCR:what].
comboList bottomInset:(comboList preferredExtent y negated).
top open
|
with a model (see in the inspector, how the index-holders value changes)
the defaults are setup to allow a SelectionInList directly as model:
|p model|
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
p := ComboListView label:'healthy fruit'.
p model:model.
p openAt:(Screen current center).
model inspect
|
model provides selection; list is explicit:
|model top b|
model := 'foo' asValue.
top := StandardSystemView new.
top extent:(300 @ 200).
b := ComboListView in:top.
b origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
b bottomInset:(b preferredExtent y negated).
b list:#('hello' 'world' 'this' 'is' 'st/x').
b model:model.
top openModal.
Transcript showCR:('comboBox''s value: ' , model value).
|
a comboListView and a SelectionInListView on the same model:
|p slv model|
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
model selection:'apples'.
p := ComboListView on:model.
p openAt:(Screen current center).
slv := SelectionInListView on:model.
slv openAt:(Screen current center + (100@100)).
|
like above, using index:
|p slv model|
model := SelectionInList with:#('apples' 'bananas' 'grape' 'lemon' 'margaritas').
model selection:'apples'.
p := ComboListView on:model.
p openAt:(Screen current center).
slv := SelectionInListView on:model.
slv openAt:(Screen current center + (100@100)).
|
two comboListViews on the same model, different aspects:
|top panel p model|
model := Plug new.
model respondTo:#eat: with:[:val | Transcript showCR:'eat: ' , val].
model respondTo:#drink: with:[:val | Transcript showCR:'drink: ' , val].
model respondTo:#meals with:[#(taco burrito enchilada)].
model respondTo:#drinks with:[#(margarita water corona)].
top := StandardSystemView label:'meal chooser'.
top extent:(150@150).
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
panel horizontalLayout:#fitSpace.
p := ComboListView label:'meals'.
p aspect:nil; model:model; listMessage:#meals; change:#eat:.
panel add:p.
p := ComboListView label:'drinks'.
p aspect:nil; model:model; listMessage:#drinks; change:#drink:.
panel add:p.
top open
|
with separate list- and indexHolders:
|p selectionHolder listHolder|
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
selectionHolder := 'apples' asValue.
p := ComboListView label:'healthy fruit'.
p listHolder:listHolder.
p model:selectionHolder.
p openAt:(Screen current center).
selectionHolder inspect
|
using different values:
|p priceHolder listHolder prices priceField|
listHolder := #('apples' 'bananas' 'grape' 'lemon' 'margaritas') asValue.
prices := #(10 10 5 15 50).
priceHolder := nil asValue.
p := ComboListView new.
p listHolder:listHolder.
p model:priceHolder.
p values:prices.
p openAt:(Screen current center).
priceField := EditField new.
priceField readOnly:true.
priceField model:(TypeConverter onNumberValue:priceHolder).
priceField openAt:(Screen current center + (10@10)).
|
in a dialog:
|model1 model2 dialog b|
model1 := 'foo' asValue.
model2 := 'bar' asValue.
dialog := Dialog new.
(dialog addTextLabel:'ComboList example:') adjust:#left.
dialog addVerticalSpace.
(b := dialog addComboListOn:model1 tabable:true).
b list:#('fee' 'foe' 'foo').
dialog addVerticalSpace.
(b := dialog addComboListOn:model2 tabable:true).
b list:#('bar' 'baz' 'baloo').
dialog addVerticalSpace.
dialog addOkButton.
dialog open.
Transcript showCR:('1st comboBox''s value: ' , model1 value).
Transcript showCR:('2nd comboBox''s value: ' , model2 value).
|
Select condition
|top comboList|
top := StandardSystemView new.
top extent:(300 @ 200).
comboList := ComboListView in:top.
comboList origin:(0.0 @ 0.0) corner:(1.0 @ 0.0).
comboList bottomInset:(comboList preferredExtent y negated).
comboList list:((1 to:100) collect:[:n | n printString]).
comboList selectCondition:[:newValue | (Number readFrom:newValue) even].
top open.
|
|