This is the working version of my listpresenter code for Ver 2.1 that does not
work for 4.01 for those who wanted to see more of the code.. please disregard some of the comments and other 'snippets' which I left in place during the exploratory coding... The Shell simply contains a ListPresenter (comboBox) and a TextPresenter Thanks in advance Andy ====================== Below is MyListModel.cls ====================== "Filed out from Dolphin Smalltalk/Version 2.1"! Model subclass: #MyListModel instanceVariableNames: 'selected choices' classVariableNames: '' poolDictionaries: ''! MyListModel class instanceVariableNames: ''! MyListModel comment: ''! !MyListModel categoriesForClass!No category! ! !MyListModel methodsFor! choices ^choices! choices: anObject choices := anObject! initialize self choices: SortedCollection new. self choices add: 'a'; add: 'c'; add: 'b'; yourself. self choices." asValue " self selected: (choices at: 2) asValue. " inits the selected window" ^ self! selected ^selected! selected: anObject selected := anObject! ! !MyListModel categoriesFor: #choices!accessing! ! !MyListModel categoriesFor: #choices:!accessing! ! !MyListModel categoriesFor: #initialize!accessing!initializing! ! !MyListModel categoriesFor: #selected!accessing! ! !MyListModel categoriesFor: #selected:!accessing! ! !MyListModel class methodsFor! example1 | model | model := MyListModel new. Transcript show: (model choices) printString;cr. Transcript show: model selected value printString; cr.! ! !MyListModel class categoriesFor: #example1!no category! ! ============================= clip here ========================================= ============================= Below is MyListDemoShell.cls ====================== "Filed out from Dolphin Smalltalk/Version 2.1"! Shell subclass: #MyListDemoShell instanceVariableNames: 'selectedPresenter choicesPresenter' classVariableNames: '' poolDictionaries: ''! MyListDemoShell class instanceVariableNames: ''! MyListDemoShell comment: ''! !MyListDemoShell categoriesForClass!No category! ! !MyListDemoShell methodsFor! createComponents super createComponents. choicesPresenter := self add: ListPresenter new name: 'choicesField'. selectedPresenter := self add: TextPresenter new name: 'selectedField'.! createSchematicWiring super createSchematicWiring. choicesPresenter when: #selectionChanged send: #updateSelected to: self. " MUST use name of #selectionChanged, and a local definition " " MyListDemoShell show. "! model: aModel super model: aModel. selectedPresenter model: ( aModel selected). choicesPresenter model: ( aModel choices).! onViewOpened super onViewOpened. self selectedPresenter.! selectedPresenter "self halt." " got here !!!!" " choicesPresenter selectionByIndex: 2. " "comment line to have empty selection with index of 0" "selectedPresenter value: (choicesPresenter selectionByIndex)." " to do index" ^ selectedPresenter value: 'no selection' " (choicesPresenter selectionByIndex). "" to do content" " MyListDemoShell show. "! selectionChanged " must be named 'selectionChanged' to correctly be used in >>createSchematicWiring" selectedPresenter value: self model selectionByIndex! updateSelected "selectedPresenter model: (choicesPresenter selectionByIndex). " " works to show index !!!!!!" selectedPresenter model: (choicesPresenter selection). " works to show content" " MyListDemoShell show. "! ! !MyListDemoShell categoriesFor: #createComponents!initializing! ! !MyListDemoShell categoriesFor: #createSchematicWiring!initializing! ! !MyListDemoShell categoriesFor: #model:!accessing! ! !MyListDemoShell categoriesFor: #onViewOpened!event handling! ! !MyListDemoShell categoriesFor: #selectedPresenter!no category! ! !MyListDemoShell categoriesFor: #selectionChanged!private helpers! ! !MyListDemoShell categoriesFor: #updateSelected!updating! ! !MyListDemoShell class methodsFor! defaultModel ^MyListModel new! defaultView ^'Default View'! example1 MyListDemoShell show.! ! !MyListDemoShell class categoriesFor: #defaultModel!no category! ! !MyListDemoShell class categoriesFor: #defaultView!no category! ! !MyListDemoShell class categoriesFor: #example1!no category! ! ====================================== clip here ============================== |
Andy,
One way to get it to work is to change the line in MyListDemoShell>>model: from choicesPresenter model: ( aModel choices) to choicesPresenter model list: aModel choices The key change is using #list: instead of #model:. (Taking out the parentheses is just cosmetic, they are not needed.) What's the difference between the two lines above? The first line assigns a SortedCollection as the ListPresenter's model, but the ListPresenter expects a ListModel as its model. The second line assigns the SortedCollection as the ListModel's list. In other words, choicesPresenter is a ListPresenter whose model is a ListModel whose list is a SortedCollection. Why it works in version 2.1 but not in version 4 I don't know. -- Louis |
In reply to this post by acg
Andrew,
There is a bit of extra code in your classes that might be confusing you. I've pared it down to the bare bones which might, or might not!, help you to understand what is happening. I was going to write one of my convoluted explanations about what was happening but (probably to a sigh of relief from the rest of the group) I haven't been able to get round to it. The following works in the way I think you were intending to go, sharing a ListModel and ValueModel between your model and the sub presenters added to the Shell. I don't think this is generally the best way to do it, it can get a bit complex when you have more presenters/views/variables, but it is probably the best way to demonstrate in this type of example. MyListModel ========= initialize choices := ListModel on: #('a' 'c' 'b') asSortedCollection. selected := 'no selection' asValue choices ^choices selected ^selected MyListDemoShell class ================ defaultModel ^MyListModel new MyListDemoShell ============ createComponents super createComponents. choicesPresenter := self add: ListPresenter new name: 'choicesField'. selectedPresenter := self add: TextPresenter new name: 'selectedField' createSchematicWiring super createSchematicWiring. choicesPresenter when: #selectionChanged send: #updateSelected to: self model: aModel super model: aModel. selectedPresenter model: aModel selected. choicesPresenter model: aModel choices updateSelected selectedPresenter value: choicesPresenter selection Regards Ian |
Free forum by Nabble | Edit this page |