Hi,
I'm writing this as PRWidget initialisation had me confused for a while, and
I guess it might confuse other newcomers. I'd also like to check with the
list that my understanding is correct.
For example given the code below:
PRDistribution>>childrenWidget
^ childrenWidget ifNil: [childrenWidget := (PRComponent named: 'children')
componentClass: PRChildrenWidget;
write: 2
using: PRChildrenWidget descriptionLevel;
write: true
using: PRChildrenWidget descriptionExpand;
yourself
]
and:
PRChildrenWidget class>>descriptionExpand
^ MABooleanDescription new
default: self defaultExpand;
parameterName: 'expand';
accessor: #expand;
label: 'Expand';
priority: 310;
yourself
I would have expected an accessor "PRChildWidget>>expand:" to be called
with
the value: 'true'. I created my PRWidget derived class based on this
assumption. However my equivalent setter was not being called and a closer
look showed PRChildWidget to have no setters only getters. The getter reads
as:
PRChildWidget>>expand
^ self read: #descriptionExpand
What's actually happening is "PRComponent>>description" is being
called, not
as I'd imagined: "PRChildWidget>>description".
tracing through the following code:
PRComponent>>write: anObject using: aDescription
(self basicDescription includes: aDescription)
ifTrue: [ super write: anObject using: aDescription ]
ifFalse: [
(anObject notNil and: [ aDescription isDocumentDescription ])
ifTrue: [ anObject owner: self ].
self settings at: aDescription put: anObject ]
reveals the code: "self settings at: aDescription put: anObject" is called,
so "true" is placed in a settings Dictionary keyed by: #descriptionExpand
I've just about understood the code so far, and though I haven't traced
through PRChildrenWidget instantiation it looks like in
WAComponent>>initializeOwner:link: that the settings are copied to the newly
created PRChildrenWidget object.
Phew.
I think I can see why there's complexity, but seems a shame that it in
WAComponent>>initializeOwner:link: the code couldn't call the accessors of
the componentClass assuming that the Magritte descriptions were configured
to use an accessor pattern.
Or perhaps I've misunderstood??
Cheers
Nick