MVP question

This is a discussion on MVP question within the Smalltalk forums in Programming Languages category; I am struggling to write an application that displays a list in the left hand pane and draws a related diagram in the right hand pane i.e. when the user selects an item in the list, a matching diagram is drawn in the right hand pane. I've tried a number of different structuring schemes but I just can't seem to get it right. Do I need a different Model for each pane? Does a View that draws itself have to have a Presenter too? Does anyone have a convenient sample of how to do this kind of application? I am ...

Go Back   Application Development Forum > Programming Languages > Smalltalk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-25-2008, 02:13 PM
Graham Dicker
Guest
 
Default MVP question

I am struggling to write an application that displays a list in the left
hand pane and draws a related diagram in the right hand pane i.e. when the
user selects an item in the list, a matching diagram is drawn in the right
hand pane. I've tried a number of different structuring schemes but I just
can't seem to get it right. Do I need a different Model for each pane? Does
a View that draws itself have to have a Presenter too? Does anyone have a
convenient sample of how to do this kind of application? I am using the
Community Edition X6.

Thanks in advance

Graham Dicker


Reply With Quote
  #2  
Old 08-25-2008, 04:16 PM
John A.
Guest
 
Default Re: MVP question

Hi Graham,

> I am struggling to write an application that displays a list in the left
> hand pane and draws a related diagram in the right hand pane i.e. when the
> user selects an item in the list, a matching diagram is drawn in the right
> hand pane. I've tried a number of different structuring schemes but I just
> can't seem to get it right. Do I need a different Model for each pane? Does
> a View that draws itself have to have a Presenter too? Does anyone have a
> convenient sample of how to do this kind of application? I am using the
> Community Edition X6.


Hopefully the example class (below) will help - just save it to a file and file
it in. The evaluate:

ExamplePresenter show

There is a single overall model which is an OrderedCollection of key-value pairs
representing shapes, with the name of a shape as the key, and a collection of
InkStroke instances forming that shape as the value. This is defined in the
defaultModel class method of ExamplePresenter.

There are two sub-presenters; a ListPresenter to show the list of available
shapes, and a Scribble Presenter (borrowed from the Scribble example
application) to display the shape. If you're thinking of implementing your own
View to display your diagrams, then Scribble is worth taking a look at - it
implements a view (ScribbleView) and corresponding presenter (Scribble); this is
a pretty standard pattern in Dolphin's MVP framework.

In the method createSchematicWiring, the ListPresenter is wired to notify the
ExamplePresenter when a shape is selected. In turn, the ExamplePresenter sets
the model of the ScribblePresenter to be the selected shape.

Hope this helps, please post again if you have any further questions.

John Aspinall
Solutions Software

----

"Filed out from Dolphin Smalltalk X6.1"!

Presenter subclass: #ExamplePresenter
instanceVariableNames: 'namesPresenter scribblePresenter'
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''!
ExamplePresenter guid: (GUID fromString:
'{8884ED9D-496A-444D-8C54-938236830D00}')!
ExamplePresenter comment: ''!
!ExamplePresenter categoriesForClass!MVP-Presenters! !
!ExamplePresenter methodsFor!

createComponents

super createComponents.

namesPresenter := self add: ListPresenter new name: 'names'.
scribblePresenter := self add: Scribble new name: 'scribble'!

createSchematicWiring

super createSchematicWiring.

namesPresenter when: #selectionChanged send: #onShapeSelected to: self!

model: aCollection

super model: aCollection.

namesPresenter model: aCollection!

onShapeSelected

scribblePresenter model: (OrderedCollection with: namesPresenter selection
value)! !
!ExamplePresenter categoriesFor: #createComponents!initializing!public! !
!ExamplePresenter categoriesFor: #createSchematicWiring!initializing!public! !
!ExamplePresenter categoriesFor: #model:!accessing!public! !
!ExamplePresenter categoriesFor: #onShapeSelected!event handling!public! !

!ExamplePresenter class methodsFor!

defaultModel

^OrderedCollection new
add: 'Horizontal Line' -> (InkStroke new addPoint: 10@100; addPoint: 200@100;
yourself);
add: 'Vertical Line' -> (InkStroke new addPoint: 100@10; addPoint: 100@200;
yourself);
add: 'Box' -> (InkStroke new addPoint: 10@10; addPoint: 200@10; addPoint:
200@200; addPoint: 10@200; addPoint: 10@10; yourself);
yourself!

resource_Default_view
"Answer the literal data from which the 'Default view' resource can be
reconstituted.
DO NOT EDIT OR RECATEGORIZE THIS METHOD.

If you wish to modify this resource evaluate:
ViewComposer openOn: (ResourceIdentifier class: self selector:
#resource_Default_view)
"

^#(#'!!STL' 3 788558 10 ##(Smalltalk.STBViewProxy) 8
##(Smalltalk.ContainerView) 98 15 0 0 98 2 8 1409286144 131073 416 0 0 0 5 0 0
0 416 1180166 ##(Smalltalk.ProportionalLayout) 234 240 98 0 32 234 256 98 4 410
8 ##(Smalltalk.ListBox) 98 17 0 416 98 2 8 1412497665 1025 592 590662 2
##(Smalltalk.ListModel) 202 208 544 0 1310726
##(Smalltalk.IdentitySearchPolicy) 524550 ##(Smalltalk.ColorRef) 8 4278190080
0 5 0 0 0 592 0 8 4294902935 459270 ##(Smalltalk.Message) 8 #key 544 544 32
983302 ##(Smalltalk.MessageSequence) 202 208 98 2 721670
##(Smalltalk.MessageSend) 8 #createAt:extent: 98 2 328198 ##(Smalltalk.Point)
1 1 994 345 501 592 930 8 #horizontalExtent: 98 1 1 592 983302
##(Smalltalk.WINDOWPLACEMENT) 8 #[44 0 0 0 0 0 0 0 1 0 0 0 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 0 0 0 0 0 0 0 0 172 0 0 0 250 0 0 0]
98 0 994 193 193 0 27 8 'names' 410 8 ##(Smalltalk.ScribbleView) 98 12 0 416 98
2 8 1140850688 1025 1184 674 202 208 544 0 736 196934 1 ##(Smalltalk.RGB)
21889023 0 5 0 0 0 1184 866 202 208 98 1 930 960 98 2 994 355 1 994 347 501 1184
1090 8 #[44 0 0 0 0 0 0 0 1 0 0 0 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 177 0 0 0 0 0 0 0 94 1 0 0 250 0 0 0] 98 0 1152 0 27 8
'scribble' 0 866 202 208 98 1 930 960 98 2 994 2303 21 994 701 501 416 1090 8
#[44 0 0 0 0 0 0 0 1 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 127 4 0 0 10 0 0 0 221 5 0 0 4 1 0 0] 98 3 592 410 8
##(Smalltalk.Splitter) 98 12 0 416 98 2 8 1140850688 1 1664 0 754 8 4278190080
0 517 0 0 0 1664 866 202 208 98 1 930 960 98 2 994 345 1 994 11 501 1664 1090 8
#[44 0 0 0 0 0 0 0 1 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 172 0 0 0 0 0 0 0 177 0 0 0 250 0 0 0] 98 0 1152 0 27 1184 1152 0
27 )! !
!ExamplePresenter class categoriesFor: #defaultModel!public! !
!ExamplePresenter class categoriesFor:
#resource_Default_view!public!resources-views! !








Reply With Quote
  #3  
Old 08-25-2008, 05:13 PM
Graham Dicker
Guest
 
Default Re: MVP question

Thanks very much John, I believe that's exactly what I was after.

Graham


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:37 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.