Navigation:  Programming Cookbook > Creating GUI Applications > Creating MVP Components >

Views

Previous pageReturn to chapter overviewNext page

A view must be created to match the type of model data that must be displayed and to be compatible with the expectations of the presenter. Some views may have their own class but others may simply be "composed" out of other views. In either case it is the job of the View Composer to configure a view object and save it down as a named view resource.

It has become fashionable to use the word "Skins" to apply to interchangeable user interface designs that can be plugged onto an underlying application component. This is exactly what views are in the MVP world.

View resources are actually class methods (usually of a particular presenter) that hold a literal specification of how to rebuild a view. For example, the method that specifies the default view for a TextPresenter looks like this:

TextPresenter class>>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 ##(STBViewProxy)  8 ##(TextEdit)  98 16 0 0 98 2 8

       1140916352 1025 416 0 524550 ##(ColorRef)  8 4278190080 0 7 0 0 0 416 0 8

       4294906635 852486 ##(NullConverter)  0 0 1 983302 ##(MessageSequence)

       202 208 98 3 721670 ##(MessageSend)  8 #createAt:extent: 98 2 328198

       ##(Point)  11 11 722 241 39 416 658 8 #selectionRange: 98 1 525062 ##(Interval)

       3 1 3 416 658 8 #isTextModified: 98 1 32 416 983302 ##(WINDOWPLACEMENT)

       8 #[44 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255

       255 255 255 255 255 5 0 0 0 5 0 0 0 125 0 0 0 24 0 0 0] 98 0 722 193 193 0 27 )

 

When reconstituted, this view resource yields an instance of TextEdit (you may be able to see the class name in the first line of the specification). View resources are always given textual names to identify them. This particular resource is called TextPresenter.Default view. Once again, from the above, you may be able to see how the resource name and maps onto the name of the method that holds it.

Note, although the above method indicates that you can evaluate an expression to open the View Composer onto this view resource, there is a much easier way; simply locate the view in the View Browser and double-click it.