From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:49:30 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>SetListAndSelectionExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none removeSelect targetList selectionList undoList redoList <imports></imports> <category>Examples-List + Selection Updates</category> <attributes> <package>SetListAndSelection-Examples</package> </attributes> </class> <comment> Examples.SetListAndSelectionExample
The SetListAndSelectionExample application demonstrates the use of #setList:selecting: to set both the contents and selection of a single-select list widget while maintaining visibility of the selection as much as possible. Its application interface includes one user editable supply list used to set the target list and another list to set the target list selection. Items from the supply list may be selected for removal by the user and these changes may be later removed or restored to compare its affect on the target list. The visible position of the targetList selection should remain unaltered when set unless the item is missing from the new list. Instance Variables: redoList <OrderedCollection of: OrderedCollection> zero or more collections of items by index and value to be removed again from the removeSelect list. removeSelect <MultiSelectionInList> list model of class names to set the targetList list to. selectionList <SelectionInList> list model that determines the selection (if any) targetList is set to. targetList <SelectionInList> list model that displays a selection and list determined by selectionList and removeSelect. undoList <OrderedCollection of: OrderedCollection> zero or more collections of items by index and value to be restored to the removeSelect list.
</comment> <class> <name>SetListAndMultiSelectionExample</name> <environment>Examples</environment> <super>Examples.SetListAndSelectionExample</super> <private>false</private> none <imports></imports> <category>Examples-List + Selection Updates</category> <attributes> <package>SetListAndSelection-Examples</package> </attributes> </class> <comment> Examples.SetListAndMultiSelectionExample
The SetListAndMultiSelectionExample application demonstrates the use of #setList:selecting: to set both the contents and selections of a multiple selection list widget while maintaining visibility of the selections as much as possible. Its application interface includes one user editable supply list used to set the target list and another list to set the target list selections. Items from the supply list may be selected for removal by the user and these changes may later be removed or restored to compare its affect on the target list. The visible position of the targetList selections should remain unaltered when set unless a formerly selected item is missing from the new list. In the targetList new selections may change position between themselves as well as their order in the list. The list and selections of targetList are set using the message #setList:selecting: which requires that the first visible selection matching any prior selection appear stationary. If there is no new selection matching a prior selection then the targetList list widget scrolls to make the first new selection visible in its place. Or, if the new list of targetList is smaller its list widget scrolls upward as needed so that at least one list item (e.g. the last) remains visible. This last requirement ensures the current scroll position is not altered unless the contents of the list would disappear entirely off the widget. Instance Variables: redoList <OrderedCollection of: OrderedCollection> zero or more collections of items by index and value that might be removed later from the removeSelect list. removeSelect <MultiSelectionInList> list model of class names to set the targetList list to. selectionList <MultiSelectionInList> list model that determines the selections (if any) targetList is set to. targetList <SelectionInList> list model that displays selections and list determined by selectionList and removeSelect. undoList <OrderedCollection of: OrderedCollection> zero or more collections of items by index and value to be restored to the removeSelect list.
</comment> <methods> Examples.SetListAndSelectionExample <category>actions</category>
redoSelectionsRemove | list | list := self removeSelect list. (undoList add: redoList removeLast) do: [:assoc | list remove: assoc value].
removeSelections | list | list := self removeSelect list. undoList add:(self removeSelect selectionIndexes asSortedCollection asArray collect:[:index| index -> (list at: index)]). redoList := OrderedCollection new. list removeAll: self removeSelect selections.
setListAndSelection self targetList setList: self removeSelect list copy selecting: self selectionList selection
undoSelectionsRemove | list | list := self removeSelect list. (redoList add: undoList removeLast) do: [:assoc | list add: assoc value beforeIndex: assoc key. self removeSelect selectionIndexes add: assoc key].
</methods> <methods> Examples.SetListAndSelectionExample <category>testing</category>
hasRedo ^redoList notEmpty
hasSelections ^self removeSelect selectionIndexes notEmpty
hasUndo ^undoList notEmpty
</methods> <methods> Examples.SetListAndSelectionExample <category>initialize-release</category>
initialize super initialize. undoList := OrderedCollection new. redoList := OrderedCollection new. removeSelect := MultiSelectionInList with: (Object allSubclasses asSortedCollection:[:a :b| a name < b name]) asList.
</methods> <methods> Examples.SetListAndSelectionExample <category>aspects</category>
removeSelect ^removeSelect
selectionList ^selectionList isNil ifTrue: [selectionList := SelectionInList with: self removeSelect list copy] ifFalse: [selectionList]
targetList ^targetList isNil ifTrue: [targetList := SelectionInList new] ifFalse: [targetList]
</methods> <methods> Examples.SetListAndMultiSelectionExample <category>actions</category>
setListAndSelection self targetList setList: self removeSelect list copy selecting: self selectionList selections
</methods> <methods> Examples.SetListAndMultiSelectionExample <category>aspects</category>
selectionList ^selectionList isNil ifTrue: [selectionList := MultiSelectionInList with: self removeSelect list copy] ifFalse: [selectionList]
targetList ^targetList isNil ifTrue: [targetList := MultiSelectionInList new] ifFalse: [targetList]
</methods> <methods> Examples.SetListAndSelectionExample class <category>resources</category>
classMenu "Tools.MenuEditor new openOnClass: self andSelector: #classMenu" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: 'remove' #enabled: false #value: #removeSelections #enablementSelector: #hasSelections ) #(#{UI.MenuItem} #rawLabel: 'undo remove' #enabled: false #value: #undoSelectionsRemove #enablementSelector: #hasUndo ) #(#{UI.MenuItem} #rawLabel: 'redo remove' #enabled: false #value: #redoSelectionsRemove #enablementSelector: #hasRedo ) ) #(3 ) nil ) decodeAsLiteralArray
</methods> <methods> Examples.SetListAndSelectionExample class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'List update w/o selection position change' #min: #(#{Core.Point} 20 20 ) #max: #(#{Core.Point} 1600 1200 ) #bounds: #(#{Graphics.Rectangle} 800 600 1442 1093 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.LabelSpec} #layout: #(#{Core.Point} 10 0 ) #name: #Label3 #label: 'Add/Remove List Items' ) #(#{UI.LabelSpec} #layout: #(#{Graphics.LayoutOrigin} 10 0.333333 1 0 ) #name: #Label5 #label: 'Select' ) #(#{UI.LabelSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0.666666 1 0 ) #name: #Label4 #label: 'Target' ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 10 0.333333 25 0 -20 0.666666 -10 1 ) #name: #List5 #model: #selectionList #useModifierKeys: true #selectionType: #highlight ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 25 0.666666 25 0 -5 1 -10 1 ) #name: #List6 #model: #targetList #useModifierKeys: true #selectionType: #highlight ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} -15 0.666666 -11 0.5 20 0.666666 11 0.5 ) #name: #ActionButton3 #model: #setListAndSelection #label: '>>' ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 10 0 25 0 -10 0.333333 -10 1 ) #name: #List4 #model: #removeSelect #menu: #classMenu #multipleSelections: true #useModifierKeys: true #selectionType: #highlight ) #(#{UI.LabelSpec} #layout: #(#{UI.AlignmentOrigin} 0 0.333333 0 0 0.5 0 ) #name: #Label1 #label: '+' ) #(#{UI.LabelSpec} #layout: #(#{UI.AlignmentOrigin} 0 0.666666 2 0 0.5 0 ) #name: #Label2 #label: '=' ) ) ) )
</methods> <methods> Examples.SetListAndMultiSelectionExample class <category>interface specs</category>
windowSpec "Tools.UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: 'List update w/o selection position change' #min: #(#{Core.Point} 20 20 ) #max: #(#{Core.Point} 1600 1200 ) #bounds: #(#{Graphics.Rectangle} 800 600 1442 1093 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.LabelSpec} #layout: #(#{Core.Point} 10 0 ) #name: #Label3 #label: 'Add/Remove List Items' ) #(#{UI.LabelSpec} #layout: #(#{Graphics.LayoutOrigin} 10 0.333333 1 0 ) #name: #Label5 #label: 'Select' ) #(#{UI.LabelSpec} #layout: #(#{Graphics.LayoutOrigin} 25 0.666666 1 0 ) #name: #Label4 #label: 'Target' ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} -15 0.666666 -11 0.5 20 0.666666 11 0.5 ) #name: #ActionButton3 #model: #setListAndSelection #label: '>>' ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 10 0 25 0 -10 0.333333 -10 1 ) #name: #List4 #model: #removeSelect #menu: #classMenu #multipleSelections: true #useModifierKeys: true #selectionType: #highlight ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 25 0.666666 25 0 -5 1 -10 1 ) #name: #List6 #model: #targetList #multipleSelections: true #useModifierKeys: true #selectionType: #highlight ) #(#{UI.SequenceViewSpec} #layout: #(#{Graphics.LayoutFrame} 10 0.333333 25 0 -20 0.666666 -10 1 ) #name: #List5 #model: #selectionList #multipleSelections: true #useModifierKeys: true #selectionType: #highlight ) #(#{UI.LabelSpec} #layout: #(#{UI.AlignmentOrigin} 0 0.333333 2 0 0.5 0 ) #name: #Label1 #label: '+' ) #(#{UI.LabelSpec} #layout: #(#{UI.AlignmentOrigin} 0 0.666666 2 0 0.5 0 ) #name: #Label2 #label: '=' ) ) ) )
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>ApplicationModel</name> <environment>UI</environment> <super>UI.Model</super> <private>false</private> none builder uiSession eventHandlers savedWindowInformation <imports></imports> <category>UIBuilder-Framework</category> <attributes> <package>UIBuilder-Framework</package> </attributes> </class>